FMU safety button: cleanup disabling safety

This commit is contained in:
Matthias Grob
2021-02-04 06:25:43 +01:00
committed by Lorenz Meier
parent 867b006861
commit 3fbd008c4e
+7 -21
View File
@@ -71,34 +71,20 @@ SafetyButton::CheckButton()
{ {
const bool safety_button_pressed = px4_arch_gpioread(GPIO_BTN_SAFETY); const bool safety_button_pressed = px4_arch_gpioread(GPIO_BTN_SAFETY);
/* /* Keep safety button pressed for one second to turn off safety
* Keep pressed for a while to arm.
* *
* Note that the counting sequence has to be same length * Note that safety cannot be turned on again by button because a button
* for arming / disarming in order to end up as proper * hardware problem could accidentally disable it in flight.
* state machine, keep ARM_COUNTER_THRESHOLD the same
* length in all cases of the if/else struct below.
*/ */
if (safety_button_pressed && !_safety_btn_off) { if (safety_button_pressed && !_safety_btn_off) {
if (_button_counter < CYCLE_COUNT) {
_button_counter++;
} else if (_button_counter == CYCLE_COUNT) { if (_button_counter <= CYCLE_COUNT) {
// switch safety off and to ok-to-arm state
_safety_btn_off = true;
_button_counter++; _button_counter++;
} }
} else if (safety_button_pressed && _safety_btn_off) { if (_button_counter == CYCLE_COUNT) {
// switch safety off -> ready to arm state
if (_button_counter < CYCLE_COUNT) { _safety_btn_off = true;
_button_counter++;
} else if (_button_counter == CYCLE_COUNT) {
// do not switch safety off,
// as a button that is stuck in hardware
// could cause this
_button_counter++;
} }
} else { } else {