From ccefe9da846137c204637cb98ce16c2cc7536c71 Mon Sep 17 00:00:00 2001 From: SergeyBokhantsev Date: Fri, 25 May 2018 15:10:53 +0300 Subject: [PATCH] Copter: implement user auxswitch functions --- ArduCopter/APM_Config.h | 1 + ArduCopter/Copter.h | 3 +++ ArduCopter/UserCode.cpp | 17 +++++++++++++++++ ArduCopter/defines.h | 3 +++ ArduCopter/switches.cpp | 14 ++++++++++++++ 5 files changed, 38 insertions(+) diff --git a/ArduCopter/APM_Config.h b/ArduCopter/APM_Config.h index 9c88942e55..8b967d6689 100644 --- a/ArduCopter/APM_Config.h +++ b/ArduCopter/APM_Config.h @@ -65,3 +65,4 @@ //#define USERHOOK_MEDIUMLOOP userhook_MediumLoop(); // for code to be run at 10hz //#define USERHOOK_SLOWLOOP userhook_SlowLoop(); // for code to be run at 3.3hz //#define USERHOOK_SUPERSLOWLOOP userhook_SuperSlowLoop(); // for code to be run at 1hz +//#define USERHOOK_AUXSWITCH ENABLED // for code to handle user aux switches diff --git a/ArduCopter/Copter.h b/ArduCopter/Copter.h index fa62b12288..dc2e9760c3 100644 --- a/ArduCopter/Copter.h +++ b/ArduCopter/Copter.h @@ -940,6 +940,9 @@ private: void userhook_MediumLoop(); void userhook_SlowLoop(); void userhook_SuperSlowLoop(); + void userhook_auxSwitch1(uint8_t ch_flag); + void userhook_auxSwitch2(uint8_t ch_flag); + void userhook_auxSwitch3(uint8_t ch_flag); #include "mode.h" diff --git a/ArduCopter/UserCode.cpp b/ArduCopter/UserCode.cpp index 8611be31b4..46070d47fa 100644 --- a/ArduCopter/UserCode.cpp +++ b/ArduCopter/UserCode.cpp @@ -42,3 +42,20 @@ void Copter::userhook_SuperSlowLoop() // put your 1Hz code here } #endif + +#ifdef USERHOOK_AUXSWITCH +void Copter::userhook_auxSwitch1(uint8_t ch_flag) +{ + // put your aux switch #1 handler here (CHx_OPT = 47) +} + +void Copter::userhook_auxSwitch2(uint8_t ch_flag) +{ + // put your aux switch #2 handler here (CHx_OPT = 48) +} + +void Copter::userhook_auxSwitch3(uint8_t ch_flag) +{ + // put your aux switch #3 handler here (CHx_OPT = 49) +} +#endif diff --git a/ArduCopter/defines.h b/ArduCopter/defines.h index fb610bb12a..5987596bd8 100644 --- a/ArduCopter/defines.h +++ b/ArduCopter/defines.h @@ -75,6 +75,9 @@ enum aux_sw_func { AUXSW_WINCH_ENABLE = 44, // winch enable/disable AUXSW_WINCH_CONTROL = 45, // winch control AUXSW_RC_OVERRIDE_ENABLE = 46, // enable RC Override + AUXSW_USER_FUNC1 = 47, // user function #1 + AUXSW_USER_FUNC2 = 48, // user function #2 + AUXSW_USER_FUNC3 = 49, // user function #3 AUXSW_SWITCH_MAX, }; diff --git a/ArduCopter/switches.cpp b/ArduCopter/switches.cpp index 40cffc9413..30e2e15037 100644 --- a/ArduCopter/switches.cpp +++ b/ArduCopter/switches.cpp @@ -730,6 +730,20 @@ void Copter::do_aux_switch_function(int8_t ch_function, uint8_t ch_flag) } } break; + +#ifdef USERHOOK_AUXSWITCH + case AUXSW_USER_FUNC1: + userhook_auxSwitch1(ch_flag); + break; + + case AUXSW_USER_FUNC2: + userhook_auxSwitch2(ch_flag); + break; + + case AUXSW_USER_FUNC3: + userhook_auxSwitch3(ch_flag); + break; +#endif } }