Fix WS2812 led definition
[inav.git] / src / main / fc / rc_controls.h
blobea23eae90758f1bdf23c8aee61591f5ed7e4c0bf
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 "config/parameter_group.h"
22 #define AIRMODE_THROTTLE_THRESHOLD 1300
24 typedef enum rc_alias {
25 ROLL = 0,
26 PITCH,
27 YAW,
28 THROTTLE,
29 AUX1,
30 AUX2,
31 AUX3,
32 AUX4,
33 AUX5,
34 AUX6,
35 AUX7,
36 AUX8,
37 AUX9,
38 AUX10,
39 AUX11,
40 AUX12
41 } rc_alias_e;
43 typedef enum {
44 THROTTLE_LOW = 0,
45 THROTTLE_HIGH
46 } throttleStatus_e;
48 typedef enum {
49 THROTTLE_STATUS_TYPE_RC = 0,
50 THROTTLE_STATUS_TYPE_COMMAND
51 } throttleStatusType_e;
53 typedef enum {
54 NOT_CENTERED = 0,
55 CENTERED
56 } rollPitchStatus_e;
58 typedef enum {
59 STICK_CENTER = 0,
60 THROTTLE_THRESHOLD,
61 STICK_CENTER_ONCE
62 } airmodeHandlingType_e;
64 typedef enum {
65 ROL_LO = (1 << (2 * ROLL)),
66 ROL_CE = (3 << (2 * ROLL)),
67 ROL_HI = (2 << (2 * ROLL)),
69 PIT_LO = (1 << (2 * PITCH)),
70 PIT_CE = (3 << (2 * PITCH)),
71 PIT_HI = (2 << (2 * PITCH)),
73 YAW_LO = (1 << (2 * YAW)),
74 YAW_CE = (3 << (2 * YAW)),
75 YAW_HI = (2 << (2 * YAW)),
77 THR_LO = (1 << (2 * THROTTLE)),
78 THR_CE = (3 << (2 * THROTTLE)),
79 THR_HI = (2 << (2 * THROTTLE))
80 } stickPositions_e;
82 extern int16_t rcCommand[4];
84 typedef struct rcControlsConfig_s {
85 uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
86 uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
87 uint8_t pos_hold_deadband; // Deadband for position hold
88 uint8_t control_deadband; // General deadband to check if sticks are deflected, us PWM.
89 uint8_t alt_hold_deadband; // Defines the neutral zone of throttle stick during altitude hold
90 uint16_t mid_throttle_deadband; // default throttle deadband from MIDRC
91 uint8_t airmodeHandlingType; // Defaults to ANTI_WINDUP triggered at sticks centered
92 uint16_t airmodeThrottleThreshold; // Throttle threshold for airmode initial activation
93 } rcControlsConfig_t;
95 PG_DECLARE(rcControlsConfig_t, rcControlsConfig);
97 typedef struct armingConfig_s {
98 bool fixed_wing_auto_arm; // Auto-arm fixed wing aircraft on throttle up and never disarm
99 bool disarm_kill_switch; // allow disarm via AUX switch regardless of throttle value
100 uint16_t switchDisarmDelayMs; // additional delay between ARM box going off and actual disarm
101 uint16_t prearmTimeoutMs; // duration for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout.
102 } armingConfig_t;
104 PG_DECLARE(armingConfig_t, armingConfig);
106 stickPositions_e getRcStickPositions(void);
107 bool checkStickPosition(stickPositions_e stickPos);
109 bool areSticksInApModePosition(uint16_t ap_mode);
110 bool areSticksDeflected(void);
111 bool isRollPitchStickDeflected(uint8_t deadband);
112 throttleStatus_e calculateThrottleStatus(throttleStatusType_e type);
113 int16_t throttleStickMixedValue(void);
114 rollPitchStatus_e calculateRollPitchCenterStatus(void);
115 void processRcStickPositions(bool isThrottleLow);
116 bool throttleStickIsLow(void);
118 int32_t getRcStickDeflection(int32_t axis);