Meant to efficiently store and send data. It essentially "sits on top of" the RadioHead library that interfaces with the rf69 LoRA radio and allows me to very easily specify bits to turn on/off. In total, I think I can send all the controller data for my quadruped with 4 bytes... which should be SUPERRR fast! I may consider making this a standalone class(this is currently only useful for those using the same radio as me) but we shall see.
First, you need to instantiate an RH_RF69 radio object. The arguments specify SPI pins, and can be modified in Config.h
RH_RF69 rf69(RFM69_CS, RFM69_INT);
This needs to be passed to a 'Transfer object as such:
Transfer dataBuffer(&rf69, BUFFER_SIZE, key);
BUFFER _SIZE
is the size of the buffer array to be sent across devices, in bytes (can be modified in Config.h)
key is a 16 byte array for data encryption
init()
Initializes the dataBuffer and performs radio setup. This includes a manual reset of the radio via an interrupt pin on G0; this pin can be changed in Config.h
write(BIT_OR_BYTE bitOrByte, int index, int value)
Allows you to write data to the local Transfer
object
Where:
bitOrByte
specifies whether data is written to a bit or a byte in the buffer; choose between 'BIT' or 'BYTE
index
is the bit or byte you want to modify
- If you wish to modify a
BIT
, index allows you to select the number bit you wish to change. Indexes larger than 8 will shift to the next byte, and the bit's index in the byte is determined byindex % 8
, counting from right to left and starting from 0 in each byte. - If you wish to modify a
BYTE
, then you may select the index in the buffer to modify, starting with 0, obviously.value
is required only for bytes; this is simply the value you want to write the selected byte.
read(BIT_OR_BYTE bitOrByte, int index)
Allows you to read data in the local Transfer
object
Where:
bitOrByte
specifies whether data is written to a bit or a byte in the buffer; choose between BIT
or BYTE
index
is the bit or byte you want to read
- If you wish to read a
BIT
, index allows you to select the number bit you wish to read. Indexes larger than 8 will shift to the next byte, and the bit's index in the byte is determined byindex % 8
, counting from right to left and starting from 0 in each byte. - If you wish to read a
BYTE
, then you may select the index in the buffer to read, starting with 0, obviously.
This is recommended to be used after a call to receive()
, which handles the reception of a buffer sent fro manother device.
send(bool resetBuffer)
Sends a local buffer to a different device. Defaults to resetting the local buffer, but this can be overwritten by specifying false in the argument.
Note that this will wait for the buffer to be sent, which may cause issues
receive()
Receives a buffer from a different device. Returns true if successful, false if not.
For transmitting data, it makes sense to use write()
and send
. Send will reset the local buffer to 0 for future calls to write()
.
For receiving data, it makes sense to use receive()
, and upon a return of true
, to 'read() relevant data.