rcProtocol  V.0.3.0
A protocol for diy transmitters/receivers
rcSettings.cpp
Go to the documentation of this file.
1 #include <RF24.h>
2 
3 #include "rcSettings.h"
4 
7  setEnableAck(true);
10  setDataRate(RF24_1MBPS);
11  setPayloadSize(32);
13  setRetryDelay(15);
14  setNumChannels(6);
15 }
16 
17 void RCSettings::setSettings(const uint8_t* settings) {
18  for(int i = 0; i < 32; i++) {
19  _settings[i] = settings[i];
20  }
21 }
22 
24  return _settings;
25 }
26 
28  //put Enable Dynamic Payload in bit 0 of byte 0
29  //0b00000001
30  _settings[0] = (enable ? (_settings[0] | 1) : (_settings[0] & (~1)));
31 }
32 
34  return _settings[0] & 1;
35 }
36 
37 void RCSettings::setEnableAck(bool enable) {
38  //Put Enable Ack in bit 1 of byte 0
39  //0b00000010: 2
40  _settings[0] = (enable ? (_settings[0] | 2) : (_settings[0] & (~2)));
41 }
42 
44  return (_settings[0] >> 1) & 1;
45 }
46 
48  //Put Enable Ack Payload in bit 2 of byte 0
49  //0b00000100: 4
50  _settings[0] = (enable ? (_settings[0] | 4) : (_settings[0] & (~4)));
51 }
52 
54  return (_settings[0] >> 2) & 1;
55 }
56 
57 void RCSettings::setDataRate(rf24_datarate_e datarate) {
58  //Put Datarate in bits 3 and 4 of byte 0
59  //0b00011000: 24
60  _settings[0] = (_settings[0] & (~24)) | (datarate << 3);
61 }
62 
63 rf24_datarate_e RCSettings::getDataRate() {
64  uint8_t datarate = (_settings[0] >> 3) & 3;
65  switch(datarate) {
66  case RF24_2MBPS:
67  return RF24_2MBPS;
68  case RF24_250KBPS:
69  return RF24_250KBPS;
70  case RF24_1MBPS:
71  default:
72  return RF24_1MBPS;
73  }
74 }
75 
76 void RCSettings::setStartChannel(uint8_t channel) {
77  _settings[1] = channel;
78 }
79 
81  return _settings[1];
82 }
83 
84 void RCSettings::setPayloadSize(uint8_t payload) {
85  _settings[2] = min(payload, 32);
86 }
87 
89  return _settings[2];
90 }
91 
92 void RCSettings::setCommsFrequency(uint8_t frequency) {
93  _settings[3] = frequency;
94 }
95 
97  return _settings[3];
98 }
99 
100 void RCSettings::setRetryDelay(uint8_t time) {
101  //Put Retry Delay in bits 0 through 3 of byte 4
102  //0b00001111: 15
103  _settings[4] = (_settings[4] & (~15)) | (time & 15);
104 }
105 
107  return _settings[4] & 15;
108 }
109 
110 void RCSettings::setNumChannels(uint8_t numChannels) {
111  _settings[5] = numChannels;
112 }
113 
115  return _settings[5];
116 }
117 
119  Serial.print("Dyn Load: ");
120  Serial.println(getEnableDynamicPayload() ? "True" : "False");
121 
122  Serial.print("Ack: ");
123  Serial.println(getEnableAck() ? "True" : "False");
124 
125  Serial.print("Ack Load: ");
126  Serial.println(getEnableAckPayload() ? "True" : "False");
127 
128  Serial.print("DataRate: ");
129  Serial.println(getDataRate() == RF24_1MBPS ? "1MBPS" :
130  (getDataRate() == RF24_250KBPS ? "250MBPS" : "2MBPS"));
131 
132  Serial.print("Channel: ");
133  Serial.println(getStartChannel());
134 
135  Serial.print("Payload SIze: ");
136  Serial.println(getPayloadSize());
137 
138  Serial.print("Frequency: ");
139  Serial.println(getCommsFrequency());
140 
141  Serial.print("Retry Delay: ");
142  Serial.println(getRetryDelay());
143 
144  Serial.print("Num Channels: ");
145  Serial.println(getNumChannels());
146 
147  Serial.println("Array:");
148  for(int i = 0; i < 5; i++) {
149  Serial.print(" ");
150  Serial.print(i);
151  Serial.print(": ");
152  Serial.println(_settings[i]);
153  }
154 }
rf24_datarate_e getDataRate()
Definition: rcSettings.cpp:63
void setEnableAck(bool enable)
Definition: rcSettings.cpp:37
void printSettings()
Definition: rcSettings.cpp:118
bool getEnableDynamicPayload()
Definition: rcSettings.cpp:33
void setSettings(const uint8_t *settings)
Definition: rcSettings.cpp:17
void setDataRate(rf24_datarate_e datarate)
Definition: rcSettings.cpp:57
uint8_t getStartChannel()
Definition: rcSettings.cpp:80
uint8_t getCommsFrequency()
Definition: rcSettings.cpp:96
uint8_t * getSettings()
Definition: rcSettings.cpp:23
uint8_t getRetryDelay()
Definition: rcSettings.cpp:106
void setCommsFrequency(uint8_t frequency)
Definition: rcSettings.cpp:92
void setNumChannels(uint8_t numChannels)
Definition: rcSettings.cpp:110
uint8_t getPayloadSize()
Definition: rcSettings.cpp:88
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
uint8_t getNumChannels()
Definition: rcSettings.cpp:114