2 * This file is part of INAV Project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/.
8 * Alternatively, the contents of this file may be used under the terms
9 * of the GNU General Public License Version 3, as described below:
11 * This file is free software: you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by the
13 * Free Software Foundation, either version 3 of the License, or (at your
14 * option) any later version.
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see http://www.gnu.org/licenses/.
26 #include "build/debug.h"
27 #include "drivers/time.h"
29 #ifdef USE_MULTI_FUNCTIONS
31 #include "fc/fc_core.h"
32 #include "fc/multifunction.h"
33 #include "fc/rc_modes.h"
34 #include "fc/runtime_config.h"
37 #include "navigation/navigation.h"
39 multi_function_e selectedItem
= MULTI_FUNC_NONE
;
40 uint8_t multiFunctionFlags
;
41 bool nextItemIsAvailable
= false;
43 static void multiFunctionApply(multi_function_e selectedItem
)
45 switch (selectedItem
) {
48 case MULTI_FUNC_1
: // redisplay current warnings
49 osdResetWarningFlags();
51 case MULTI_FUNC_2
: // control manual emergency landing
52 checkManualEmergencyLandingControl(ARMING_FLAG(ARMED
));
54 case MULTI_FUNC_3
: // toggle Safehome suspend
55 #if defined(USE_SAFE_HOME)
56 if (navConfig()->general
.flags
.safehome_usage_mode
!= SAFEHOME_USAGE_OFF
) {
57 MULTI_FUNC_FLAG(MF_SUSPEND_SAFEHOMES
) ? MULTI_FUNC_FLAG_DISABLE(MF_SUSPEND_SAFEHOMES
) : MULTI_FUNC_FLAG_ENABLE(MF_SUSPEND_SAFEHOMES
);
61 case MULTI_FUNC_4
: // toggle RTH Trackback suspend
62 if (navConfig()->general
.flags
.rth_trackback_mode
!= RTH_TRACKBACK_OFF
) {
63 MULTI_FUNC_FLAG(MF_SUSPEND_TRACKBACK
) ? MULTI_FUNC_FLAG_DISABLE(MF_SUSPEND_TRACKBACK
) : MULTI_FUNC_FLAG_ENABLE(MF_SUSPEND_TRACKBACK
);
68 if (STATE(MULTIROTOR
)) { // toggle Turtle mode
69 MULTI_FUNC_FLAG(MF_TURTLE_MODE
) ? MULTI_FUNC_FLAG_DISABLE(MF_TURTLE_MODE
) : MULTI_FUNC_FLAG_ENABLE(MF_TURTLE_MODE
);
73 case MULTI_FUNC_6
: // emergency ARM
74 if (!ARMING_FLAG(ARMED
)) {
75 emergencyArmingUpdate(true, true);
82 bool isNextMultifunctionItemAvailable(void)
84 return nextItemIsAvailable
;
87 void setMultifunctionSelection(multi_function_e item
)
89 selectedItem
= item
== MULTI_FUNC_END
? MULTI_FUNC_1
: item
;
90 nextItemIsAvailable
= false;
93 multi_function_e
multiFunctionSelection(void)
95 static timeMs_t startTimer
;
96 static timeMs_t selectTimer
;
97 static bool toggle
= true;
98 const timeMs_t currentTime
= millis();
100 if (IS_RC_MODE_ACTIVE(BOXMULTIFUNCTION
)) {
102 if (currentTime
- selectTimer
> 3000) { // 3s selection duration to activate selected function
103 multiFunctionApply(selectedItem
);
105 selectedItem
= MULTI_FUNC_NONE
;
106 nextItemIsAvailable
= false;
109 if (selectedItem
== MULTI_FUNC_NONE
) {
112 selectTimer
= currentTime
;
113 nextItemIsAvailable
= true;
116 startTimer
= currentTime
;
118 } else if (startTimer
) {
119 if (!toggle
&& selectTimer
) {
120 setMultifunctionSelection(++selectedItem
);
122 if (currentTime
- startTimer
> 4000) { // 4s reset delay after mode deselected
124 selectedItem
= MULTI_FUNC_NONE
;