Skip to content

Commit 82e1736

Browse files
committed
update irqConfig examples
1 parent 0c5463e commit 82e1736

File tree

4 files changed

+33
-66
lines changed

4 files changed

+33
-66
lines changed

examples/InterruptConfigure/InterruptConfigure.ino

+6-16
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void setup() {
122122
// setup for RX mode
123123

124124
// let IRQ pin only trigger on "data_ready" event in RX mode
125-
flags.set_rx_dr(true);
125+
flags = StatusFlags(RF24_RX_DR);
126126
radio.setStatusFlags(flags);
127127

128128
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
@@ -154,19 +154,15 @@ void loop() {
154154
// Test the "data ready" event with the IRQ pin
155155

156156
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data sent' event"));
157-
flags.set_rx_dr(true);
158-
flags.set_tx_ds(false);
159-
flags.set_tx_df(true);
157+
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF);
160158
radio.setStatusFlags(flags);
161159
Serial.println(F(" Pinging RX node for 'data ready' event..."));
162160

163161
} else if (pl_iterator == 1) {
164162
// Test the "data sent" event with the IRQ pin
165163

166164
Serial.println(F("\nConfiguring IRQ pin to ignore the 'data ready' event"));
167-
flags.set_rx_dr(false);
168-
flags.set_tx_ds(true);
169-
flags.set_tx_df(true);
165+
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF);
170166
radio.setStatusFlags(flags);
171167
Serial.println(F(" Pinging RX node for 'data sent' event..."));
172168

@@ -175,9 +171,7 @@ void loop() {
175171

176172
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
177173
// disable IRQ pin for this step
178-
flags.set_rx_dr(false);
179-
flags.set_tx_ds(false);
180-
flags.set_tx_df(false);
174+
flags = StatusFlags();
181175
radio.setStatusFlags(flags);
182176

183177
Serial.println(F("\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected."));
@@ -197,9 +191,7 @@ void loop() {
197191
// test the "data fail" event with the IRQ pin
198192

199193
Serial.println(F("\nConfiguring IRQ pin to reflect all events"));
200-
flags.set_rx_dr(true);
201-
flags.set_tx_ds(true);
202-
flags.set_tx_df(true);
194+
flags = StatusFlags(RF24_IRQ_ALL);
203195
radio.setStatusFlags(flags);
204196
Serial.println(F(" Pinging inactive RX node for 'data fail' event..."));
205197
}
@@ -284,9 +276,7 @@ void loop() {
284276
role = false;
285277

286278
// let IRQ pin only trigger on "data_ready" event in RX mode
287-
flags.set_rx_dr(true);
288-
flags.set_tx_ds(false);
289-
flags.set_tx_df(false);
279+
flags = StatusFlags(RF24_RX_DR);
290280
radio.setStatusFlags(flags);
291281

292282
// Fill the TX FIFO with 3 ACK payloads for the first 3 received

examples_linux/interruptConfigure.cpp

+5-15
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,15 @@ void master()
177177

178178
// Test the "data ready" event with the IRQ pin
179179
cout << "\nConfiguring IRQ pin to ignore the 'data sent' event\n";
180-
flags.set_rx_dr(true);
181-
flags.set_tx_ds(false);
182-
flags.set_tx_df(true);
180+
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF);
183181
radio.setStatusFlags(flags);
184182
cout << " Pinging RX node for 'data ready' event..." << endl;
185183
ping_n_wait(); // transmit a payload and detect the IRQ pin
186184
pl_iterator++; // increment iterator for next test
187185

188186
// Test the "data sent" event with the IRQ pin
189187
cout << "\nConfiguring IRQ pin to ignore the 'data ready' event\n";
190-
flags.set_rx_dr(false);
191-
flags.set_tx_ds(true);
192-
flags.set_tx_df(true);
188+
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF);
193189
radio.setStatusFlags(flags);
194190
cout << " Pinging RX node for 'data sent' event..." << endl;
195191
radio.flush_tx(); // flush payloads from any failed prior test
@@ -199,9 +195,7 @@ void master()
199195
// Use this iteration to fill the RX node's FIFO which sets us up for the next test.
200196
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin.
201197
// disable IRQ pin for this step
202-
flags.set_rx_dr(false);
203-
flags.set_tx_ds(false);
204-
flags.set_tx_df(false);
198+
flags = StatusFlags();
205199
radio.setStatusFlags(flags);
206200

207201
cout << "\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected.\n";
@@ -216,9 +210,7 @@ void master()
216210

217211
// test the "data fail" event with the IRQ pin
218212
cout << "\nConfiguring IRQ pin to reflect all events\n";
219-
flags.set_rx_dr(true);
220-
flags.set_tx_ds(true);
221-
flags.set_tx_df(true);
213+
flags = StatusFlags(RF24_IRQ_ALL);
222214
radio.setStatusFlags(flags);
223215
cout << " Pinging inactive RX node for 'data fail' event..." << endl;
224216
ping_n_wait(); // transmit a payload and detect the IRQ pin
@@ -239,9 +231,7 @@ void slave()
239231
{
240232

241233
// let IRQ pin only trigger on "data_ready" event in RX mode
242-
flags.set_rx_dr(true);
243-
flags.set_tx_ds(false);
244-
flags.set_tx_df(false);
234+
flags = StatusFlags(RF24_RX_DR);
245235
radio.setStatusFlags(flags);
246236

247237
// Fill the TX FIFO with 3 ACK payloads for the first 3 received

examples_linux/interrupt_configure.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
"""
77

88
import time
9-
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER, StatusFlags
9+
from RF24 import (
10+
RF24,
11+
RF24_PA_LOW,
12+
RF24_DRIVER,
13+
StatusFlags,
14+
RF24_TX_DF,
15+
RF24_TX_DS,
16+
RF24_RX_DR,
17+
RF24_IRQ_ALL,
18+
)
1019

1120
try:
1221
import gpiod
@@ -149,9 +158,7 @@ def master():
149158

150159
# on data ready test
151160
print("\nConfiguring IRQ pin to only ignore 'on data sent' event")
152-
flags.tx_df = True
153-
flags.tx_ds = False
154-
flags.rx_dr = True
161+
flags = StatusFlags(RF24_RX_DR | RF24_TX_DF)
155162
radio.setStatusFlags(flags)
156163
print(" Pinging slave node for an ACK payload...")
157164
pl_iterator[0] = 0
@@ -161,9 +168,7 @@ def master():
161168

162169
# on "data sent" test
163170
print("\nConfiguring IRQ pin to only ignore 'on data ready' event")
164-
flags.tx_df = True
165-
flags.tx_ds = True
166-
flags.rx_dr = False
171+
flags = StatusFlags(RF24_TX_DS | RF24_TX_DF)
167172
radio.setStatusFlags(flags)
168173
print(" Pinging slave node again...")
169174
pl_iterator[0] = 1
@@ -174,9 +179,7 @@ def master():
174179
# trigger slave node to exit by filling the slave node's RX FIFO
175180
print("\nSending one extra payload to fill RX FIFO on slave node.")
176181
print("Disabling IRQ pin for all events.")
177-
flags.tx_df = False
178-
flags.tx_ds = False
179-
flags.rx_dr = False
182+
flags = StatusFlags()
180183
radio.setStatusFlags(flags)
181184
if radio.write(tx_payloads[2]):
182185
print("Slave node should not be listening anymore.")
@@ -185,9 +188,7 @@ def master():
185188

186189
# on "data fail" test
187190
print("\nConfiguring IRQ pin to go active for all events.")
188-
flags.tx_df = True
189-
flags.tx_ds = True
190-
flags.rx_dr = True
191+
flags = StatusFlags(RF24_IRQ_ALL)
191192
radio.setStatusFlags(flags)
192193
print(" Sending a ping to inactive slave node...")
193194
radio.flush_tx() # just in case any previous tests failed
@@ -207,9 +208,7 @@ def slave(timeout=6): # will listen for 6 seconds before timing out
207208
# the "data sent" or "data fail" events will trigger when we
208209
# receive with ACK payloads enabled (& loaded in TX FIFO)
209210
print("\nDisabling IRQ pin for all events.")
210-
flags.tx_df = False
211-
flags.tx_ds = False
212-
flags.rx_dr = False
211+
flags = StatusFlags()
213212
radio.setStatusFlags(flags)
214213
# setup radio to receive pings, fill TX FIFO with ACK payloads
215214
radio.writeAckPayload(1, ack_payloads[0])

examples_pico/interruptConfigure.cpp

+7-19
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ uint8_t pl_iterator = 0;
3939
char tx_payloads[][tx_pl_size + 1] = {"Ping ", "Pong ", "Radio", "1FAIL"};
4040
char ack_payloads[][ack_pl_size + 1] = {"Yak ", "Back", " ACK"};
4141

42-
// A variable used to interpret and manipulate the IRQ pin.
43-
StatusFlags flags;
44-
4542
void interruptHandler(uint gpio, uint32_t events); // prototype to handle IRQ events
4643
void printRxFifo(); // prototype to print RX FIFO with 1 buffer
4744
void assessInterruptEvent(); // prototype to assess IRQ flags triggered
@@ -114,6 +111,7 @@ bool setup()
114111
// setup for RX mode
115112

116113
// let IRQ pin not trigger in RX mode
114+
StatusFlags flags;
117115
radio.setStatusFlags(flags);
118116

119117
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
@@ -145,19 +143,15 @@ void loop()
145143
// Test the "data ready" event with the IRQ pin
146144

147145
printf("\nConfiguring IRQ pin to ignore the 'data sent' event\n");
148-
flags.set_rx_dr(true);
149-
flags.set_tx_ds(false);
150-
flags.set_tx_df(true);
146+
StatusFlags flags(RF24_RX_DR | RF24_TX_DF);
151147
radio.setStatusFlags(flags);
152148
printf(" Pinging RX node for 'data ready' event...\n");
153149
}
154150
else if (pl_iterator == 1) {
155151
// Test the "data sent" event with the IRQ pin
156152

157153
printf("\nConfiguring IRQ pin to ignore the 'data ready' event\n");
158-
flags.set_rx_dr(false);
159-
flags.set_tx_ds(true);
160-
flags.set_tx_df(true);
154+
StatusFlags flags(RF24_TX_DS | RF24_TX_DF);
161155
radio.setStatusFlags(flags);
162156
printf(" Pinging RX node for 'data sent' event...\n");
163157
}
@@ -166,9 +160,7 @@ void loop()
166160

167161
// write() uses virtual interrupt flags that work despite the masking of the IRQ pin
168162
// disable IRQ pin for this step
169-
flags.set_rx_dr(false);
170-
flags.set_tx_ds(false);
171-
flags.set_tx_df(false);
163+
StatusFlags flags;
172164
radio.setStatusFlags(flags);
173165

174166
printf("\nSending 1 payload to fill RX node's FIFO. IRQ pin is neglected.\n");
@@ -190,9 +182,7 @@ void loop()
190182
// test the "data fail" event with the IRQ pin
191183

192184
printf("\nConfiguring IRQ pin to reflect all events\n");
193-
flags.set_rx_dr(true);
194-
flags.set_tx_ds(true);
195-
flags.set_tx_df(true);
185+
StatusFlags flags(RF24_IRQ_ALL);
196186
radio.setStatusFlags(flags);
197187
printf(" Pinging inactive RX node for 'data fail' event...\n");
198188
}
@@ -280,9 +270,7 @@ void loop()
280270

281271
role = false;
282272
// do not trigger IRQ pin in RX mode
283-
flags.set_rx_dr(false);
284-
flags.set_tx_ds(false);
285-
flags.set_tx_df(false);
273+
StatusFlags flags;
286274
radio.setStatusFlags(flags);
287275

288276
// Fill the TX FIFO with 3 ACK payloads for the first 3 received
@@ -322,7 +310,7 @@ void assessInterruptEvent()
322310
{
323311
// print IRQ status and all masking flags' states
324312
printf("\tIRQ pin is actively LOW\n"); // show that this function was called
325-
flags = radio.clearStatusFlags();
313+
StatusFlags flags = radio.clearStatusFlags();
326314
// Resetting the tx_df flag is required for
327315
// continued TX operations when a transmission fails.
328316
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)

0 commit comments

Comments
 (0)