From f3634450d71c508fbf6f6bccb0937ce0f6056587 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 8 Jul 2019 12:44:25 -0700 Subject: [PATCH] Sub: Enforce configuration of a disarm button --- ArduSub/AP_Arming_Sub.cpp | 34 ++++++++++++++++++++++++++++++++++ ArduSub/AP_Arming_Sub.h | 1 + 2 files changed, 35 insertions(+) diff --git a/ArduSub/AP_Arming_Sub.cpp b/ArduSub/AP_Arming_Sub.cpp index dcf3e56a04..89e09ddd61 100644 --- a/ArduSub/AP_Arming_Sub.cpp +++ b/ArduSub/AP_Arming_Sub.cpp @@ -12,11 +12,45 @@ bool AP_Arming_Sub::rc_calibration_checks(bool display_failure) return rc_checks_copter_sub(display_failure, channels); } +const bool AP_Arming_Sub::has_disarm_function () { + bool has_shift_function = false; + // make sure the craft has a disarm button assigned before it is armed + // check all the standard btn functions + for (uint8_t i = 0; i < 16; i++) { + switch (sub.get_button(i)->function(false)) { + case JSButton::k_shift : + has_shift_function = true; + break; + case JSButton::k_arm_toggle : + return true; + case JSButton::k_disarm : + return true; + } + } + + // check all the shift functions if there's shift assigned + if (has_shift_function) { + for (uint8_t i = 0; i < 16; i++) { + switch (sub.get_button(i)->function(true)) { + case JSButton::k_arm_toggle : + case JSButton::k_disarm : + return true; + } + } + } + return false; +} + bool AP_Arming_Sub::pre_arm_checks(bool display_failure) { if (armed) { return true; } + // don't allow arming unless there is a disarm button configured + if (!has_disarm_function()) { + check_failed(ARMING_CHECK_NONE, display_failure, "Must assign a disarm or arm_toggle button"); + return false; + } return AP_Arming::pre_arm_checks(display_failure); } diff --git a/ArduSub/AP_Arming_Sub.h b/ArduSub/AP_Arming_Sub.h index 12a57cbb5d..0fcc85f6c3 100644 --- a/ArduSub/AP_Arming_Sub.h +++ b/ArduSub/AP_Arming_Sub.h @@ -13,6 +13,7 @@ public: bool rc_calibration_checks(bool display_failure) override; bool pre_arm_checks(bool display_failure) override; + const bool has_disarm_function(); bool disarm() override; bool arm(AP_Arming::Method method, bool do_arming_checks=true) override;