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)
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/>.
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
[]= {
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
)
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
;