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/>.
23 #include "common/utils.h"
25 // FIXME some of these are flight modes, some of these are general status indicators
28 WAS_EVER_ARMED
= (1 << 1),
29 WAS_ARMED_WITH_PREARM
= (1 << 2)
32 extern uint8_t armingFlags
;
34 #define DISABLE_ARMING_FLAG(mask) (armingFlags &= ~(mask))
35 #define ENABLE_ARMING_FLAG(mask) (armingFlags |= (mask))
36 #define ARMING_FLAG(mask) (armingFlags & (mask))
39 * Arming disable flags are listed in the order of criticalness.
40 * (Beeper code can notify the most critical reason.)
43 ARMING_DISABLED_NO_GYRO
= (1 << 0),
44 ARMING_DISABLED_FAILSAFE
= (1 << 1),
45 ARMING_DISABLED_RX_FAILSAFE
= (1 << 2),
46 ARMING_DISABLED_NOT_DISARMED
= (1 << 3),
47 ARMING_DISABLED_BOXFAILSAFE
= (1 << 4),
48 ARMING_DISABLED_RUNAWAY_TAKEOFF
= (1 << 5),
49 ARMING_DISABLED_CRASH_DETECTED
= (1 << 6),
50 ARMING_DISABLED_THROTTLE
= (1 << 7),
51 ARMING_DISABLED_ANGLE
= (1 << 8),
52 ARMING_DISABLED_BOOT_GRACE_TIME
= (1 << 9),
53 ARMING_DISABLED_NOPREARM
= (1 << 10),
54 ARMING_DISABLED_LOAD
= (1 << 11),
55 ARMING_DISABLED_CALIBRATING
= (1 << 12),
56 ARMING_DISABLED_CLI
= (1 << 13),
57 ARMING_DISABLED_CMS_MENU
= (1 << 14),
58 ARMING_DISABLED_BST
= (1 << 15),
59 ARMING_DISABLED_MSP
= (1 << 16),
60 ARMING_DISABLED_PARALYZE
= (1 << 17),
61 ARMING_DISABLED_GPS
= (1 << 18),
62 ARMING_DISABLED_RESC
= (1 << 19),
63 ARMING_DISABLED_DSHOT_TELEM
= (1 << 20),
64 ARMING_DISABLED_REBOOT_REQUIRED
= (1 << 21),
65 ARMING_DISABLED_DSHOT_BITBANG
= (1 << 22),
66 ARMING_DISABLED_ACC_CALIBRATION
= (1 << 23),
67 ARMING_DISABLED_MOTOR_PROTOCOL
= (1 << 24),
68 ARMING_DISABLED_CRASHFLIP
= (1 << 25),
69 ARMING_DISABLED_ALTHOLD
= (1 << 26),
70 ARMING_DISABLED_POSHOLD
= (1 << 27),
71 ARMING_DISABLED_ARM_SWITCH
= (1 << 28) // Needs to be the last element, since it's always activated if one of the others is active when arming
72 } armingDisableFlags_e
;
74 #define ARMING_DISABLE_FLAGS_COUNT (LOG2(ARMING_DISABLED_ARM_SWITCH) + 1)
76 void setArmingDisabled(armingDisableFlags_e flag
);
77 void unsetArmingDisabled(armingDisableFlags_e flag
);
78 bool isArmingDisabled(void);
79 armingDisableFlags_e
getArmingDisableFlags(void);
80 const char *getArmingDisableFlagName(armingDisableFlags_e flag
);
83 ANGLE_MODE
= (1 << 0),
84 HORIZON_MODE
= (1 << 1),
86 ALT_HOLD_MODE
= (1 << 3),
87 // GPS_HOME_MODE = (1 << 4),
88 POS_HOLD_MODE
= (1 << 5),
89 HEADFREE_MODE
= (1 << 6),
90 // UNUSED_MODE = (1 << 7), // old autotune
91 PASSTHRU_MODE
= (1 << 8),
92 // RANGEFINDER_MODE= (1 << 9),
93 FAILSAFE_MODE
= (1 << 10),
94 GPS_RESCUE_MODE
= (1 << 11)
97 extern uint16_t flightModeFlags
;
99 #define DISABLE_FLIGHT_MODE(mask) disableFlightMode(mask)
100 #define ENABLE_FLIGHT_MODE(mask) enableFlightMode(mask)
101 #define FLIGHT_MODE(mask) (flightModeFlags & (mask))
103 // macro to initialize map from boxId_e to log2(flightModeFlags). Keep it in sync with flightModeFlags_e enum.
104 // [BOXARM] is left unpopulated
105 #define BOXID_TO_FLIGHT_MODE_MAP_INITIALIZER { \
106 [BOXANGLE] = LOG2(ANGLE_MODE), \
107 [BOXHORIZON] = LOG2(HORIZON_MODE), \
108 [BOXMAG] = LOG2(MAG_MODE), \
109 [BOXALTHOLD] = LOG2(ALT_HOLD_MODE), \
110 [BOXPOSHOLD] = LOG2(POS_HOLD_MODE), \
111 [BOXHEADFREE] = LOG2(HEADFREE_MODE), \
112 [BOXPASSTHRU] = LOG2(PASSTHRU_MODE), \
113 [BOXFAILSAFE] = LOG2(FAILSAFE_MODE), \
114 [BOXGPSRESCUE] = LOG2(GPS_RESCUE_MODE), \
119 GPS_FIX_HOME
= (1 << 0),
121 GPS_FIX_EVER
= (1 << 2),
124 #define DISABLE_STATE(mask) (stateFlags &= ~(mask))
125 #define ENABLE_STATE(mask) (stateFlags |= (mask))
126 #define STATE(mask) (stateFlags & (mask))
128 extern uint8_t stateFlags
;
130 uint16_t enableFlightMode(flightModeFlags_e mask
);
131 uint16_t disableFlightMode(flightModeFlags_e mask
);
133 bool sensors(uint32_t mask
);
134 void sensorsSet(uint32_t mask
);
135 void sensorsClear(uint32_t mask
);
136 uint32_t sensorsMask(void);