HAL_ChibiOS: use safety button logic from AP_BoardConfig

This commit is contained in:
Andrew Tridgell 2019-09-03 12:24:34 +10:00
parent 5a96e374ba
commit 03c1a8bfd9
2 changed files with 13 additions and 26 deletions

View File

@ -1506,36 +1506,22 @@ void RCOutput::safety_update(void)
#ifdef HAL_GPIO_PIN_SAFETY_IN #ifdef HAL_GPIO_PIN_SAFETY_IN
// handle safety button // handle safety button
uint16_t safety_options = 0;
if (boardconfig) {
safety_options = boardconfig->get_safety_button_options();
}
bool safety_pressed = palReadLine(HAL_GPIO_PIN_SAFETY_IN); bool safety_pressed = palReadLine(HAL_GPIO_PIN_SAFETY_IN);
if (!(safety_options & AP_BoardConfig::BOARD_SAFETY_OPTION_BUTTON_ACTIVE_ARMED) &&
hal.util->get_soft_armed()) {
safety_pressed = false;
}
if (safety_state==AP_HAL::Util::SAFETY_DISARMED &&
!(safety_options & AP_BoardConfig::BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_OFF)) {
safety_pressed = false;
}
if (safety_state==AP_HAL::Util::SAFETY_ARMED &&
!(safety_options & AP_BoardConfig::BOARD_SAFETY_OPTION_BUTTON_ACTIVE_SAFETY_ON)) {
safety_pressed = false;
}
if (safety_pressed) { if (safety_pressed) {
safety_button_counter++; AP_BoardConfig *brdconfig = AP_BoardConfig::get_singleton();
} else { if (safety_press_count < 255) {
safety_button_counter = 0; safety_press_count++;
} }
if (safety_button_counter == 10) { if (brdconfig && brdconfig->safety_button_handle_pressed(safety_press_count)) {
// safety has been pressed for 1 second, change state
if (safety_state ==AP_HAL::Util::SAFETY_ARMED) { if (safety_state ==AP_HAL::Util::SAFETY_ARMED) {
safety_state = AP_HAL::Util::SAFETY_DISARMED; safety_state = AP_HAL::Util::SAFETY_DISARMED;
} else { } else {
safety_state = AP_HAL::Util::SAFETY_ARMED; safety_state = AP_HAL::Util::SAFETY_ARMED;
} }
} }
} else {
safety_press_count = 0;
}
#elif HAL_WITH_IO_MCU #elif HAL_WITH_IO_MCU
safety_state = _safety_switch_state(); safety_state = _safety_switch_state();
iomcu.set_safety_mask(safety_mask); iomcu.set_safety_mask(safety_mask);

View File

@ -314,6 +314,7 @@ private:
uint32_t safety_update_ms; uint32_t safety_update_ms;
uint8_t led_counter; uint8_t led_counter;
int8_t safety_button_counter; int8_t safety_button_counter;
uint8_t safety_press_count; // 0.1s units
// mask of channels to allow when safety on // mask of channels to allow when safety on
uint16_t safety_mask; uint16_t safety_mask;