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/>.
20 #include "config/parameter_group.h"
22 #include "fc/rc_controls.h"
23 #include "fc/rc_modes.h"
25 //#define USE_INFLIGHT_PROFILE_ADJUSTMENT - not currently enabled
29 ADJUSTMENT_RC_RATE
= 1,
30 ADJUSTMENT_RC_EXPO
= 2,
31 ADJUSTMENT_THROTTLE_EXPO
= 3,
32 ADJUSTMENT_PITCH_ROLL_RATE
= 4,
33 ADJUSTMENT_YAW_RATE
= 5,
34 ADJUSTMENT_PITCH_ROLL_P
= 6,
35 ADJUSTMENT_PITCH_ROLL_I
= 7,
36 ADJUSTMENT_PITCH_ROLL_D
= 8,
38 ADJUSTMENT_YAW_I
= 10,
39 ADJUSTMENT_YAW_D
= 11,
40 ADJUSTMENT_RATE_PROFILE
= 12, // Unused, placeholder for compatibility
41 ADJUSTMENT_PITCH_RATE
= 13,
42 ADJUSTMENT_ROLL_RATE
= 14,
43 ADJUSTMENT_PITCH_P
= 15,
44 ADJUSTMENT_PITCH_I
= 16,
45 ADJUSTMENT_PITCH_D
= 17,
46 ADJUSTMENT_ROLL_P
= 18,
47 ADJUSTMENT_ROLL_I
= 19,
48 ADJUSTMENT_ROLL_D
= 20,
49 ADJUSTMENT_RC_YAW_EXPO
= 21,
50 ADJUSTMENT_MANUAL_RC_EXPO
= 22,
51 ADJUSTMENT_MANUAL_RC_YAW_EXPO
= 23,
52 ADJUSTMENT_MANUAL_PITCH_ROLL_RATE
= 24,
53 ADJUSTMENT_MANUAL_ROLL_RATE
= 25,
54 ADJUSTMENT_MANUAL_PITCH_RATE
= 26,
55 ADJUSTMENT_MANUAL_YAW_RATE
= 27,
56 ADJUSTMENT_NAV_FW_CRUISE_THR
= 28,
57 ADJUSTMENT_NAV_FW_PITCH2THR
= 29,
58 ADJUSTMENT_ROLL_BOARD_ALIGNMENT
= 30,
59 ADJUSTMENT_PITCH_BOARD_ALIGNMENT
= 31,
60 ADJUSTMENT_LEVEL_P
= 32,
61 ADJUSTMENT_LEVEL_I
= 33,
62 ADJUSTMENT_LEVEL_D
= 34,
63 ADJUSTMENT_POS_XY_P
= 35,
64 ADJUSTMENT_POS_XY_I
= 36,
65 ADJUSTMENT_POS_XY_D
= 37,
66 ADJUSTMENT_POS_Z_P
= 38,
67 ADJUSTMENT_POS_Z_I
= 39,
68 ADJUSTMENT_POS_Z_D
= 40,
69 ADJUSTMENT_HEADING_P
= 41,
70 ADJUSTMENT_VEL_XY_P
= 42,
71 ADJUSTMENT_VEL_XY_I
= 43,
72 ADJUSTMENT_VEL_XY_D
= 44,
73 ADJUSTMENT_VEL_Z_P
= 45,
74 ADJUSTMENT_VEL_Z_I
= 46,
75 ADJUSTMENT_VEL_Z_D
= 47,
76 ADJUSTMENT_FW_MIN_THROTTLE_DOWN_PITCH_ANGLE
= 48,
77 ADJUSTMENT_VTX_POWER_LEVEL
= 49,
78 #ifdef USE_INFLIGHT_PROFILE_ADJUSTMENT
79 ADJUSTMENT_PROFILE
= 50,
81 ADJUSTMENT_FUNCTION_COUNT
// must be last
82 } adjustmentFunction_e
;
86 ADJUSTMENT_MODE_SELECT
89 typedef struct adjustmentStepConfig_s
{
91 } adjustmentStepConfig_t
;
93 typedef struct adjustmentSelectConfig_s
{
94 uint8_t switchPositions
;
95 } adjustmentSelectConfig_t
;
97 typedef union adjustmentConfig_u
{
98 adjustmentStepConfig_t stepConfig
;
99 adjustmentSelectConfig_t selectConfig
;
102 typedef struct adjustmentConfig_s
{
103 uint8_t adjustmentFunction
;
105 adjustmentData_t data
;
106 } adjustmentConfig_t
;
108 typedef struct adjustmentRange_s
{
109 // when aux channel is in range...
110 channelRange_t range
;
111 uint8_t auxChannelIndex
;
113 // ..then apply the adjustment function to the auxSwitchChannel ...
114 uint8_t adjustmentFunction
;
115 uint8_t auxSwitchChannelIndex
;
118 uint8_t adjustmentIndex
;
121 #define ADJUSTMENT_INDEX_OFFSET 1
123 typedef struct adjustmentState_s
{
124 const adjustmentConfig_t
*config
;
126 uint8_t auxChannelIndex
;
130 #ifndef MAX_SIMULTANEOUS_ADJUSTMENT_COUNT
131 #define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
134 #define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
136 PG_DECLARE_ARRAY(adjustmentRange_t
, MAX_ADJUSTMENT_RANGE_COUNT
, adjustmentRanges
);
138 void resetAdjustmentStates(void);
139 void updateAdjustmentStates(bool canUseRxData
);
140 struct controlRateConfig_s
;
141 void processRcAdjustments(struct controlRateConfig_s
*controlRateConfig
, bool canUseRxData
);
142 bool isAdjustmentFunctionSelected(uint8_t adjustmentFunction
);