Skip to content

Commit e62f3bc

Browse files
committed
update examples again
1 parent 8121adb commit e62f3bc

File tree

8 files changed

+36
-70
lines changed

8 files changed

+36
-70
lines changed

examples/InterruptConfigure/InterruptConfigure.ino

+7-16
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ uint8_t pl_iterator = 0;
4949
char tx_payloads[][tx_pl_size + 1] = { "Ping ", "Pong ", "Radio", "1FAIL" };
5050
char ack_payloads[][ack_pl_size + 1] = { "Yak ", "Back", " ACK" };
5151

52-
// A variable to interpret and manipulate the radio's IRQ pin.
53-
StatusFlags flags;
54-
5552
void interruptHandler(); // prototype to handle IRQ events
5653
void printRxFifo(); // prototype to print RX FIFO with 1 buffer
5754

@@ -122,8 +119,7 @@ void setup() {
122119
// setup for RX mode
123120

124121
// let IRQ pin only trigger on "data_ready" event in RX mode
125-
flags = StatusFlags(RF24_RX_DR);
126-
radio.setStatusFlags(flags);
122+
radio.setStatusFlags(RF24_RX_DR);
127123

128124
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
129125
// transmissions on pipe 1
@@ -154,25 +150,22 @@ void loop() {
154150
// Test the "data ready" event with the IRQ pin
155151

156152
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data sent' event"));
157-
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF);
158-
radio.setStatusFlags(flags);
153+
radio.setStatusFlags(RF24_RX_DR | RF24_TX_DF);
159154
Serial.println(F(" Pinging RX node for 'data ready' event..."));
160155

161156
} else if (pl_iterator == 1) {
162157
// Test the "data sent" event with the IRQ pin
163158

164159
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data ready' event"));
165-
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF);
166-
radio.setStatusFlags(flags);
160+
radio.setStatusFlags(RF24_TX_DS | RF24_TX_DF);
167161
Serial.println(F(" Pinging RX node for 'data sent' event..."));
168162

169163
} else if (pl_iterator == 2) {
170164
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
171165

172166
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
173167
// disable IRQ pin for this step
174-
flags = StatusFlags();
175-
radio.setStatusFlags(flags);
168+
radio.setStatusFlags();
176169

177170
Serial.println(F("\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected."));
178171
// write() will call flush_tx() on 'data fail' events
@@ -191,8 +184,7 @@ void loop() {
191184
// test the "data fail" event with the IRQ pin
192185

193186
Serial.println(F("\nConfiguring IRQ pin to reflect all events"));
194-
flags = StatusFlags(RF24_IRQ_ALL);
195-
radio.setStatusFlags(flags);
187+
radio.setStatusFlags(RF24_IRQ_ALL);
196188
Serial.println(F(" Pinging inactive RX node for 'data fail' event..."));
197189
}
198190

@@ -276,8 +268,7 @@ void loop() {
276268
role = false;
277269

278270
// let IRQ pin only trigger on "data_ready" event in RX mode
279-
flags = StatusFlags(RF24_RX_DR);
280-
radio.setStatusFlags(flags);
271+
radio.setStatusFlags(RF24_RX_DR);
281272

282273
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
283274
// transmissions on pipe 1
@@ -309,7 +300,7 @@ void assessInterruptEvent() {
309300

310301
Serial.println(F("\tIRQ pin is actively LOW")); // show that this function was called
311302
delayMicroseconds(250);
312-
flags = radio.clearStatusFlags();
303+
StatusFlags flags(radio.clearStatusFlags());
313304
// Resetting the tx_df flag is required for
314305
// continued TX operations when a transmission fails.
315306
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)

examples/StreamingData/StreamingData.ino

+2-3
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,19 @@ void loop() {
106106
if (role) {
107107
// This device is a TX node
108108

109-
StatusFlags flags;
110109
radio.flush_tx();
111110
uint8_t i = 0;
112111
uint8_t failures = 0;
113112
unsigned long start_timer = micros(); // start the timer
114113
while (i < SIZE) {
115114
makePayload(i); // make the payload
116115
if (!radio.writeFast(&buffer, SIZE)) {
117-
radio.getStatusFlags(flags);
116+
StatusFlags flags(radio.getStatusFlags());
118117
if (flags.tx_df()) {
119118
failures++;
120119
// now we need to reset the tx_df flag and the radio's CE pin
121120
radio.ce(LOW);
122-
radio.clearStatusFlags(flags);
121+
radio.clearStatusFlags(RF24_TX_DF);
123122
radio.ce(HIGH);
124123
}
125124
// else the TX FIFO is full; just continue loop.

examples_linux/interruptConfigure.cpp

+6-14
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ uint8_t pl_iterator = 0;
6363
char tx_payloads[4][tx_pl_size + 1] = {"Ping ", "Pong ", "Radio", "1FAIL"};
6464
char ack_payloads[3][ack_pl_size + 1] = {"Yak ", "Back", " ACK"};
6565

66-
// A variable used to interpret and manipulate the IRQ pin.
67-
StatusFlags flags;
68-
6966
void interruptHandler(); // prototype to handle the interrupt request (IRQ) pin
7067
void setRole(); // prototype to set the node's role
7168
void master(); // prototype of the TX node's behavior
@@ -177,16 +174,14 @@ void master()
177174

178175
// Test the "data ready" event with the IRQ pin
179176
cout << "\nConfiguring IRQ pin to ignore the 'data sent' event\n";
180-
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF);
181-
radio.setStatusFlags(flags);
177+
radio.setStatusFlags(RF24_RX_DR | RF24_TX_DF);
182178
cout << " Pinging RX node for 'data ready' event..." << endl;
183179
ping_n_wait(); // transmit a payload and detect the IRQ pin
184180
pl_iterator++; // increment iterator for next test
185181

186182
// Test the "data sent" event with the IRQ pin
187183
cout << "\nConfiguring IRQ pin to ignore the 'data ready' event\n";
188-
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF);
189-
radio.setStatusFlags(flags);
184+
radio.setStatusFlags(RF24_TX_DS | RF24_TX_DF);
190185
cout << " Pinging RX node for 'data sent' event..." << endl;
191186
radio.flush_tx(); // flush payloads from any failed prior test
192187
ping_n_wait(); // transmit a payload and detect the IRQ pin
@@ -195,8 +190,7 @@ void master()
195190
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
196191
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin.
197192
// disable IRQ pin for this step
198-
flags = StatusFlags();
199-
radio.setStatusFlags(flags);
193+
radio.setStatusFlags();
200194

201195
cout << "\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected.\n";
202196
// write() will call flush_tx() on 'data fail' events
@@ -210,8 +204,7 @@ void master()
210204

211205
// test the "data fail" event with the IRQ pin
212206
cout << "\nConfiguring IRQ pin to reflect all events\n";
213-
flags = StatusFlags(RF24_IRQ_ALL);
214-
radio.setStatusFlags(flags);
207+
radio.setStatusFlags(RF24_IRQ_ALL);
215208
cout << " Pinging inactive RX node for 'data fail' event..." << endl;
216209
ping_n_wait(); // transmit a payload and detect the IRQ pin
217210

@@ -231,8 +224,7 @@ void slave()
231224
{
232225

233226
// let IRQ pin only trigger on "data_ready" event in RX mode
234-
flags = StatusFlags(RF24_RX_DR);
235-
radio.setStatusFlags(flags);
227+
radio.setStatusFlags(RF24_RX_DR);
236228

237229
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
238230
// transmissions on pipe 0.
@@ -286,7 +278,7 @@ void ping_n_wait()
286278

287279
cout << "\tIRQ pin is actively LOW" << endl; // show that this function was called
288280

289-
flags = radio.clearStatusFlags();
281+
StatusFlags flags(radio.clearStatusFlags());
290282
// Resetting the tx_df flag is required for
291283
// continued TX operations when a transmission fails.
292284
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)

examples_linux/interrupt_configure.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@
102102
tx_payloads = (b"Ping ", b"Pong ", b"Radio", b"1FAIL")
103103
ack_payloads = (b"Yak ", b"Back", b" ACK")
104104

105-
# a variable used interpret and manipulate the IRQ pin
106-
flags = StatusFlags()
107-
108105

109106
def interrupt_handler():
110107
"""This function is called when IRQ pin is detected active LOW"""
111108
print("\tIRQ pin went active LOW.")
112-
flags = radio.clearStatusFlags()
109+
flags = StatusFlags(radio.clearStatusFlags())
113110
# Resetting the tx_df flag is required for
114111
# continued TX operations when a transmission fails.
115112
# clearing the status flags resets the IRQ pin to its inactive state (HIGH)
@@ -158,8 +155,7 @@ def master():
158155

159156
# on data ready test
160157
print("\nConfiguring IRQ pin to only ignore 'on data sent' event")
161-
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF)
162-
radio.setStatusFlags(flags)
158+
radio.setStatusFlags(RF24_RX_DR | RF24_TX_DF)
163159
print(" Pinging slave node for an ACK payload...")
164160
pl_iterator[0] = 0
165161
radio.startFastWrite(tx_payloads[0], False) # False means expecting an ACK
@@ -168,8 +164,7 @@ def master():
168164

169165
# on "data sent" test
170166
print("\nConfiguring IRQ pin to only ignore 'on data ready' event")
171-
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF)
172-
radio.setStatusFlags(flags)
167+
radio.setStatusFlags(RF24_TX_DS | RF24_TX_DF)
173168
print(" Pinging slave node again...")
174169
pl_iterator[0] = 1
175170
radio.startFastWrite(tx_payloads[1], False) # False means expecting an ACK
@@ -179,17 +174,15 @@ def master():
179174
# trigger slave node to exit by filling the slave node's RX FIFO
180175
print("\nSending one extra payload to fill RX FIFO on slave node.")
181176
print("Disabling IRQ pin for all events.")
182-
flags = StatusFlags()
183-
radio.setStatusFlags(flags)
177+
radio.setStatusFlags()
184178
if radio.write(tx_payloads[2]):
185179
print("Slave node should not be listening anymore.")
186180
else:
187181
print("Slave node was unresponsive.")
188182

189183
# on "data fail" test
190184
print("\nConfiguring IRQ pin to go active for all events.")
191-
flags = StatusFlags(RF24_IRQ_ALL)
192-
radio.setStatusFlags(flags)
185+
radio.setStatusFlags(RF24_IRQ_ALL)
193186
print(" Sending a ping to inactive slave node...")
194187
radio.flush_tx() # just in case any previous tests failed
195188
pl_iterator[0] = 2
@@ -208,8 +201,7 @@ def slave(timeout=6): # will listen for 6 seconds before timing out
208201
# the "data sent" or "data fail" events will trigger when we
209202
# receive with ACK payloads enabled (& loaded in TX FIFO)
210203
print("\nDisabling IRQ pin for all events.")
211-
flags = StatusFlags()
212-
radio.setStatusFlags(flags)
204+
radio.setStatusFlags()
213205
# setup radio to receive pings, fill TX FIFO with ACK payloads
214206
radio.writeAckPayload(1, ack_payloads[0])
215207
radio.writeAckPayload(1, ack_payloads[1])

examples_linux/streamingData.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,19 @@ void master()
202202
{
203203
radio.stopListening(); // put radio in TX mode
204204

205-
StatusFlags flags;
206205
unsigned int failures = 0; // keep track of failures
207206
uint8_t i = 0;
208207
clock_gettime(CLOCK_MONOTONIC_RAW, &startTimer); // start the timer
209208
while (i < SIZE) {
210209
makePayload(i);
211210
if (!radio.writeFast(&buffer, SIZE)) {
212-
radio.getStatusFlags(flags);
211+
StatusFlags flags(radio.getStatusFlags());
213212
if (flags.tx_df()) {
214213
failures++;
215214
// failed to transmit a previous payload.
216215
// Now we need to reset the tx_df flag and the CE pin
217216
radio.ce(LOW);
218-
radio.clearStatusFlags(flags);
217+
radio.clearStatusFlags(RF24_TX_DF);
219218
radio.ce(HIGH);
220219
}
221220
// else the TX FIFO is full; just continue loop

examples_linux/streaming_data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import time
10-
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER, StatusFlags
10+
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER, StatusFlags, RF24_TX_DF
1111

1212
print(__file__) # print example name
1313

@@ -93,7 +93,6 @@ def master(count: int = 1):
9393
"""
9494
radio.stopListening() # put radio in TX mode
9595
radio.flush_tx() # clear the TX FIFO so we can use all 3 levels
96-
flags = StatusFlags()
9796
failures = 0 # keep track of manual retries
9897
start_timer = time.monotonic_ns() # start timer
9998
for multiplier in range(count): # repeat transmit the same data stream
@@ -102,11 +101,12 @@ def master(count: int = 1):
102101
buffer = make_buffer(buf_iter) # make a payload
103102

104103
if not radio.writeFast(buffer): # transmission failed
104+
flags = StatusFlags(radio.getStatusFlags())
105105
if flags.tx_df:
106106
failures += 1 # increment manual retry count
107107
# now we need to reset the tx_df flag and the radio's CE pin
108108
radio.ce(False)
109-
radio.clearStatusFlags(flags)
109+
flags = radio.clearStatusFlags(RF24_TX_DF)
110110
radio.ce(True)
111111
if failures > 99 and buf_iter < 7 and multiplier < 2:
112112
# we need to prevent an infinite loop

examples_pico/interruptConfigure.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ bool setup()
110110
else {
111111
// setup for RX mode
112112

113-
// let IRQ pin not trigger in RX mode
114-
StatusFlags flags;
115-
radio.setStatusFlags(flags);
113+
// disable IRQ pin in RX mode
114+
radio.setStatusFlags();
116115

117116
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
118117
// transmissions on pipe 1
@@ -143,25 +142,22 @@ void loop()
143142
// Test the "data ready" event with the IRQ pin
144143

145144
printf("\nConfiguring IRQ pin to ignore the 'data sent' event\n");
146-
StatusFlags flags(RF24_RX_DR | RF24_TX_DF);
147-
radio.setStatusFlags(flags);
145+
radio.setStatusFlags(RF24_RX_DR | RF24_TX_DF);
148146
printf(" Pinging RX node for 'data ready' event...\n");
149147
}
150148
else if (pl_iterator == 1) {
151149
// Test the "data sent" event with the IRQ pin
152150

153151
printf("\nConfiguring IRQ pin to ignore the 'data ready' event\n");
154-
StatusFlags flags(RF24_TX_DS | RF24_TX_DF);
155-
radio.setStatusFlags(flags);
152+
radio.setStatusFlags(RF24_TX_DS | RF24_TX_DF);
156153
printf(" Pinging RX node for 'data sent' event...\n");
157154
}
158155
else if (pl_iterator == 2) {
159156
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
160157

161158
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
162159
// disable IRQ pin for this step
163-
StatusFlags flags;
164-
radio.setStatusFlags(flags);
160+
radio.setStatusFlags();
165161

166162
printf("\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected.\n");
167163
// write() will call flush_tx() on 'data fail' events
@@ -182,8 +178,7 @@ void loop()
182178
// test the "data fail" event with the IRQ pin
183179

184180
printf("\nConfiguring IRQ pin to reflect all events\n");
185-
StatusFlags flags(RF24_IRQ_ALL);
186-
radio.setStatusFlags(flags);
181+
radio.setStatusFlags(RF24_IRQ_ALL);
187182
printf(" Pinging inactive RX node for 'data fail' event...\n");
188183
}
189184

@@ -270,8 +265,7 @@ void loop()
270265

271266
role = false;
272267
// do not trigger IRQ pin in RX mode
273-
StatusFlags flags;
274-
radio.setStatusFlags(flags);
268+
radio.setStatusFlags();
275269

276270
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
277271
// transmissions on pipe 1
@@ -310,7 +304,7 @@ void assessInterruptEvent()
310304
{
311305
// print IRQ status and all masking flags' states
312306
printf("\tIRQ pin is actively LOW\n"); // show that this function was called
313-
StatusFlags flags = radio.clearStatusFlags();
307+
StatusFlags flags(radio.clearStatusFlags());
314308
// Resetting the tx_df flag is required for
315309
// continued TX operations when a transmission fails.
316310
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)

examples_pico/streamingData.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,19 @@ void loop()
103103
if (role) {
104104
// This device is a TX node
105105

106-
StatusFlags flags;
107106
radio.flush_tx();
108107
uint8_t i = 0;
109108
uint8_t failures = 0;
110109
uint64_t start_timer = to_us_since_boot(get_absolute_time()); // start the timer
111110
while (i < SIZE) {
112111
makePayload(i); // make the payload
113112
if (!radio.writeFast(&buffer, SIZE)) {
114-
radio.getStatusFlags(flags);
113+
StatusFlags flags(radio.getStatusFlags());
115114
if (flags.tx_df()) {
116115
failures++;
117116
// now we need to reset the tx_df flag and the radio's CE pin.
118117
radio.ce(LOW);
119-
radio.clearStatusFlags(flags);
118+
radio.clearStatusFlags(RF24_TX_DF);
120119
radio.ce(HIGH);
121120
}
122121
// else the TX FIFO is full; just continue loop.

0 commit comments

Comments
 (0)