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

#include <rcRemoteProtocol.h>

+ Inheritance diagram for RemoteProtocol:

Public Types

typedef void() saveSettings(const uint8_t *id, const uint8_t *settings)
typedef bool() checkIfValid(const uint8_t *id, uint8_t *settings)
typedef void() getLastConnection(uint8_t *id)
typedef void() setLastConnection(const uint8_t *id)

Public Member Functions

 RemoteProtocol (RF24 *tranceiver, const uint8_t remoteId[])
int8_t begin (getLastConnection getLastConnection, checkIfValid checkIfValid)
int8_t pair (saveSettings saveSettings)
int8_t connect (checkIfValid checkIfValid, setLastConnection setLastConnection)
bool isConnected ()
int8_t update (uint16_t channels[], uint8_t telemetry[]=NULL)
int8_t disconnect (setLastConnection setLastConnection)
RCSettingsgetSettings ()

Detailed Description

Communication Protocol for transmitters

Definition at line 39 of file rcRemoteProtocol.h.

Member Typedef Documentation

◆ saveSettings

typedef void() RemoteProtocol::saveSettings(const uint8_t *id, const uint8_t *settings)

Save settings to non-volitile memory, such as EEPROM

The function should save both the id, and settings to some form of non-volitile memory. This can be done in any way as long as the data can be retrieved, and checked.

id5 byte char array containing the ID of the receiver
settings32 byte array of settings

Definition at line 50 of file rcRemoteProtocol.h.

◆ checkIfValid

typedef bool() RemoteProtocol::checkIfValid(const uint8_t *id, uint8_t *settings)

Check if the given id has been paired, and load the corresponding settings into the settings array.

If the id is not found, the settings should not be changed, and return false.

Here is a heavily simplified example:

if(findID(id) == true) {
return true;
} else {
return false;
id5 byte char array containing the ID of the receiver
settings32 byte array to be loaded with the settings of the ID
true if the check was successful

Definition at line 72 of file rcRemoteProtocol.h.

◆ getLastConnection

typedef void() RemoteProtocol::getLastConnection(uint8_t *id)

Load the id of the last connected device.

This should load the id from setLastConnection() into id

This is used in begin(), so any classes used by this function should be setup before begin() is called
id5 byte array to put the loaded id in

Definition at line 83 of file rcRemoteProtocol.h.

◆ setLastConnection

typedef void() RemoteProtocol::setLastConnection(const uint8_t *id)

Save the id of the current device to non-volitile memory.

id5 byte array to save the id.

Definition at line 89 of file rcRemoteProtocol.h.

Constructor & Destructor Documentation

◆ RemoteProtocol()

RemoteProtocol::RemoteProtocol ( RF24 *  tranceiver,
const uint8_t  remoteId[] 


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

tranceiverA reference to the RF24 chip, this allows you to create your own instance, allowing multi-platform support
remoteIdThe 5 byte char array of the remotes ID: ex "MyRmt"

Definition at line 7 of file rcRemoteProtocol.cpp.

Member Function Documentation

◆ begin()

int8_t RemoteProtocol::begin ( RemoteProtocol::getLastConnection  getLastConnection,
RemoteProtocol::checkIfValid  checkIfValid 

Begin the Protocol

When begin is called, it will check if it was disconnected before it last shutdown. If it did not disconnect, It will try to reconnect.

There is no need to begin the RF24 driver, as this function does this for you
getLastConnectionUsed for emergency reconnects
checkIfValidUsed for emergency reconnects
1 if a previous connection was re-established
-1 if a previous connection was NOT re-established

Definition at line 21 of file rcRemoteProtocol.cpp.

◆ pair()

int8_t RemoteProtocol::pair ( RemoteProtocol::saveSettings  saveSettings)

Attempt to pair with a receiver

The receiver you are trying to pair with should also be in pair mode
saveSettingsA function pointer to save the settings of the paired device.
0 if successful
RC_ERROR_TIMEOUT if no receiver was found.
RC_ERROR_LOST_CONNECTION if receiver stoped replying
RC_ERROR_ALREADY_CONNECTED if the remote is already connected.

Definition at line 92 of file rcRemoteProtocol.cpp.

◆ connect()

int8_t RemoteProtocol::connect ( RemoteProtocol::checkIfValid  checkIfValid,
RemoteProtocol::setLastConnection  setLastConnection 

Attempt to connect with a previously paired device

The receiver should have already been paired with the remote, and in connect mode
checkIfValidA function pointer to check if the found device has been paired, and to load the settings
0 if successful
RC_ERROR_TIMEOUT if no receiver was found.
RC_ERROR_LOST_CONNECTION if receiver stopped replying
RC_ERROR_CONNECTION_REFUSED if the receiver is not on the pair list.
RC_ERROR_BAD_DATA if the settings are not set properly on both devices
RC_ERROR_ALREADY_CONNECTED if the remote is already connected to a device.

Definition at line 144 of file rcRemoteProtocol.cpp.

◆ isConnected()

bool RemoteProtocol::isConnected ( )

Check if the transmitter is connected with a receiver.

true when connected.

Definition at line 264 of file rcRemoteProtocol.cpp.

◆ update()

int8_t RemoteProtocol::update ( uint16_t  channels[],
uint8_t  telemetry[] = NULL 

Update the communications with the currently connected device

This function holds until a specific amount of time has passed since it was last called to fulfill RCSettings.setCommsFrequency()

If telemetry is received from the receiver, telemetry will be updated, and returns 1.

channelsarray of size RCSettings.setNumChannels() to send
telemetryoptional array of size RCSettings.setPayloadSize() to receive data from the Receiver.
>= 0 if successful
1 if telemetry was received
RC_INFO_TICK_TOO_SHORT if RCSettings.setCommsFrequency() is too high
RC_ERROR_NOT_CONNECTED if there is no device connected

Definition at line 292 of file rcRemoteProtocol.cpp.

◆ disconnect()

int8_t RemoteProtocol::disconnect ( RemoteProtocol::setLastConnection  setLastConnection)

Disconnect From the currently conencted device

Once you disconnect, you can't reconnect until both devices call the connect() command.
0 if successful

Definition at line 336 of file rcRemoteProtocol.cpp.

◆ getSettings()

RCSettings * RemoteProtocol::getSettings ( )

Get pointer for the current settings


Definition at line 365 of file rcRemoteProtocol.cpp.

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