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 #define BOXID_NONE 255
40 BOXID_FLIGHTMODE_LAST
= BOXGPSRESCUE
,
42 // When new flight modes are added, the parameter group version for 'modeActivationConditions' in src/main/fc/rc_modes.c has to be incremented to ensure that the RC modes configuration is reset.
64 BOXFLIPOVERAFTERCRASH
,
78 BOXSTICKCOMMANDDISABLE
,
88 // type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
89 typedef struct boxBitmask_s
{ uint32_t bits
[(CHECKBOX_ITEM_COUNT
+ 31) / 32]; } boxBitmask_t
;
91 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
93 #define CHANNEL_RANGE_MIN 900
94 #define CHANNEL_RANGE_MAX 2100
96 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
97 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
99 #define MIN_MODE_RANGE_STEP 0
100 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
102 // steps are 25 apart
103 // a value of 0 corresponds to a channel value of 900 or less
104 // a value of 48 corresponds to a channel value of 2100 or more
105 // 48 steps between 900 and 2100
106 typedef struct channelRange_s
{
111 typedef struct modeActivationCondition_s
{
113 uint8_t auxChannelIndex
;
114 channelRange_t range
;
115 modeLogic_e modeLogic
;
117 } modeActivationCondition_t
;
119 PG_DECLARE_ARRAY(modeActivationCondition_t
, MAX_MODE_ACTIVATION_CONDITION_COUNT
, modeActivationConditions
);
121 #if defined(USE_CUSTOM_BOX_NAMES)
123 #define MAX_BOX_USER_NAME_LENGTH 16
125 typedef struct modeActivationConfig_s
{
126 char box_user_1_name
[MAX_BOX_USER_NAME_LENGTH
];
127 char box_user_2_name
[MAX_BOX_USER_NAME_LENGTH
];
128 char box_user_3_name
[MAX_BOX_USER_NAME_LENGTH
];
129 char box_user_4_name
[MAX_BOX_USER_NAME_LENGTH
];
130 } modeActivationConfig_t
;
132 PG_DECLARE(modeActivationConfig_t
, modeActivationConfig
);
135 typedef struct modeActivationProfile_s
{
136 modeActivationCondition_t modeActivationConditions
[MAX_MODE_ACTIVATION_CONDITION_COUNT
];
137 } modeActivationProfile_t
;
139 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
141 bool IS_RC_MODE_ACTIVE(boxId_e boxId
);
142 void rcModeUpdate(boxBitmask_t
*newState
);
144 bool airmodeIsEnabled(void);
146 bool isRangeActive(uint8_t auxChannelIndex
, const channelRange_t
*range
);
147 void updateActivatedModes(void);
148 bool isModeActivationConditionPresent(boxId_e modeId
);
149 bool isModeActivationConditionLinked(boxId_e modeId
);
150 void removeModeActivationCondition(boxId_e modeId
);
151 bool isModeActivationConditionConfigured(const modeActivationCondition_t
*mac
, const modeActivationCondition_t
*emptyMac
);
152 void analyzeModeActivationConditions(void);