vtx: fix VTX_SETTINGS_POWER_COUNT and add dummy entries to saPowerNames
[inav.git] / src / main / fc / runtime_config.c
blob44118ef54b928f38d82d5cf3bb8aa5199c7d2aa5
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #include "common/utils.h"
24 #include "fc/runtime_config.h"
26 #include "io/beeper.h"
28 EXTENDED_FASTRAM uint32_t armingFlags = 0;
29 EXTENDED_FASTRAM uint32_t stateFlags = 0;
30 EXTENDED_FASTRAM uint32_t flightModeFlags = 0;
32 static EXTENDED_FASTRAM uint32_t enabledSensors = 0;
34 #if !defined(CLI_MINIMAL_VERBOSITY)
35 const char *armingDisableFlagNames[]= {
36 "FS", "ANGLE", "CAL", "OVRLD", "NAV", "COMPASS",
37 "ACC", "ARMSW", "HWFAIL", "BOXFS", "RX",
38 "THR", "CLI", "CMS", "OSD", "ROLL/PITCH", "AUTOTRIM", "OOM",
39 "SETTINGFAIL", "PWMOUT", "NOPREARM", "DSHOTBEEPER", "LANDED"
41 #endif
43 const armingFlag_e armDisableReasonsChecklist[] = {
44 ARMING_DISABLED_INVALID_SETTING,
45 ARMING_DISABLED_HARDWARE_FAILURE,
46 ARMING_DISABLED_PWM_OUTPUT_ERROR,
47 ARMING_DISABLED_COMPASS_NOT_CALIBRATED,
48 ARMING_DISABLED_ACCELEROMETER_NOT_CALIBRATED,
49 ARMING_DISABLED_RC_LINK,
50 ARMING_DISABLED_NAVIGATION_UNSAFE,
51 ARMING_DISABLED_ARM_SWITCH,
52 ARMING_DISABLED_BOXFAILSAFE,
53 ARMING_DISABLED_THROTTLE,
54 ARMING_DISABLED_CLI,
55 ARMING_DISABLED_CMS_MENU,
56 ARMING_DISABLED_OSD_MENU,
57 ARMING_DISABLED_ROLLPITCH_NOT_CENTERED,
58 ARMING_DISABLED_SERVO_AUTOTRIM,
59 ARMING_DISABLED_OOM,
60 ARMING_DISABLED_NO_PREARM,
61 ARMING_DISABLED_DSHOT_BEEPER
64 armingFlag_e isArmingDisabledReason(void)
66 // Shortcut, if we don't block arming at all
67 if (!isArmingDisabled()) {
68 return 0;
71 armingFlag_e reasons = armingFlags & ARMING_DISABLED_ALL_FLAGS;
73 // First check for "more important reasons"
74 for (unsigned ii = 0; ii < ARRAYLEN(armDisableReasonsChecklist); ii++) {
75 armingFlag_e flag = armDisableReasonsChecklist[ii];
76 if (flag & reasons) {
77 return flag;
81 // Fallback, we ended up with a blocker flag not included in armDisableReasonsChecklist[]
82 for (unsigned ii = 0; ii < sizeof(armingFlag_e) * 8; ii++) {
83 armingFlag_e flag = 1u << ii;
84 if (flag & reasons) {
85 return flag;
89 return 0;
92 /**
93 * Called at Rx update rate. Beeper sounded if flight mode state has changed.
95 void updateFlightModeChangeBeeper(void)
97 static uint32_t previousFlightModeFlags = 0;
99 if (flightModeFlags != previousFlightModeFlags) {
100 beeperConfirmationBeeps(1);
102 previousFlightModeFlags = flightModeFlags;
105 bool sensors(uint32_t mask)
107 return enabledSensors & mask;
110 void sensorsSet(uint32_t mask)
112 enabledSensors |= mask;
115 void sensorsClear(uint32_t mask)
117 enabledSensors &= ~(mask);
120 uint32_t sensorsMask(void)
122 return enabledSensors;
125 flightModeForTelemetry_e getFlightModeForTelemetry(void)
127 if (FLIGHT_MODE(FAILSAFE_MODE))
128 return FLM_FAILSAFE;
130 if (FLIGHT_MODE(MANUAL_MODE))
131 return FLM_MANUAL;
133 if (FLIGHT_MODE(NAV_LAUNCH_MODE))
134 return FLM_LAUNCH;
136 if (FLIGHT_MODE(NAV_RTH_MODE))
137 return FLM_RTH;
139 if (FLIGHT_MODE(NAV_POSHOLD_MODE))
140 return FLM_POSITION_HOLD;
142 if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE) && FLIGHT_MODE(NAV_ALTHOLD_MODE))
143 return FLM_CRUISE;
145 if (FLIGHT_MODE(NAV_COURSE_HOLD_MODE))
146 return FLM_COURSE_HOLD;
148 if (FLIGHT_MODE(NAV_WP_MODE))
149 return FLM_MISSION;
151 if (FLIGHT_MODE(NAV_ALTHOLD_MODE))
152 return FLM_ALTITUDE_HOLD;
154 if (FLIGHT_MODE(ANGLE_MODE))
155 return FLM_ANGLE;
157 if (FLIGHT_MODE(HORIZON_MODE))
158 return FLM_HORIZON;
160 if (FLIGHT_MODE(ANGLEHOLD_MODE))
161 return FLM_ANGLEHOLD;
163 return STATE(AIRMODE_ACTIVE) ? FLM_ACRO_AIR : FLM_ACRO;
166 #ifdef USE_SIMULATOR
167 simulatorData_t simulatorData = {
168 .flags = 0,
169 .debugIndex = 0,
170 .vbat = 0
172 #endif