Set blackbox file handler to NULL after closing file
[inav.git] / src / main / fc / rc_controls.h
blob3705a29c3a19ab267ec50085ab3f465e2677f4bc
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 CONTROL_DEADBAND 10 // Used to check if sticks are centered
24 typedef enum rc_alias {
25 ROLL = 0,
26 PITCH,
27 YAW,
28 THROTTLE,
29 AUX1, // 5
30 AUX2, // 6
31 AUX3, // 7
32 AUX4, // 8
33 AUX5, // 9
34 AUX6, // 10
35 AUX7, // 11
36 AUX8, // 12
37 AUX9, // 13
38 AUX10, // 14
39 AUX11, // 15
40 AUX12, // 16
41 AUX13, // 17
42 AUX14, // 18
43 #ifdef USE_24CHANNELS
44 AUX15, // 19
45 AUX16, // 20
46 AUX17, // 21
47 AUX18, // 22
48 AUX19, // 23
49 AUX20, // 24
50 #endif
51 } rc_alias_e;
53 typedef enum {
54 THROTTLE_LOW = 0,
55 THROTTLE_HIGH
56 } throttleStatus_e;
58 typedef enum {
59 THROTTLE_STATUS_TYPE_RC = 0,
60 THROTTLE_STATUS_TYPE_COMMAND
61 } throttleStatusType_e;
63 typedef enum {
64 NOT_CENTERED = 0,
65 CENTERED
66 } rollPitchStatus_e;
68 typedef enum {
69 STICK_CENTER = 0,
70 THROTTLE_THRESHOLD,
71 STICK_CENTER_ONCE
72 } airmodeHandlingType_e;
74 typedef enum {
75 ROL_LO = (1 << (2 * ROLL)),
76 ROL_CE = (3 << (2 * ROLL)),
77 ROL_HI = (2 << (2 * ROLL)),
79 PIT_LO = (1 << (2 * PITCH)),
80 PIT_CE = (3 << (2 * PITCH)),
81 PIT_HI = (2 << (2 * PITCH)),
83 YAW_LO = (1 << (2 * YAW)),
84 YAW_CE = (3 << (2 * YAW)),
85 YAW_HI = (2 << (2 * YAW)),
87 THR_LO = (1 << (2 * THROTTLE)),
88 THR_CE = (3 << (2 * THROTTLE)),
89 THR_HI = (2 << (2 * THROTTLE))
90 } stickPositions_e;
92 extern int16_t rcCommand[4];
94 typedef struct rcControlsConfig_s {
95 uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
96 uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
97 uint8_t pos_hold_deadband; // Deadband for position hold
98 uint8_t alt_hold_deadband; // Defines the neutral zone of throttle stick during altitude hold
99 uint16_t mid_throttle_deadband; // default throttle deadband from MIDRC
100 uint8_t airmodeHandlingType; // Defaults to ANTI_WINDUP triggered at sticks centered
101 uint16_t airmodeThrottleThreshold; // Throttle threshold for airmode initial activation
102 } rcControlsConfig_t;
104 PG_DECLARE(rcControlsConfig_t, rcControlsConfig);
106 typedef struct armingConfig_s {
107 bool fixed_wing_auto_arm; // Auto-arm fixed wing aircraft on throttle up and never disarm
108 bool disarm_always; // Disarm motors regardless of throttle value
109 uint16_t switchDisarmDelayMs; // additional delay between ARM box going off and actual disarm
110 uint16_t prearmTimeoutMs; // duration for which Prearm being activated is valid. after this, Prearm needs to be reset. 0 means Prearm does not timeout.
111 } armingConfig_t;
113 PG_DECLARE(armingConfig_t, armingConfig);
115 stickPositions_e getRcStickPositions(void);
116 bool checkStickPosition(stickPositions_e stickPos);
118 bool areSticksInApModePosition(uint16_t ap_mode);
119 bool areSticksDeflected(void);
120 bool isRollPitchStickDeflected(uint8_t deadband);
121 throttleStatus_e calculateThrottleStatus(throttleStatusType_e type);
122 int16_t throttleStickMixedValue(void);
123 rollPitchStatus_e calculateRollPitchCenterStatus(void);
124 void processRcStickPositions(bool isThrottleLow);
125 bool throttleStickIsLow(void);
127 int32_t getRcStickDeflection(int32_t axis);