NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rc.h File Reference
#include "../config/rx.h"
#include "../config/rc_controls.h"
#include "rc_command.h"
#include <stdbool.h>
Include dependency graph for rc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rc_event_listener
 
struct  rc
 

Macros

#define RC_KEY_REPEAT_MS   200
 
#define CHANNEL_RANGE_MIN   900
 
#define CHANNEL_RANGE_MAX   2100
 
#define MODE_STEP_TO_CHANNEL_VALUE(step)   (CHANNEL_RANGE_MIN + 25 * (step))
 
#define CHANNEL_VALUE_TO_STEP(channelValue)   ((constrain((channelValue), CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
 
#define MIN_MODE_RANGE_STEP   0
 
#define MAX_MODE_RANGE_STEP   ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
 
#define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX   100
 
#define CONTROL_RATE_CONFIG_YAW_RATE_MAX   255
 
#define CONTROL_RATE_CONFIG_TPA_MAX   100
 
#define IS_RANGE_USABLE(range)   ((range)->startStep < (range)->endStep)
 

Enumerations

enum  rc_key_t {
  RC_KEY_IDLE, RC_KEY_GYROCAL, RC_KEY_ACCCAL, RC_KEY_MAGCAL,
  RC_KEY_ACC_INFLIGHT_CALIB, RC_KEY_PROFILE1, RC_KEY_PROFILE2, RC_KEY_PROFILE3,
  RC_KEY_SAVE, RC_KEY_STICK_ARM, RC_KEY_STICK_DISARM, RC_KEY_ACC_TRIM_PITCH_INC,
  RC_KEY_ACC_TRIM_PITCH_DEC, RC_KEY_ACC_TRIM_ROLL_INC, RC_KEY_ACC_TRIM_ROLL_DEC, RC_KEY_DISPLAY_OFF,
  RC_KEY_DISPLAY_ON, RC_KEY_FUNC_LEVEL, RC_KEY_FUNC_ARM, RC_KEY_FUNC_BLEND,
  RC_KEY_FUNC_ALTSTAB, RC_KEY_FUNC_HEADSTAB, RC_KEY_FUNC_HEADFIX, RC_KEY_FUNC_CALIBRATE,
  RC_KEY_FUNC_BEEPER, RC_NUM_KEYS
}
 
enum  rc_key_state_t { RC_KEY_DISABLED, RC_KEY_PRESSED, RC_KEY_RELEASED }
 
enum  throttleStatus_e { THROTTLE_LOW = 0, THROTTLE_HIGH }
 
enum  rollPitchStatus_e { NOT_CENTERED = 0, CENTERED }
 

Functions

void rc_init (struct rc *self, struct rx *rx, struct rc_event_listener *evl, const struct config *config)
 
rc_key_state_t rc_key_state (struct rc *rc, rc_key_t key)
 
int16_t rc_get_command (struct rc *self, uint8_t axis)
 
void rc_update (struct rc *self)
 

Macro Definition Documentation

#define CHANNEL_RANGE_MAX   2100
#define CHANNEL_RANGE_MIN   900
#define CHANNEL_VALUE_TO_STEP (   channelValue)    ((constrain((channelValue), CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
#define CONTROL_RATE_CONFIG_ROLL_PITCH_RATE_MAX   100
#define CONTROL_RATE_CONFIG_TPA_MAX   100
#define CONTROL_RATE_CONFIG_YAW_RATE_MAX   255
#define IS_RANGE_USABLE (   range)    ((range)->startStep < (range)->endStep)
#define MAX_MODE_RANGE_STEP   ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
#define MIN_MODE_RANGE_STEP   0
#define MODE_STEP_TO_CHANNEL_VALUE (   step)    (CHANNEL_RANGE_MIN + 25 * (step))
#define RC_KEY_REPEAT_MS   200

Enumeration Type Documentation

This enum defines key state. To support cases where an rc range is not configured (ie you can't really tell if the key is pressed or released) the third option has been added which is returned by rc_key_state() if the key does not exist.

Enumerator
RC_KEY_DISABLED 

returned by rc_key_state() if the key does not exist (not configured etc.)

RC_KEY_PRESSED 

returned by rc_key_state() when the key is pressed

RC_KEY_RELEASED 

returned by rc_key_state() when the key is not pressed

enum rc_key_t

Defines supported virtual keys. Certain stick combinations may trigger these keys. Most of these keys specify a kind of virtual rc keyboard. How they are actually interpreted is up to the current state of the flight controller.

Enumerator
RC_KEY_IDLE 
RC_KEY_GYROCAL 
RC_KEY_ACCCAL 
RC_KEY_MAGCAL 
RC_KEY_ACC_INFLIGHT_CALIB 
RC_KEY_PROFILE1 
RC_KEY_PROFILE2 
RC_KEY_PROFILE3 
RC_KEY_SAVE 
RC_KEY_STICK_ARM 
RC_KEY_STICK_DISARM 
RC_KEY_ACC_TRIM_PITCH_INC 
RC_KEY_ACC_TRIM_PITCH_DEC 
RC_KEY_ACC_TRIM_ROLL_INC 
RC_KEY_ACC_TRIM_ROLL_DEC 
RC_KEY_DISPLAY_OFF 
RC_KEY_DISPLAY_ON 
RC_KEY_FUNC_LEVEL 
RC_KEY_FUNC_ARM 

arming through box range

RC_KEY_FUNC_BLEND 
RC_KEY_FUNC_ALTSTAB 
RC_KEY_FUNC_HEADSTAB 
RC_KEY_FUNC_HEADFIX 
RC_KEY_FUNC_CALIBRATE 
RC_KEY_FUNC_BEEPER 
RC_NUM_KEYS 
Enumerator
NOT_CENTERED 
CENTERED 
Enumerator
THROTTLE_LOW 
THROTTLE_HIGH 

Function Documentation

int16_t rc_get_command ( struct rc self,
uint8_t  axis 
)

This function is used to get stick commands after exponential curves have been applied to the rx input.

Parameters
axisone of ROLL, PITCH, YAW, THROTTLE
Returns
a value between -500 and 500.

Here is the call graph for this function:

void rc_init ( struct rc self,
struct rx rx,
struct rc_event_listener evl,
const struct config config 
)

Initializes a new rc struct.

Parameters
rxinstance of the underlying rx to read values from.
evlevent listener or NULL

Here is the call graph for this function:

rc_key_state_t rc_key_state ( struct rc rc,
rc_key_t  key 
)
Parameters
keythe key for which to return state
Returns
current state of the key (PRESSED, RELEASED, DISABLED)
void rc_update ( struct rc self)

Runs an iteration of the rc calculations. This function does not call update on the underlying receiver object - user is expected to update the receiver object outside of rc object (and possibly at a different rate). The responsibility of this function is mainly taking care of repeat logic and firing new events for keys that are pressed for a while.

Here is the call graph for this function: