Initial draft for gimbal support.
[inav.git] / src / main / fc / rc_modes.h
blobcac8528b6ad4975363220bc394ebe7ed0300a96f
1 /*
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/>.
18 #pragma once
20 #include <stdbool.h>
22 #include "common/bitarray.h"
24 #include "config/parameter_group.h"
26 #define BOXID_NONE 255
28 typedef enum {
29 BOXARM = 0,
30 BOXANGLE = 1,
31 BOXHORIZON = 2,
32 BOXNAVALTHOLD = 3, // old BOXBARO
33 BOXHEADINGHOLD = 4, // old MAG
34 BOXHEADFREE = 5,
35 BOXHEADADJ = 6,
36 BOXCAMSTAB = 7,
37 BOXNAVRTH = 8, // old GPSHOME
38 BOXNAVPOSHOLD = 9, // old GPSHOLD
39 BOXMANUAL = 10,
40 BOXBEEPERON = 11,
41 BOXLEDLOW = 12,
42 BOXLIGHTS = 13,
43 BOXNAVLAUNCH = 14,
44 BOXOSD = 15,
45 BOXTELEMETRY = 16,
46 BOXBLACKBOX = 17,
47 BOXFAILSAFE = 18,
48 BOXNAVWP = 19,
49 BOXAIRMODE = 20,
50 BOXHOMERESET = 21,
51 BOXGCSNAV = 22,
52 BOXSURFACE = 24,
53 BOXFLAPERON = 25,
54 BOXTURNASSIST = 26,
55 BOXAUTOTRIM = 27,
56 BOXAUTOTUNE = 28,
57 BOXCAMERA1 = 29,
58 BOXCAMERA2 = 30,
59 BOXCAMERA3 = 31,
60 BOXOSDALT1 = 32,
61 BOXOSDALT2 = 33,
62 BOXOSDALT3 = 34,
63 BOXNAVCOURSEHOLD = 35,
64 BOXBRAKING = 36,
65 BOXUSER1 = 37,
66 BOXUSER2 = 38,
67 BOXFPVANGLEMIX = 39,
68 BOXLOITERDIRCHN = 40,
69 BOXMSPRCOVERRIDE = 41,
70 BOXPREARM = 42,
71 BOXTURTLE = 43,
72 BOXNAVCRUISE = 44,
73 BOXAUTOLEVEL = 45,
74 BOXPLANWPMISSION = 46,
75 BOXSOARING = 47,
76 BOXUSER3 = 48,
77 BOXUSER4 = 49,
78 BOXCHANGEMISSION = 50,
79 BOXBEEPERMUTE = 51,
80 BOXMULTIFUNCTION = 52,
81 BOXMIXERPROFILE = 53,
82 BOXMIXERTRANSITION = 54,
83 BOXANGLEHOLD = 55,
84 BOXGIMBALLOCK = 56,
85 BOXGIMBALPLOCK = 57,
86 BOXGIMBALPRLOCK = 58,
87 BOXGIMBALCENTER = 59,
88 CHECKBOX_ITEM_COUNT
89 } boxId_e;
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 {
114 uint8_t startStep;
115 uint8_t endStep;
116 } channelRange_t;
118 typedef struct modeActivationCondition_s {
119 boxId_e modeId;
120 uint8_t auxChannelIndex;
121 channelRange_t range;
122 } modeActivationCondition_t;
124 typedef enum {
125 MODE_OPERATOR_OR, // default
126 MODE_OPERATOR_AND
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);