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_BAD_RX_RECOVERY
= (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_RPMFILTER
= (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_ARM_SWITCH
= (1 << 24), // Needs to be the last element, since it's always activated if one of the others is active when arming
68 } armingDisableFlags_e
;
70 #define ARMING_DISABLE_FLAGS_COUNT (LOG2(ARMING_DISABLED_ARM_SWITCH) + 1)
72 extern const char *armingDisableFlagNames
[ARMING_DISABLE_FLAGS_COUNT
];
74 void setArmingDisabled(armingDisableFlags_e flag
);
75 void unsetArmingDisabled(armingDisableFlags_e flag
);
76 bool isArmingDisabled(void);
77 armingDisableFlags_e
getArmingDisableFlags(void);
80 ANGLE_MODE
= (1 << 0),
81 HORIZON_MODE
= (1 << 1),
83 // BARO_MODE = (1 << 3),
84 // GPS_HOME_MODE = (1 << 4),
85 // GPS_HOLD_MODE = (1 << 5),
86 HEADFREE_MODE
= (1 << 6),
87 // UNUSED_MODE = (1 << 7), // old autotune
88 PASSTHRU_MODE
= (1 << 8),
89 // RANGEFINDER_MODE= (1 << 9),
90 FAILSAFE_MODE
= (1 << 10),
91 GPS_RESCUE_MODE
= (1 << 11)
94 extern uint16_t flightModeFlags
;
96 #define DISABLE_FLIGHT_MODE(mask) disableFlightMode(mask)
97 #define ENABLE_FLIGHT_MODE(mask) enableFlightMode(mask)
98 #define FLIGHT_MODE(mask) (flightModeFlags & (mask))
100 // macro to initialize map from boxId_e to log2(flightModeFlags). Keep it in sync with flightModeFlags_e enum.
101 // [BOXARM] is left unpopulated
102 #define BOXID_TO_FLIGHT_MODE_MAP_INITIALIZER { \
103 [BOXANGLE] = LOG2(ANGLE_MODE), \
104 [BOXHORIZON] = LOG2(HORIZON_MODE), \
105 [BOXMAG] = LOG2(MAG_MODE), \
106 [BOXHEADFREE] = LOG2(HEADFREE_MODE), \
107 [BOXPASSTHRU] = LOG2(PASSTHRU_MODE), \
108 [BOXFAILSAFE] = LOG2(FAILSAFE_MODE), \
109 [BOXGPSRESCUE] = LOG2(GPS_RESCUE_MODE), \
114 GPS_FIX_HOME
= (1 << 0),
116 CALIBRATE_MAG
= (1 << 2),
117 SMALL_ANGLE
= (1 << 3),
118 FIXED_WING
= (1 << 4) // set when in flying_wing or airplane mode. currently used by althold selection code
121 #define DISABLE_STATE(mask) (stateFlags &= ~(mask))
122 #define ENABLE_STATE(mask) (stateFlags |= (mask))
123 #define STATE(mask) (stateFlags & (mask))
125 extern uint8_t stateFlags
;
127 uint16_t enableFlightMode(flightModeFlags_e mask
);
128 uint16_t disableFlightMode(flightModeFlags_e mask
);
130 bool sensors(uint32_t mask
);
131 void sensorsSet(uint32_t mask
);
132 void sensorsClear(uint32_t mask
);
133 uint32_t sensorsMask(void);