Update cloud build defines (#14080)
[betaflight.git] / src / main / fc / rc_modes.h
blob04bd4f2f3a19ca8ce259b525daebb9a68d37b4e1
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include <stdbool.h>
25 #include "pg/pg.h"
27 #define BOXID_NONE 255
29 typedef enum {
30 // ARM flag
31 BOXARM = 0,
32 // FLIGHT_MODE
33 BOXANGLE,
34 BOXHORIZON,
35 BOXMAG,
36 BOXALTHOLD,
37 BOXHEADFREE,
38 BOXPASSTHRU,
39 BOXFAILSAFE,
40 BOXPOSHOLD,
41 BOXGPSRESCUE,
42 BOXID_FLIGHTMODE_LAST = BOXGPSRESCUE,
44 // When new flight modes are added, the parameter group version for 'modeActivationConditions' in src/main/fc/rc_modes.c has to be incremented to ensure that the RC modes configuration is reset.
46 // RCMODE flags
47 BOXANTIGRAVITY,
48 BOXHEADADJ,
49 BOXCAMSTAB,
50 BOXBEEPERON,
51 BOXLEDLOW,
52 BOXCALIB,
53 BOXOSD,
54 BOXTELEMETRY,
55 BOXSERVO1,
56 BOXSERVO2,
57 BOXSERVO3,
58 BOXBLACKBOX,
59 BOXAIRMODE,
60 BOX3D,
61 BOXFPVANGLEMIX,
62 BOXBLACKBOXERASE,
63 BOXCAMERA1,
64 BOXCAMERA2,
65 BOXCAMERA3,
66 BOXCRASHFLIP,
67 BOXPREARM,
68 BOXBEEPGPSCOUNT,
69 BOXVTXPITMODE,
70 BOXPARALYZE,
71 BOXUSER1,
72 BOXUSER2,
73 BOXUSER3,
74 BOXUSER4,
75 BOXPIDAUDIO,
76 BOXACROTRAINER,
77 BOXVTXCONTROLDISABLE,
78 BOXLAUNCHCONTROL,
79 BOXMSPOVERRIDE,
80 BOXSTICKCOMMANDDISABLE,
81 BOXBEEPERMUTE,
82 BOXREADY,
83 BOXLAPTIMERRESET,
84 CHECKBOX_ITEM_COUNT
85 } boxId_e;
87 typedef enum {
88 MODELOGIC_OR = 0,
89 MODELOGIC_AND
90 } modeLogic_e;
92 // type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
93 typedef struct boxBitmask_s { uint32_t bits[(CHECKBOX_ITEM_COUNT + 31) / 32]; } boxBitmask_t;
95 #define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
97 #define CHANNEL_RANGE_MIN 900
98 #define CHANNEL_RANGE_MAX 2100
100 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
101 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
103 #define MIN_MODE_RANGE_STEP 0
104 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
106 // steps are 25 apart
107 // a value of 0 corresponds to a channel value of 900 or less
108 // a value of 48 corresponds to a channel value of 2100 or more
109 // 48 steps between 900 and 2100
110 typedef struct channelRange_s {
111 uint8_t startStep;
112 uint8_t endStep;
113 } channelRange_t;
115 typedef struct modeActivationCondition_s {
116 boxId_e modeId;
117 uint8_t auxChannelIndex;
118 channelRange_t range;
119 modeLogic_e modeLogic;
120 boxId_e linkedTo;
121 } modeActivationCondition_t;
123 PG_DECLARE_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions);
125 #if defined(USE_CUSTOM_BOX_NAMES)
127 #define MAX_BOX_USER_NAME_LENGTH 16
128 #define BOX_USER_NAME_COUNT 4
129 STATIC_ASSERT(BOXUSER4 + 1 - BOXUSER1 == BOX_USER_NAME_COUNT, "Invalid BOX_USER_NAME_COUNT");
130 typedef struct modeActivationConfig_s {
131 char box_user_names[BOX_USER_NAME_COUNT][MAX_BOX_USER_NAME_LENGTH];
132 } modeActivationConfig_t;
134 PG_DECLARE(modeActivationConfig_t, modeActivationConfig);
135 #endif
137 typedef struct modeActivationProfile_s {
138 modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
139 } modeActivationProfile_t;
141 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
143 bool IS_RC_MODE_ACTIVE(boxId_e boxId);
144 void rcModeUpdate(const boxBitmask_t *newState);
146 bool isAirmodeEnabled(void);
148 bool isRangeActive(uint8_t auxChannelIndex, const channelRange_t *range);
149 void updateActivatedModes(void);
150 bool isModeActivationConditionPresent(boxId_e modeId);
151 bool isModeActivationConditionLinked(boxId_e modeId);
152 void removeModeActivationCondition(boxId_e modeId);
153 bool isModeActivationConditionConfigured(const modeActivationCondition_t *mac, const modeActivationCondition_t *emptyMac);
154 void analyzeModeActivationConditions(void);