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/>.
47 extern uint32_t rcModeActivationMask
;
49 #define IS_RC_MODE_ACTIVE(modeId) ((1 << modeId) & rcModeActivationMask)
50 #define ACTIVATE_RC_MODE(modeId) (rcModeActivationMask |= (1 << modeId))
52 typedef enum rc_alias
{
72 #define ROL_LO (1 << (2 * ROLL))
73 #define ROL_CE (3 << (2 * ROLL))
74 #define ROL_HI (2 << (2 * ROLL))
75 #define PIT_LO (1 << (2 * PITCH))
76 #define PIT_CE (3 << (2 * PITCH))
77 #define PIT_HI (2 << (2 * PITCH))
78 #define YAW_LO (1 << (2 * YAW))
79 #define YAW_CE (3 << (2 * YAW))
80 #define YAW_HI (2 << (2 * YAW))
81 #define THR_LO (1 << (2 * THROTTLE))
82 #define THR_CE (3 << (2 * THROTTLE))
83 #define THR_HI (2 << (2 * THROTTLE))
85 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 40
86 // 40 is enough for 1 mode for each position of 11 * 3 position switches and a 6 pos switch.
87 // however, that is unlikely because you don't define the 'off' positions, so for a 3 position
88 // switch it's normal that only 2 values would be configured.
89 // this leaves plenty of 'slots' free for cases where you enable multiple modes for a switch
90 // position (like gps rth + horizon + baro + beeper)
92 #define CHANNEL_RANGE_MIN 900
93 #define CHANNEL_RANGE_MAX 2100
95 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
96 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
98 #define MIN_MODE_RANGE_STEP 0
99 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
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
;
116 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
118 typedef struct controlRateConfig_s
{
123 uint8_t rollPitchRate
;
126 uint16_t tpa_breakpoint
; // Breakpoint where TPA is activated
127 } controlRateConfig_t
;
129 extern int16_t rcCommand
[4];
131 typedef struct rcControlsConfig_s
{
132 uint8_t deadband
; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
133 uint8_t yaw_deadband
; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
134 uint8_t alt_hold_deadband
; // defines the neutral zone of throttle stick during altitude hold, default setting is +/-40
135 uint8_t alt_hold_fast_change
; // when disabled, turn off the althold when throttle stick is out of deadband defined with alt_hold_deadband; when enabled, altitude changes slowly proportional to stick movement
136 } rcControlsConfig_t
;
138 bool areSticksInApModePosition(uint16_t ap_mode
);
139 throttleStatus_e
calculateThrottleStatus(rxConfig_t
*rxConfig
, uint16_t deadband3d_throttle
);
140 void processRcStickPositions(rxConfig_t
*rxConfig
, throttleStatus_e throttleStatus
, bool retarded_arm
, bool disarm_kill_switch
);
142 void updateActivatedModes(modeActivationCondition_t
*modeActivationConditions
);
149 ADJUSTMENT_THROTTLE_EXPO
,
150 ADJUSTMENT_PITCH_ROLL_RATE
,
152 ADJUSTMENT_PITCH_ROLL_P
,
153 ADJUSTMENT_PITCH_ROLL_I
,
154 ADJUSTMENT_PITCH_ROLL_D
,
158 ADJUSTMENT_RATE_PROFILE
159 } adjustmentFunction_e
;
161 #define ADJUSTMENT_FUNCTION_COUNT 13
164 ADJUSTMENT_MODE_STEP
,
165 ADJUSTMENT_MODE_SELECT
168 typedef struct adjustmentStepConfig_s
{
170 } adjustmentStepConfig_t
;
172 typedef struct adjustmentSelectConfig_s
{
173 uint8_t switchPositions
;
174 } adjustmentSelectConfig_t
;
176 typedef union adjustmentConfig_u
{
177 adjustmentStepConfig_t stepConfig
;
178 adjustmentSelectConfig_t selectConfig
;
181 typedef struct adjustmentConfig_s
{
182 uint8_t adjustmentFunction
;
184 adjustmentData_t data
;
185 } adjustmentConfig_t
;
187 typedef struct adjustmentRange_s
{
188 // when aux channel is in range...
189 uint8_t auxChannelIndex
;
190 channelRange_t range
;
192 // ..then apply the adjustment function to the auxSwitchChannel ...
193 uint8_t adjustmentFunction
;
194 uint8_t auxSwitchChannelIndex
;
197 uint8_t adjustmentIndex
;
200 #define ADJUSTMENT_INDEX_OFFSET 1
202 typedef struct adjustmentState_s
{
203 uint8_t auxChannelIndex
;
204 const adjustmentConfig_t
*config
;
208 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
210 #define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
212 void configureAdjustment(uint8_t index
, uint8_t auxChannelIndex
, const adjustmentConfig_t
*adjustmentConfig
);
213 void updateAdjustmentStates(adjustmentRange_t
*adjustmentRanges
);
214 void processRcAdjustments(controlRateConfig_t
*controlRateConfig
, rxConfig_t
*rxConfig
);
216 bool isUsingSticksForArming(void);
218 int32_t getRcStickDeflection(int32_t axis
, uint16_t midrc
);