Update actions to ubuntu-latest (#14114)
[betaflight.git] / src / main / fc / runtime_config.c
blob4dbe7ee8c93c74a15e1f39d7971f24d28579b6c0
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
27 #include "fc/runtime_config.h"
28 #include "io/beeper.h"
30 uint8_t armingFlags = 0;
31 uint8_t stateFlags = 0;
32 uint16_t flightModeFlags = 0;
34 static uint32_t enabledSensors = 0;
36 // Name must be no longer than OSD_WARNINGS_MAX_SIZE
37 // try to keep names within OSD_WARNINGS_PREFFERED_SIZE
38 const char *armingDisableFlagNames[]= {
39 "NOGYRO",
40 "FAILSAFE",
41 "RXLOSS",
42 "NOT_DISARMED",
43 "BOXFAILSAFE",
44 "RUNAWAY",
45 "CRASH",
46 "THROTTLE",
47 "ANGLE",
48 "BOOTGRACE",
49 "NOPREARM",
50 "LOAD",
51 "CALIB",
52 "CLI",
53 "CMS",
54 "BST",
55 "MSP",
56 "PARALYZE",
57 "GPS",
58 "RESCUE_SW",
59 "DSHOT_TELEM",
60 "REBOOT_REQD",
61 "DSHOT_BBANG",
62 "NO_ACC_CAL",
63 "MOTOR_PROTO",
64 "FLIP_SWITCH",
65 "ALT_HOLD_SW",
66 "POS_HOLD_SW",
67 "ARM_SWITCH",
69 STATIC_ASSERT(ARRAYLEN(armingDisableFlagNames) == ARMING_DISABLE_FLAGS_COUNT, armingDisableFlagNames_size_mismatch);
71 static armingDisableFlags_e armingDisableFlags = 0;
73 void setArmingDisabled(armingDisableFlags_e flag)
75 armingDisableFlags = armingDisableFlags | flag;
78 void unsetArmingDisabled(armingDisableFlags_e flag)
80 armingDisableFlags = armingDisableFlags & ~flag;
83 bool isArmingDisabled(void)
85 return armingDisableFlags;
88 armingDisableFlags_e getArmingDisableFlags(void)
90 return armingDisableFlags;
93 // return name for given flag
94 // will return first name (LSB) if multiple bits are passed
95 const char *getArmingDisableFlagName(armingDisableFlags_e flag)
97 if (!flag) {
98 return "NONE";
100 unsigned idx = ffs(flag & -flag) - 1; // use LSB if there are multiple bits set
101 return idx < ARRAYLEN(armingDisableFlagNames) ? armingDisableFlagNames[idx] : "UNKNOWN";
105 * Enables the given flight mode. A beep is sounded if the flight mode
106 * has changed. Returns the new 'flightModeFlags' value.
108 uint16_t enableFlightMode(flightModeFlags_e mask)
110 uint16_t oldVal = flightModeFlags;
112 flightModeFlags |= (mask);
113 if (flightModeFlags != oldVal)
114 beeperConfirmationBeeps(1);
115 return flightModeFlags;
119 * Disables the given flight mode. A beep is sounded if the flight mode
120 * has changed. Returns the new 'flightModeFlags' value.
122 uint16_t disableFlightMode(flightModeFlags_e mask)
124 uint16_t oldVal = flightModeFlags;
126 flightModeFlags &= ~(mask);
127 if (flightModeFlags != oldVal)
128 beeperConfirmationBeeps(1);
129 return flightModeFlags;
132 bool sensors(uint32_t mask)
134 return enabledSensors & mask;
137 void sensorsSet(uint32_t mask)
139 enabledSensors |= mask;
142 void sensorsClear(uint32_t mask)
144 enabledSensors &= ~(mask);
147 uint32_t sensorsMask(void)
149 return enabledSensors;