From b81074d83a0f57aa8d9b8232670fb64077a1e2f3 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 23 Sep 2016 16:41:10 +1000 Subject: [PATCH] Copter: simplify auxsw duplicates check --- ArduCopter/defines.h | 1 + ArduCopter/switches.cpp | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ArduCopter/defines.h b/ArduCopter/defines.h index 1a3050d8ff..124002e820 100644 --- a/ArduCopter/defines.h +++ b/ArduCopter/defines.h @@ -69,6 +69,7 @@ enum aux_sw_func { AUXSW_RELAY4 = 36, // Relay4 pin on/off (in Mission planner set CH10_OPT = 36) AUXSW_THROW = 37, // change to THROW flight mode AUXSW_AVOID_ADSB = 38, // enable AP_Avoidance library + AUXSW_SWITCH_MAX, }; // Frame types diff --git a/ArduCopter/switches.cpp b/ArduCopter/switches.cpp index 85e2e85bf6..c2844dcc84 100644 --- a/ArduCopter/switches.cpp +++ b/ArduCopter/switches.cpp @@ -86,23 +86,23 @@ bool Copter::check_if_auxsw_mode_used(uint8_t auxsw_mode_check) // check_duplicate_auxsw - Check to see if any Aux Switch Functions are duplicated bool Copter::check_duplicate_auxsw(void) { - bool ret = ((g.ch7_option != AUXSW_DO_NOTHING) && (g.ch7_option == g.ch8_option || - g.ch7_option == g.ch9_option || g.ch7_option == g.ch10_option || - g.ch7_option == g.ch11_option || g.ch7_option == g.ch12_option)); - - ret = ret || ((g.ch8_option != AUXSW_DO_NOTHING) && (g.ch8_option == g.ch9_option || - g.ch8_option == g.ch10_option || g.ch8_option == g.ch11_option || - g.ch8_option == g.ch12_option)); - - ret = ret || ((g.ch9_option != AUXSW_DO_NOTHING) && (g.ch9_option == g.ch10_option || - g.ch9_option == g.ch11_option || g.ch9_option == g.ch12_option)); - - ret = ret || ((g.ch10_option != AUXSW_DO_NOTHING) && (g.ch10_option == g.ch11_option || - g.ch10_option == g.ch12_option)); - - ret = ret || ((g.ch11_option != AUXSW_DO_NOTHING) && (g.ch11_option == g.ch12_option)); - - return ret; + uint8_t auxsw_option_counts[AUXSW_SWITCH_MAX] = {}; + auxsw_option_counts[g.ch7_option]++; + auxsw_option_counts[g.ch8_option]++; + auxsw_option_counts[g.ch9_option]++; + auxsw_option_counts[g.ch10_option]++; + auxsw_option_counts[g.ch11_option]++; + auxsw_option_counts[g.ch12_option]++; + + for (uint8_t i=0; i 1) { + return true; + } + } + return false; } void Copter::reset_control_switch()