NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rc.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight 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.
8  *
9  * Ninjaflight 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #include "../config/rx.h"
21 #include "../config/rc_controls.h"
22 #include "rc_command.h"
23 #include <stdbool.h>
24 
30 typedef enum {
31  // these keys are result of stick movement
49  // following keys are related to range functions and do not generate repeat events
59 } rc_key_t;
60 
67 typedef enum {
72 
82  void (*on_key_state)(struct rc_event_listener *self, rc_key_t key, rc_key_state_t newstate);
88  void (*on_key_repeat)(struct rc_event_listener *self, rc_key_t key, rc_key_state_t newstate);
89 };
90 
91 struct rc {
93  uint32_t boxes;
94  struct rx *rx;
97  uint8_t key_mask[RC_NUM_KEYS / 8 + 1];
98  uint8_t key_enabled_mask[RC_NUM_KEYS / 8 + 1];
99  uint32_t range_mask;
100 
101  const struct config *config;
102 };
103 
104 typedef enum {
108 
109 typedef enum {
113 
114 #define RC_KEY_REPEAT_MS 200
115 
116 #define CHANNEL_RANGE_MIN 900
117 #define CHANNEL_RANGE_MAX 2100
118 
119 #define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * (step))
120 #define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain((channelValue), CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
121 
122 #define MIN_MODE_RANGE_STEP 0
123 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
124 
125 // Roll/pitch rates are a proportion used for mixing, so it tops out at 1.0:
126 #define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX 100
127 
128 /* Meaningful yaw rates are effectively unbounded because they are treated as a rotation rate multiplier: */
129 #define CONTROL_RATE_CONFIG_YAW_RATE_MAX 255
130 
131 #define CONTROL_RATE_CONFIG_TPA_MAX 100
132 
133 #define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
134 
135 struct rx;
136 struct config;
142 void rc_init(struct rc *self, struct rx *rx, struct rc_event_listener *evl, const struct config *config);
143 
149 
157 int16_t rc_get_command(struct rc *self, uint8_t axis);
158 
166 void rc_update(struct rc *self);
Definition: rc.h:39
returned by rc_key_state() when the key is pressed
Definition: rc.h:69
Definition: rc.h:50
Definition: rc.h:41
Definition: rc.h:110
Definition: rc.h:106
Definition: config.h:81
Definition: rc.h:34
arming through box range
Definition: rc.h:51
returned by rc_key_state() when the key is not pressed
Definition: rc.h:70
const struct config * config
Definition: rc.h:101
rollPitchStatus_e
Definition: rc.h:109
Definition: rc.h:32
rc_key_state_t rc_key_state(struct rc *rc, rc_key_t key)
Definition: rc.c:171
rc_key_t
Definition: rc.h:30
Definition: rc.h:53
void rc_init(struct rc *self, struct rx *rx, struct rc_event_listener *evl, const struct config *config)
Definition: rc.c:157
Definition: rc.h:44
uint8_t key_enabled_mask[RC_NUM_KEYS/8+1]
Definition: rc.h:98
Definition: rc.h:42
uint32_t range_mask
Definition: rc.h:99
void(* on_key_repeat)(struct rc_event_listener *self, rc_key_t key, rc_key_state_t newstate)
Definition: rc.h:88
Definition: rc.h:33
throttleStatus_e
Definition: rc.h:104
RC commands state. Inputs are raw commands in range [1000-2000]. Outputs are RC commands in range [-5...
Definition: rc_command.h:39
Definition: rx.h:97
Definition: rc.h:48
returned by rc_key_state() if the key does not exist (not configured etc.)
Definition: rc.h:68
void rc_update(struct rc *self)
Definition: rc.c:113
Definition: rc.h:91
Definition: rc.h:78
Definition: rc.h:36
struct rc_event_listener * evl
Definition: rc.h:95
Definition: rc.h:45
Definition: rc.h:58
int16_t rc_get_command(struct rc *self, uint8_t axis)
Definition: rc.c:166
struct rx * rx
Definition: rc.h:94
Definition: rc.h:105
rc_key_state_t
Definition: rc.h:67
Definition: rc.h:52
Definition: rc.h:56
Definition: rc.h:35
Definition: rc.h:111
uint32_t boxes
Definition: rc.h:93
Definition: rc.h:46
void(* on_key_state)(struct rc_event_listener *self, rc_key_t key, rc_key_state_t newstate)
Definition: rc.h:82
Definition: rc.h:47
Definition: rc.h:38
uint8_t key_mask[RC_NUM_KEYS/8+1]
holds the key bits. This mask grows as we add more keys.
Definition: rc.h:97
Definition: rc.h:43
Definition: rc.h:55
Definition: rc.h:37
Definition: rc.h:57
Definition: rc.h:54
Definition: rc.h:40