Skip to content

Commit a11d593

Browse files
committed
fix: make available(pipe) depend on available(void)
I've been code golfing in rust again... By making `available(pipe)` call `available(void)`, we can get the same behavior without instantiating a dummy byte (`RF24_FETCH_NO_PIPE`) . This way `available(pipe)` also doesn't need to check the `pipe` parameter's value; it just mutates it because that is the overload's purpose. This should decrease the compile size for any app that doesn't actually call `available(pipe)`.
1 parent 8aa7103 commit a11d593

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

RF24.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,23 +1488,18 @@ uint8_t RF24::getDynamicPayloadSize(void)
14881488

14891489
bool RF24::available(void)
14901490
{
1491-
uint8_t pipe = RF24_NO_FETCH_PIPE;
1492-
return available(&pipe);
1491+
return (read_register(FIFO_STATUS) & 1) == 0;
14931492
}
14941493

14951494
/****************************************************************************/
14961495

14971496
bool RF24::available(uint8_t* pipe_num)
14981497
{
1499-
if (read_register(FIFO_STATUS) & 1) { // if RX FIFO is empty
1500-
return 0;
1501-
}
1502-
1503-
// If the caller wants the pipe number, include that
1504-
if (*pipe_num != RF24_NO_FETCH_PIPE)
1498+
if (available()) { // if RX FIFO is not empty
15051499
*pipe_num = (get_status() >> RX_P_NO) & 0x07;
1506-
1507-
return 1;
1500+
return 1;
1501+
}
1502+
return 0;
15081503
}
15091504

15101505
/****************************************************************************/
@@ -1756,8 +1751,7 @@ bool RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
17561751

17571752
bool RF24::isAckPayloadAvailable(void)
17581753
{
1759-
uint8_t pipe = RF24_NO_FETCH_PIPE;
1760-
return available(&pipe);
1754+
return available();
17611755
}
17621756

17631757
/****************************************************************************/

RF24_config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#define RF24_SPI_SPEED 10000000
4545
#endif
4646

47-
/// A sentinel used to control fetching the pipe info in `RF24::available()`.
48-
#define RF24_NO_FETCH_PIPE 0XFF
49-
5047
//ATXMega
5148
#if defined(__AVR_ATxmega64D3__) || defined(__AVR_ATxmega128D3__) || defined(__AVR_ATxmega192D3__) || defined(__AVR_ATxmega256D3__) || defined(__AVR_ATxmega384D3__)
5249
// In order to be available both in Windows and Linux this should take presence here.

0 commit comments

Comments
 (0)