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
63 BOXNAVCOURSEHOLD
= 35,
69 BOXMSPRCOVERRIDE
= 41,
74 BOXPLANWPMISSION
= 46,
78 BOXCHANGEMISSION
= 50,
80 BOXMULTIFUNCTION
= 52,
82 BOXMIXERTRANSITION
= 54,
91 // type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
92 typedef struct boxBitmask_s
{ BITARRAY_DECLARE(bits
, CHECKBOX_ITEM_COUNT
); } boxBitmask_t
;
94 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 40
96 #define CHANNEL_RANGE_MIN 900
97 #define CHANNEL_RANGE_MAX 2100
99 #define CHANNEL_RANGE_STEP_WIDTH 25
101 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + CHANNEL_RANGE_STEP_WIDTH * step)
102 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / CHANNEL_RANGE_STEP_WIDTH)
104 #define MIN_MODE_RANGE_STEP 0
105 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / CHANNEL_RANGE_STEP_WIDTH)
107 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
109 // steps are 25 apart
110 // a value of 0 corresponds to a channel value of 900 or less
111 // a value of 48 corresponds to a channel value of 2100 or more
112 // 48 steps between 900 and 1200
113 typedef struct channelRange_s
{
118 typedef struct modeActivationCondition_s
{
120 uint8_t auxChannelIndex
;
121 channelRange_t range
;
122 } modeActivationCondition_t
;
125 MODE_OPERATOR_OR
, // default
127 } modeActivationOperator_e
;
129 typedef struct modeActivationOperatorConfig_s
{
130 modeActivationOperator_e modeActivationOperator
;
131 } modeActivationOperatorConfig_t
;
133 PG_DECLARE_ARRAY(modeActivationCondition_t
, MAX_MODE_ACTIVATION_CONDITION_COUNT
, modeActivationConditions
);
134 PG_DECLARE(modeActivationOperatorConfig_t
, modeActivationOperatorConfig
);
136 bool IS_RC_MODE_ACTIVE(boxId_e boxId
);
137 void rcModeUpdate(boxBitmask_t
*newState
);
139 bool isModeActivationConditionPresent(boxId_e modeId
);
141 void processAirmode(void);
142 bool isUsingNavigationModes(void);
143 bool isRangeActive(uint8_t auxChannelIndex
, const channelRange_t
*range
);
145 void updateActivatedModes(void);
146 void updateUsedModeActivationConditionFlags(void);