Skip to content

Commit 756e6a9

Browse files
committed
remove StatusFlags struct
don't use `printStatus()` in arduino IRQ example
1 parent 00123c1 commit 756e6a9

File tree

11 files changed

+49
-168
lines changed

11 files changed

+49
-168
lines changed

RF24.cpp

-44
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,6 @@
1212

1313
/****************************************************************************/
1414

15-
int StatusFlags::toString(char* buf) const
16-
{
17-
return sprintf(buf, "rx_dr: %s, tx_ds: %s, tx_df: %s, rx_pipe: %d, tx_full: %s",
18-
rx_dr() ? "true" : "false", tx_ds() ? "true" : "false",
19-
tx_df() ? "true" : "false", rx_pipe(), tx_full() ? "true" : "false");
20-
}
21-
22-
/****************************************************************************/
23-
24-
const bool StatusFlags::tx_full() const
25-
{
26-
return value & _BV(TX_FULL);
27-
}
28-
29-
/****************************************************************************/
30-
31-
const uint8_t StatusFlags::rx_pipe() const
32-
{
33-
return (value >> RX_P_NO) & 7;
34-
}
35-
36-
/****************************************************************************/
37-
38-
const bool StatusFlags::tx_df() const
39-
{
40-
return value & RF24_TX_DF;
41-
}
42-
43-
/****************************************************************************/
44-
45-
const bool StatusFlags::tx_ds() const
46-
{
47-
return value & RF24_TX_DS;
48-
}
49-
50-
/****************************************************************************/
51-
52-
const bool StatusFlags::rx_dr() const
53-
{
54-
return value & RF24_RX_DR;
55-
}
56-
57-
/****************************************************************************/
58-
5915
void RF24::csn(bool mode)
6016
{
6117
#if defined(RF24_TINY)

RF24.h

+1-62
Original file line numberDiff line numberDiff line change
@@ -152,67 +152,6 @@ typedef enum
152152
RF24_IRQ_ALL = (1 << MASK_MAX_RT) | (1 << TX_DS) | (1 << RX_DR),
153153
} rf24_irq_flags_e;
154154

155-
/**
156-
* @brief A bit-field struct to represent the radio's STATUS byte.
157-
*/
158-
struct StatusFlags
159-
{
160-
// starting with bit 0 at the top...
161-
/// Signifies that the TX FIFO is fully occupied.
162-
const bool tx_full() const;
163-
/// @brief Represents the pipe number that received the first available payload in the RX FIFO.
164-
/// @remark This data shall be considered invalid if the @ref StatusFlags::rx_dr flag is `false`.
165-
const uint8_t rx_pipe() const;
166-
/// Represents an event where TX Data Failed to send.
167-
const bool tx_df() const;
168-
/// Represents an event where TX Data Sent successfully.
169-
const bool tx_ds() const;
170-
/// Represents an event where RX Data is Ready to `RF24::read()`.
171-
const bool rx_dr() const;
172-
173-
/**
174-
* @brief Convert this struct to a human understandable string.
175-
*
176-
* ```cpp
177-
* char buf[69] = {0};
178-
* StatusFlags flags;
179-
* flags.toString(buf);
180-
* ```
181-
*
182-
* Afterward, printing the string in `buf` should read something similar to:
183-
*
184-
* > rx_dr: false, tx_ds: false, tx_df: false, rx_pipe: 7, tx_full: false
185-
*
186-
* @param[out] buf The string buffer into which the StatusFlags description is stored.
187-
* This buffer needs to be at least 69 bytes long.
188-
* @returns The amount of bytes altered in the given `buf` parameter.
189-
*/
190-
int toString(char* buf) const;
191-
192-
/// The default initializer constructor.
193-
/// @see Details about `StatusFlags::toString()` show an example output of default values.
194-
StatusFlags() : value(0x0E) {};
195-
196-
/**
197-
* @brief Set the StatusFlags using constants defined by @ref rf24_irq_flags_e
198-
*
199-
* @param bits This value shall be a value of @ref rf24_irq_flags_e.
200-
* Enabling multiple flags can be done with bitwise OR operator (`|`).
201-
*
202-
* ```cpp
203-
* // only enable the "RX Data Ready" event
204-
* StatusFlags flags(RF24_RX_DR);
205-
*
206-
* // only enable the "TX Data Sent" and "TX Data Fail" events
207-
* flags = StatusFlags(RF24_TX_DF | RF24_TX_DS);
208-
* ```
209-
*/
210-
StatusFlags(uint8_t bits) : value(bits) {};
211-
212-
private:
213-
const uint8_t value;
214-
};
215-
216155
/**
217156
* @}
218157
* @brief Driver class for nRF24L01(+) 2.4GHz Wireless Transceiver
@@ -1250,7 +1189,7 @@ class RF24
12501189
* passed by reference.
12511190
*
12521191
* @note When used in an ISR (Interrupt Service routine), there is a chance that the
1253-
* @ref StatusFlags::rx_pipe() information is inaccurate. See available(uint8_t*) (or the
1192+
* returned bits 0b1110 (rx_pipe number) is inaccurate. See available(uint8_t*) (or the
12541193
* datasheet) for more detail.
12551194
*
12561195
* @param flags The IRQ flags to clear. Default value is all of them (@ref RF24_IRQ_ALL).

examples/InterruptConfigure/InterruptConfigure.ino

+9-9
Original file line numberDiff line numberDiff line change
@@ -300,32 +300,32 @@ void assessInterruptEvent() {
300300

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

308308
Serial.print(F("\tdata_sent: "));
309-
Serial.print(flags.tx_ds()); // print "data sent" flag state
309+
Serial.print((flags & RF24_TX_DS) > 0); // print "data sent" flag state
310310
Serial.print(F(", data_fail: "));
311-
Serial.print(flags.tx_df()); // print "data fail" flag state
311+
Serial.print((flags & RF24_TX_DF) > 0); // print "data fail" flag state
312312
Serial.print(F(", data_ready: "));
313-
Serial.println(flags.rx_dr()); // print "data ready" flag state
313+
Serial.println((flags & RF24_RX_DR) > 0); // print "data ready" flag state
314314

315-
if (flags.tx_df()) // if TX payload failed
316-
radio.flush_tx(); // clear all payloads from the TX FIFO
315+
if (flags & RF24_TX_DF) // if TX payload failed
316+
radio.flush_tx(); // clear all payloads from the TX FIFO
317317

318318
// print if test passed or failed. Unintentional fails mean the RX node was not listening.
319319
// pl_iterator has already been incremented by now
320320
if (pl_iterator <= 1) {
321321
Serial.print(F(" 'Data Ready' event test "));
322-
Serial.println(flags.rx_dr() ? F("passed") : F("failed"));
322+
Serial.println(flags & RF24_RX_DR ? F("passed") : F("failed"));
323323
} else if (pl_iterator == 2) {
324324
Serial.print(F(" 'Data Sent' event test "));
325-
Serial.println(flags.tx_ds() ? F("passed") : F("failed"));
325+
Serial.println(flags & RF24_TX_DS ? F("passed") : F("failed"));
326326
} else if (pl_iterator == 4) {
327327
Serial.print(F(" 'Data Fail' event test "));
328-
Serial.println(flags.tx_df() ? F("passed") : F("failed"));
328+
Serial.println(flags & RF24_TX_DF ? F("passed") : F("failed"));
329329
}
330330
got_interrupt = false; // reset this flag to prevent calling this function from loop()
331331
wait_for_event = false; // ready to continue with loop() operations

examples/StreamingData/StreamingData.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ void loop() {
113113
while (i < SIZE) {
114114
makePayload(i); // make the payload
115115
if (!radio.writeFast(&buffer, SIZE)) {
116-
StatusFlags flags(radio.getStatusFlags());
117-
if (flags.tx_df()) {
116+
uint8_t flags = radio.getStatusFlags();
117+
if (flags & RF24_TX_DF) {
118118
failures++;
119119
// now we need to reset the tx_df flag and the radio's CE pin
120120
radio.ce(LOW);

examples_linux/interruptConfigure.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -278,24 +278,24 @@ void ping_n_wait()
278278

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

281-
StatusFlags flags(radio.clearStatusFlags());
281+
uint8_t flags = radio.clearStatusFlags();
282282
// Resetting the tx_df flag is required for
283283
// continued TX operations when a transmission fails.
284284
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)
285-
char buf[69];
286-
flags.toString(buf);
287-
cout << "\t" << buf << endl; // print StatusFlags description
288285

289-
if (flags.tx_df()) // if TX payload failed
290-
radio.flush_tx(); // clear all payloads from the TX FIFO
286+
cout << "\t";
287+
radio.printStatus(flags); // print StatusFlags description
288+
289+
if (flags & RF24_TX_DF) // if TX payload failed
290+
radio.flush_tx(); // clear all payloads from the TX FIFO
291291

292292
// print if test passed or failed. Unintentional fails mean the RX node was not listening.
293293
if (pl_iterator == 0)
294-
cout << " 'Data Ready' event test " << (flags.rx_dr() ? "passed" : "failed") << endl;
294+
cout << " 'Data Ready' event test " << (flags & RF24_RX_DR ? "passed" : "failed") << endl;
295295
else if (pl_iterator == 1)
296-
cout << " 'Data Sent' event test " << (flags.tx_ds() ? "passed" : "failed") << endl;
296+
cout << " 'Data Sent' event test " << (flags & RF24_TX_DS ? "passed" : "failed") << endl;
297297
else if (pl_iterator == 3)
298-
cout << " 'Data Fail' event test " << (flags.tx_df() ? "passed" : "failed") << endl;
298+
cout << " 'Data Fail' event test " << (flags & RF24_TX_DF ? "passed" : "failed") << endl;
299299

300300
got_interrupt = false;
301301
}

examples_linux/interrupt_configure.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
RF24,
1111
RF24_PA_LOW,
1212
RF24_DRIVER,
13-
StatusFlags,
1413
RF24_TX_DF,
1514
RF24_TX_DS,
1615
RF24_RX_DR,
@@ -106,17 +105,25 @@
106105
def interrupt_handler():
107106
"""This function is called when IRQ pin is detected active LOW"""
108107
print("\tIRQ pin went active LOW.")
109-
flags = StatusFlags(radio.clearStatusFlags())
108+
flags = radio.clearStatusFlags()
110109
# Resetting the tx_df flag is required for
111110
# continued TX operations when a transmission fails.
112111
# clearing the status flags resets the IRQ pin to its inactive state (HIGH)
113-
print(f"\t{flags}")
112+
print("\t", end="")
113+
radio.printStatus(flags)
114114
if pl_iterator[0] == 0:
115-
print(" 'data ready' event test", ("passed" if flags.rx_dr else "failed"))
115+
print(
116+
" 'data ready' event test",
117+
("passed" if flags & RF24_RX_DR else "failed"),
118+
)
116119
elif pl_iterator[0] == 1:
117-
print(" 'data sent' event test", ("passed" if flags.tx_ds else "failed"))
120+
print(
121+
" 'data sent' event test", ("passed" if flags & RF24_TX_DS else "failed")
122+
)
118123
elif pl_iterator[0] == 2:
119-
print(" 'data fail' event test", ("passed" if flags.tx_df else "failed"))
124+
print(
125+
" 'data fail' event test", ("passed" if flags & RF24_TX_DF else "failed")
126+
)
120127

121128

122129
# setup IRQ GPIO pin

examples_linux/streamingData.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ void master()
208208
while (i < SIZE) {
209209
makePayload(i);
210210
if (!radio.writeFast(&buffer, SIZE)) {
211-
StatusFlags flags(radio.getStatusFlags());
212-
if (flags.tx_df()) {
211+
uint8_t flags = radio.getStatusFlags();
212+
if (flags & RF24_TX_DF) {
213213
failures++;
214214
// failed to transmit a previous payload.
215215
// Now we need to reset the tx_df flag and the CE pin

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, RF24_TX_DF
10+
from RF24 import RF24, RF24_PA_LOW, RF24_DRIVER, RF24_TX_DF
1111

1212
print(__file__) # print example name
1313

@@ -101,8 +101,8 @@ def master(count: int = 1):
101101
buffer = make_buffer(buf_iter) # make a payload
102102

103103
if not radio.writeFast(buffer): # transmission failed
104-
flags = StatusFlags(radio.getStatusFlags())
105-
if flags.tx_df:
104+
flags = radio.getStatusFlags()
105+
if flags & RF24_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)

examples_pico/interruptConfigure.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -304,28 +304,27 @@ void assessInterruptEvent()
304304
{
305305
// print IRQ status and all masking flags' states
306306
printf("\tIRQ pin is actively LOW\n"); // show that this function was called
307-
StatusFlags flags(radio.clearStatusFlags());
307+
uint8_t flags = radio.clearStatusFlags();
308308
// Resetting the tx_df flag is required for
309309
// continued TX operations when a transmission fails.
310310
// clearing the status flags resets the IRQ pin to its inactive state (HIGH)
311-
char buf[69];
312-
flags.toString(buf);
313311

314-
printf("\t%s\n", buf); // print status flags info
312+
printf("\t");
313+
radio.printStatus(flags); // print status flags info
315314

316-
if (flags.tx_df()) // if TX payload failed
317-
radio.flush_tx(); // clear all payloads from the TX FIFO
315+
if (flags & RF24_TX_DF) // if TX payload failed
316+
radio.flush_tx(); // clear all payloads from the TX FIFO
318317

319318
// print if test passed or failed. Unintentional fails mean the RX node was not listening.
320319
// pl_iterator has already been incremented by now
321320
if (pl_iterator <= 1) {
322-
printf(" 'Data Ready' event test %s\n", flags.rx_dr() ? "passed" : "failed");
321+
printf(" 'Data Ready' event test %s\n", flags & RF24_RX_DR ? "passed" : "failed");
323322
}
324323
else if (pl_iterator == 2) {
325-
printf(" 'Data Sent' event test %s\n", flags.tx_ds() ? "passed" : "failed");
324+
printf(" 'Data Sent' event test %s\n", flags & RF24_TX_DS ? "passed" : "failed");
326325
}
327326
else if (pl_iterator == 4) {
328-
printf(" 'Data Fail' event test %s\n", flags.tx_df() ? "passed" : "failed");
327+
printf(" 'Data Fail' event test %s\n", flags & RF24_TX_DF ? "passed" : "failed");
329328
}
330329
got_interrupt = false; // reset this flag to prevent calling this function from loop()
331330
wait_for_event = false; // ready to continue with loop() operations

examples_pico/streamingData.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ void loop()
110110
while (i < SIZE) {
111111
makePayload(i); // make the payload
112112
if (!radio.writeFast(&buffer, SIZE)) {
113-
StatusFlags flags(radio.getStatusFlags());
114-
if (flags.tx_df()) {
113+
uint8_t flags = radio.getStatusFlags();
114+
if (flags & RF24_TX_DF) {
115115
failures++;
116116
// now we need to reset the tx_df flag and the radio's CE pin.
117117
radio.ce(LOW);

pyRF24/pyRF24.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,6 @@ bp::tuple whatHappened_wrap(RF24& ref)
113113
return bp::make_tuple(tx_ok, tx_fail, tx_ready);
114114
}
115115

116-
std::string reprStatusFlags(StatusFlags& self)
117-
{
118-
char* buf = new char[69];
119-
self.toString(buf);
120-
std::string result = "<StatusFlags ";
121-
result += buf;
122-
result += ">";
123-
delete[] buf;
124-
return result;
125-
}
126-
127116
bp::tuple available_wrap(RF24& ref)
128117
{
129118
bool result;
@@ -306,15 +295,6 @@ BOOST_PYTHON_MODULE(RF24)
306295
.value("RF24_IRQ_NONE", RF24_IRQ_NONE)
307296
.export_values();
308297

309-
bp::class_<StatusFlags>("StatusFlags", bp::init<>())
310-
.def(bp::init<uint8_t>((bp::arg("bits"))))
311-
.add_property("rx_dr", &StatusFlags::rx_dr)
312-
.add_property("tx_ds", &StatusFlags::tx_ds)
313-
.add_property("tx_df", &StatusFlags::tx_df)
314-
.add_property("tx_full", &StatusFlags::tx_full)
315-
.add_property("rx_pipe", &StatusFlags::rx_pipe)
316-
.def("__repr__", &reprStatusFlags);
317-
318298
// ******************** RF24 class **************************
319299
bp::class_<RF24>("RF24", bp::init<uint16_t, uint16_t>((bp::arg("_cepin"), bp::arg("_cspin"))))
320300
#if defined(RF24_LINUX) && !defined(MRAA)

0 commit comments

Comments
 (0)