rcProtocol  V.0.3.0
A protocol for diy transmitters/receivers
Public Types | Public Member Functions | List of all members
DeviceProtocol Class Reference

#include <rcDeviceProtocol.h>

+ Inheritance diagram for DeviceProtocol:

Public Types

typedef void() saveRemoteID(const uint8_t *id)
 
typedef void() loadRemoteID(uint8_t *id)
 
typedef bool() checkConnected()
 
typedef void() setConnected(bool connected)
 

Public Member Functions

 DeviceProtocol (RF24 *tranceiver, const uint8_t deviceId[])
 
int8_t begin (RCSettings *settings, checkConnected checkConnected, loadRemoteID loadRemoteID)
 
int8_t pair (saveRemoteID saveRemoteID)
 
bool isConnected ()
 
int8_t connect (loadRemoteID loadRemoteID, setConnected setConnected)
 
int8_t update (uint16_t channels[], uint8_t telemetry[], setConnected setConnected)
 
RCSettingsgetSettings ()
 

Detailed Description

Communication Protocol for receivers

Definition at line 27 of file rcDeviceProtocol.h.

Member Typedef Documentation

◆ saveRemoteID

typedef void() DeviceProtocol::saveRemoteID(const uint8_t *id)

Save the transmitter id to non-volitile memory.

Very simple, all that needs to be done, is to save the Id to memory, so that when the receiver tries to connect, it will know which id to request to connect with.

Parameters
id5 byte char array

Definition at line 38 of file rcDeviceProtocol.h.

◆ loadRemoteID

typedef void() DeviceProtocol::loadRemoteID(uint8_t *id)

Load the transmitter id from non-volitile memory.

Load the transmitter id set from saveRemoteID() into id

Parameters
id5 byte array to put remote id in.

Definition at line 46 of file rcDeviceProtocol.h.

◆ checkConnected

typedef bool() DeviceProtocol::checkConnected()

Check if the device was previously connected to the remote.

This checks the data set from setConnected(), and should be non-volitile

Returns
true if connected.

Definition at line 54 of file rcDeviceProtocol.h.

◆ setConnected

typedef void() DeviceProtocol::setConnected(bool connected)

Set whether the device is connected to the remote.

Note
This should be non-volitile, meaning the value set by this should remain after a power cycle or reset
Parameters
connectedtrue if connected, false if not.

Definition at line 63 of file rcDeviceProtocol.h.

Constructor & Destructor Documentation

◆ DeviceProtocol()

DeviceProtocol::DeviceProtocol ( RF24 *  tranceiver,
const uint8_t  deviceId[] 
)

Constructor

Creates a new instance of the protocol. You create an instance and send a reference to the RF24 driver as well as the id of the remote

Parameters
tranceiverA reference to the RF24 chip, this allows you to create your own instance, allowing multi-platform support
deviceIdThe 5 byte char array of the receiver's ID: ex "MyRcr"

Definition at line 6 of file rcDeviceProtocol.cpp.

Member Function Documentation

◆ begin()

int8_t DeviceProtocol::begin ( RCSettings settings,
DeviceProtocol::checkConnected  checkConnected,
DeviceProtocol::loadRemoteID  loadRemoteID 
)

Begin the Protocol

If the system power cycled or reset while in use, it will try to reconnect immidiately.

Note
There is no need to begin the RF24 driver, as this function already does this for you
Parameters
settingsRCSettings
checkConnectedcheckConnected()
loadRemoteIDloadRemoteID()
Returns
0
1 if reconnected to remote
-1 if unable to reconnect to remtoe

Definition at line 18 of file rcDeviceProtocol.cpp.

◆ pair()

int8_t DeviceProtocol::pair ( DeviceProtocol::saveRemoteID  saveRemoteID)

Attempt to pair with a transmitter

Note
The transmitter you are trying to pair with should also be in pair mode
Parameters
saveRemoteIDA function pointer to save the id of the transmitter.
Returns
0 if successful
RC_ERROR_ALREADY_CONNECTED if already connected to remote
RC_ERROR_TIMEOUT if no transmitter was found.
RC_ERROR_LOST_CONNECTION if transmitter stopped replying

Definition at line 58 of file rcDeviceProtocol.cpp.

◆ isConnected()

bool DeviceProtocol::isConnected ( )

Check if the receiver is connected with a transmitter.

Returns
true when connected.

Definition at line 237 of file rcDeviceProtocol.cpp.

◆ connect()

int8_t DeviceProtocol::connect ( DeviceProtocol::loadRemoteID  loadRemoteID,
DeviceProtocol::setConnected  setConnected 
)

Attempt to pair with a transmitter

Note
The transmitter you are trying to connect with should also be in connect mode, as well as paired with this device
Parameters
loadRemoteIDloadRemoteID()
setConnectedsetConnected()
Returns
0 if successful
RC_ERROR_ALREADY_CONNECTED if already connected to remote
RC_ERROR_TIMEOUT if no transmitter was found
RC_ERROR_LOST_CONNECTION if transmitter stopped replying
RC_ERROR_CONNECTION_REFUSED if the transmitter refused to connect
RC_ERROR_BAD_DATA if the settings are not properly set, or the transmitter sent unexpected data

Definition at line 116 of file rcDeviceProtocol.cpp.

◆ update()

int8_t DeviceProtocol::update ( uint16_t  channels[],
uint8_t  telemetry[],
DeviceProtocol::setConnected  setConnected 
)

Update the communications with the currently connected device

If there was a packet sent, it will process it.

Parameters
channelsRCSettings.setNumChannels() size array that is set when a standard packet is received.
telemetryRCSettings.setPayloadSize() size array of telemetry data to send to the transmitter
setConnectedsetConnected()
Returns
1 if channels were updated
0 if nothing happened
RC_ERROR_NOT_CONNECTED if not connected

Definition at line 267 of file rcDeviceProtocol.cpp.

◆ getSettings()

RCSettings * DeviceProtocol::getSettings ( )

Get pointer for the current settings

Returns
settings

Definition at line 332 of file rcDeviceProtocol.cpp.


The documentation for this class was generated from the following files: