Fix WS2812 led definition
[inav.git] / src / main / fc / rc_modes.h
bloba72be3ddb80296460d4354089762c62125f8f54e
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 BOXKILLSWITCH = 23, // old HEADING LOCK
53 BOXSURFACE = 24,
54 BOXFLAPERON = 25,
55 BOXTURNASSIST = 26,
56 BOXAUTOTRIM = 27,
57 BOXAUTOTUNE = 28,
58 BOXCAMERA1 = 29,
59 BOXCAMERA2 = 30,
60 BOXCAMERA3 = 31,
61 BOXOSDALT1 = 32,
62 BOXOSDALT2 = 33,
63 BOXOSDALT3 = 34,
64 BOXNAVCOURSEHOLD = 35,
65 BOXBRAKING = 36,
66 BOXUSER1 = 37,
67 BOXUSER2 = 38,
68 BOXFPVANGLEMIX = 39,
69 BOXLOITERDIRCHN = 40,
70 BOXMSPRCOVERRIDE = 41,
71 BOXPREARM = 42,
72 BOXTURTLE = 43,
73 BOXNAVCRUISE = 44,
74 BOXAUTOLEVEL = 45,
75 BOXPLANWPMISSION = 46,
76 BOXSOARING = 47,
77 BOXUSER3 = 48,
78 BOXUSER4 = 49,
79 BOXCHANGEMISSION = 50,
80 CHECKBOX_ITEM_COUNT
81 } boxId_e;
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 {
106 uint8_t startStep;
107 uint8_t endStep;
108 } channelRange_t;
110 typedef struct modeActivationCondition_s {
111 boxId_e modeId;
112 uint8_t auxChannelIndex;
113 channelRange_t range;
114 } modeActivationCondition_t;
116 typedef enum {
117 MODE_OPERATOR_OR, // default
118 MODE_OPERATOR_AND
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);