rcProtocol  V.0.3.0
A protocol for diy transmitters/receivers
rcGlobal.cpp
Go to the documentation of this file.
1 #include "rcGlobal.h"
2 
4 
5  //Setup Pair Settings
9  _pairSettings.setDataRate(RF24_1MBPS);
13 }
14 
15 int8_t RCGlobal::force_send(void* buf, uint8_t size, unsigned long timeout) {
16  uint32_t t = millis();
17  bool ack = false;
18  while(!ack && millis() - t < timeout) {
19  ack = _radio->write(buf, size);
20  }
21  if(!ack) {
22  return -1;
23  }
24 
25  return 0;
26 }
27 
28 int8_t RCGlobal::wait_till_available(unsigned long timeout) {
29  uint32_t t = millis();
30  while(!_radio->available() && millis() - t < timeout) {
31  delay(16);
32  }
33  if(millis() - t >= timeout) {
34  return -1;
35  }
36 
37  return 0;
38 }
39 
41  //Enable/disable Dynamic Payloads, and set payload size
42  if(settings->getEnableDynamicPayload()) {
43  _radio->enableDynamicPayloads();
44  } else {
45  _radio->disableDynamicPayloads();
46  _radio->setPayloadSize(settings->getPayloadSize());
47  }
48 
49  //Enable/Disable autoack, and custom payloads.
50  _radio->setAutoAck(settings->getEnableAck());
51  if(settings->getEnableAck() && settings->getEnableAckPayload()) {
52  _radio->enableAckPayload();
53  }
54 
55  //Set the channel
56  _radio->setChannel(settings->getStartChannel());
57 
58  //Set the data rate
59  _radio->setDataRate(settings->getDataRate());
60 
61  //Set the Retry delay. I might add retry number as an option later.
62  _radio->setRetries(settings->getRetryDelay(), 15);
63 }
64 
66  uint8_t tmp;
67  while(_radio->available()) {
68  _radio->read(&tmp, 1);
69  }
70 }
rf24_datarate_e getDataRate()
Definition: rcSettings.cpp:63
void setEnableAck(bool enable)
Definition: rcSettings.cpp:37
RF24 * _radio
Definition: rcGlobal.h:74
void apply_settings(RCSettings *settings)
Definition: rcGlobal.cpp:40
bool getEnableDynamicPayload()
Definition: rcSettings.cpp:33
RCGlobal()
Definition: rcGlobal.cpp:3
void setDataRate(rf24_datarate_e datarate)
Definition: rcSettings.cpp:57
uint8_t getStartChannel()
Definition: rcSettings.cpp:80
void flush_buffer()
Definition: rcGlobal.cpp:65
int8_t wait_till_available(unsigned long timeout)
Definition: rcGlobal.cpp:28
RCSettings _pairSettings
Definition: rcGlobal.h:72
uint8_t getRetryDelay()
Definition: rcSettings.cpp:106
uint8_t getPayloadSize()
Definition: rcSettings.cpp:88
int8_t force_send(void *buf, uint8_t size, unsigned long timeout)
Definition: rcGlobal.cpp:15
void setEnableAckPayload(bool enable)
Definition: rcSettings.cpp:47
void setPayloadSize(uint8_t payload)
Definition: rcSettings.cpp:84
void setStartChannel(uint8_t channel)
Definition: rcSettings.cpp:76
bool getEnableAck()
Definition: rcSettings.cpp:43
void setRetryDelay(uint8_t time)
Definition: rcSettings.cpp:100
bool getEnableAckPayload()
Definition: rcSettings.cpp:53
void setEnableDynamicPayload(bool enable)
Definition: rcSettings.cpp:27