add Safehome suspend function
[inav.git] / src / main / fc / multifunction.c
blob83ece659e7960cf9693f753443e1f7e1cf47adbd
1 /*
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/.
25 #include "platform.h"
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"
34 #include "io/osd.h"
35 #include "navigation/navigation.h"
37 static void multiFunctionApply(multi_function_e selectedItem)
39 switch (selectedItem) {
40 case MULTI_FUNC_NONE:
41 return;
42 case MULTI_FUNC_1: // redisplay current warnings
43 osdResetWarningFlags();
44 break;
45 case MULTI_FUNC_2: // control manual emergency landing
46 checkManualEmergencyLandingControl(ARMING_FLAG(ARMED));
47 break;
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) {
51 suspendSafehome();
53 #endif
54 break;
55 case MULTI_FUNC_4: // emergency ARM
56 if (!ARMING_FLAG(ARMED)) {
57 emergencyArmingUpdate(true, true);
59 break;
60 case MULTI_FUNC_END:
61 break;
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)) {
74 if (selectTimer) {
75 if (currentTime - selectTimer > 3000) { // 3s selection duration to activate selected function
76 multiFunctionApply(selectedItem);
77 selectTimer = 0;
78 selectedItem = MULTI_FUNC_NONE;
80 } else if (toggle) {
81 if (selectedItem == MULTI_FUNC_NONE) {
82 selectedItem++;
83 } else {
84 selectTimer = currentTime;
87 startTimer = currentTime;
88 toggle = false;
89 } else if (startTimer) {
90 if (!toggle && selectTimer) {
91 selectedItem = selectedItem == MULTI_FUNC_END - 1 ? MULTI_FUNC_1 : selectedItem + 1;
93 selectTimer = 0;
94 if (currentTime - startTimer > 2000) { // 2s reset delay after mode deselected
95 startTimer = 0;
96 selectedItem = MULTI_FUNC_NONE;
98 toggle = true;
101 return selectedItem;