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 #include "fc/fc_core.h"
30 #include "fc/multifunction.h"
31 #include "fc/rc_modes.h"
32 #include "fc/runtime_config.h"
35 #include "navigation/navigation.h"
37 static void multiFunctionApply(multi_function_e selectedItem
)
39 switch (selectedItem
) {
42 case MULTI_FUNC_1
: // redisplay current warnings
43 osdResetWarningFlags();
45 case MULTI_FUNC_2
: // control manual emergency landing
46 checkManualEmergencyLandingControl(ARMING_FLAG(ARMED
));
48 case MULTI_FUNC_3
: // toggle Safehome suspend
49 #if defined(USE_SAFE_HOME)
50 if (navConfig()->general
.flags
.safehome_usage_mode
!= SAFEHOME_USAGE_OFF
) {
55 case MULTI_FUNC_4
: // emergency ARM
56 if (!ARMING_FLAG(ARMED
)) {
57 emergencyArmingUpdate(true, true);
65 multi_function_e
multiFunctionSelection(void)
67 static timeMs_t startTimer
;
68 static timeMs_t selectTimer
;
69 static multi_function_e selectedItem
= MULTI_FUNC_NONE
;
70 static bool toggle
= true;
71 const timeMs_t currentTime
= millis();
73 if (IS_RC_MODE_ACTIVE(BOXMULTIFUNCTION
)) {
75 if (currentTime
- selectTimer
> 3000) { // 3s selection duration to activate selected function
76 multiFunctionApply(selectedItem
);
78 selectedItem
= MULTI_FUNC_NONE
;
81 if (selectedItem
== MULTI_FUNC_NONE
) {
84 selectTimer
= currentTime
;
87 startTimer
= currentTime
;
89 } else if (startTimer
) {
90 if (!toggle
&& selectTimer
) {
91 selectedItem
= selectedItem
== MULTI_FUNC_END
- 1 ? MULTI_FUNC_1
: selectedItem
+ 1;
94 if (currentTime
- startTimer
> 2000) { // 2s reset delay after mode deselected
96 selectedItem
= MULTI_FUNC_NONE
;