2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
22 #include "common/bitarray.h"
24 #include "config/parameter_group.h"
26 #define BOXID_NONE 255
32 BOXNAVALTHOLD
= 3, // old BOXBARO
33 BOXHEADINGHOLD
= 4, // old MAG
37 BOXNAVRTH
= 8, // old GPSHOME
38 BOXNAVPOSHOLD
= 9, // old GPSHOLD
52 BOXKILLSWITCH
= 23, // old HEADING LOCK
64 BOXNAVCOURSEHOLD
= 35,
70 BOXMSPRCOVERRIDE
= 41,
75 BOXPLANWPMISSION
= 46,
79 BOXCHANGEMISSION
= 50,
83 // type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
84 typedef struct boxBitmask_s
{ BITARRAY_DECLARE(bits
, CHECKBOX_ITEM_COUNT
); } boxBitmask_t
;
86 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 40
88 #define CHANNEL_RANGE_MIN 900
89 #define CHANNEL_RANGE_MAX 2100
91 #define CHANNEL_RANGE_STEP_WIDTH 25
93 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + CHANNEL_RANGE_STEP_WIDTH * step)
94 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / CHANNEL_RANGE_STEP_WIDTH)
96 #define MIN_MODE_RANGE_STEP 0
97 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / CHANNEL_RANGE_STEP_WIDTH)
99 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
101 // steps are 25 apart
102 // a value of 0 corresponds to a channel value of 900 or less
103 // a value of 48 corresponds to a channel value of 2100 or more
104 // 48 steps between 900 and 1200
105 typedef struct channelRange_s
{
110 typedef struct modeActivationCondition_s
{
112 uint8_t auxChannelIndex
;
113 channelRange_t range
;
114 } modeActivationCondition_t
;
117 MODE_OPERATOR_OR
, // default
119 } modeActivationOperator_e
;
121 typedef struct modeActivationOperatorConfig_s
{
122 modeActivationOperator_e modeActivationOperator
;
123 } modeActivationOperatorConfig_t
;
125 PG_DECLARE_ARRAY(modeActivationCondition_t
, MAX_MODE_ACTIVATION_CONDITION_COUNT
, modeActivationConditions
);
126 PG_DECLARE(modeActivationOperatorConfig_t
, modeActivationOperatorConfig
);
128 bool IS_RC_MODE_ACTIVE(boxId_e boxId
);
129 void rcModeUpdate(boxBitmask_t
*newState
);
131 bool isModeActivationConditionPresent(boxId_e modeId
);
133 void processAirmode(void);
134 bool isUsingNavigationModes(void);
135 bool isRangeActive(uint8_t auxChannelIndex
, const channelRange_t
*range
);
137 void updateActivatedModes(void);
138 void updateUsedModeActivationConditionFlags(void);