From 3fbd008c4e1afca35a580a329a7dc25d55e842c0 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 4 Feb 2021 05:04:29 +0100 Subject: [PATCH] FMU safety button: cleanup disabling safety --- src/drivers/safety_button/SafetyButton.cpp | 28 ++++++---------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/drivers/safety_button/SafetyButton.cpp b/src/drivers/safety_button/SafetyButton.cpp index 308ff13046..8551a37c1a 100644 --- a/src/drivers/safety_button/SafetyButton.cpp +++ b/src/drivers/safety_button/SafetyButton.cpp @@ -71,34 +71,20 @@ SafetyButton::CheckButton() { const bool safety_button_pressed = px4_arch_gpioread(GPIO_BTN_SAFETY); - /* - * Keep pressed for a while to arm. + /* Keep safety button pressed for one second to turn off safety * - * Note that the counting sequence has to be same length - * for arming / disarming in order to end up as proper - * state machine, keep ARM_COUNTER_THRESHOLD the same - * length in all cases of the if/else struct below. + * Note that safety cannot be turned on again by button because a button + * hardware problem could accidentally disable it in flight. */ if (safety_button_pressed && !_safety_btn_off) { - if (_button_counter < CYCLE_COUNT) { - _button_counter++; - } else if (_button_counter == CYCLE_COUNT) { - // switch safety off and to ok-to-arm state - _safety_btn_off = true; + if (_button_counter <= CYCLE_COUNT) { _button_counter++; } - } else if (safety_button_pressed && _safety_btn_off) { - - if (_button_counter < CYCLE_COUNT) { - _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++; + if (_button_counter == CYCLE_COUNT) { + // switch safety off -> ready to arm state + _safety_btn_off = true; } } else {