rcProtocol
V.0.3.0
A protocol for diy transmitters/receivers
|
#include <rcRemoteProtocol.h>
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) |
RCSettings * | getSettings () |
Communication Protocol for transmitters
Definition at line 39 of file rcRemoteProtocol.h.
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.
id | 5 byte char array containing the ID of the receiver |
settings | 32 byte array of settings |
Definition at line 50 of file rcRemoteProtocol.h.
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:
id | 5 byte char array containing the ID of the receiver |
settings | 32 byte array to be loaded with the settings of the ID |
Definition at line 72 of file rcRemoteProtocol.h.
typedef void() RemoteProtocol::getLastConnection(uint8_t *id) |
Load the id of the last connected device.
This should load the id from setLastConnection() into id
id | 5 byte array to put the loaded id in |
Definition at line 83 of file rcRemoteProtocol.h.
typedef void() RemoteProtocol::setLastConnection(const uint8_t *id) |
Save the id of the current device to non-volitile memory.
id | 5 byte array to save the id. |
Definition at line 89 of file rcRemoteProtocol.h.
RemoteProtocol::RemoteProtocol | ( | RF24 * | tranceiver, |
const uint8_t | remoteId[] | ||
) |
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
tranceiver | A reference to the RF24 chip, this allows you to create your own instance, allowing multi-platform support |
remoteId | The 5 byte char array of the remotes ID: ex "MyRmt" |
Definition at line 7 of file rcRemoteProtocol.cpp.
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.
getLastConnection | Used for emergency reconnects |
checkIfValid | Used for emergency reconnects |
Definition at line 21 of file rcRemoteProtocol.cpp.
int8_t RemoteProtocol::pair | ( | RemoteProtocol::saveSettings | saveSettings | ) |
Attempt to pair with a receiver
saveSettings | A function pointer to save the settings of the paired device. |
Definition at line 92 of file rcRemoteProtocol.cpp.
int8_t RemoteProtocol::connect | ( | RemoteProtocol::checkIfValid | checkIfValid, |
RemoteProtocol::setLastConnection | setLastConnection | ||
) |
Attempt to connect with a previously paired device
checkIfValid | A function pointer to check if the found device has been paired, and to load the settings |
setLastConnection | setLastConnection() |
Definition at line 144 of file rcRemoteProtocol.cpp.
bool RemoteProtocol::isConnected | ( | ) |
Check if the transmitter is connected with a receiver.
Definition at line 264 of file rcRemoteProtocol.cpp.
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.
channels | array of size RCSettings.setNumChannels() to send |
telemetry | optional array of size RCSettings.setPayloadSize() to receive data from the Receiver. |
Definition at line 292 of file rcRemoteProtocol.cpp.
int8_t RemoteProtocol::disconnect | ( | RemoteProtocol::setLastConnection | setLastConnection | ) |
Disconnect From the currently conencted device
Definition at line 336 of file rcRemoteProtocol.cpp.
RCSettings * RemoteProtocol::getSettings | ( | ) |
Get pointer for the current settings
Definition at line 365 of file rcRemoteProtocol.cpp.