Skip to content

Commit 01e6ccb

Browse files
authored
revert available() algorithm (#914)
* fix #913 Essentially, this reverts the algorithm used to satisfy #650 as it has proved erroneous on fast MCUs.
1 parent 890243c commit 01e6ccb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

RF24.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,22 +1521,21 @@ uint8_t RF24::getDynamicPayloadSize(void)
15211521

15221522
bool RF24::available(void)
15231523
{
1524-
uint8_t pipe = 0;
1524+
uint8_t pipe = RF24_NO_FETCH_PIPE;
15251525
return available(&pipe);
15261526
}
15271527

15281528
/****************************************************************************/
15291529

15301530
bool RF24::available(uint8_t* pipe_num)
15311531
{
1532-
// get implied RX FIFO empty flag from status byte
1533-
uint8_t pipe = (get_status() >> RX_P_NO) & 0x07;
1534-
if (pipe > 5)
1532+
if (read_register(FIFO_STATUS) & 1) { // if RX FIFO is empty
15351533
return 0;
1534+
}
15361535

15371536
// If the caller wants the pipe number, include that
1538-
if (pipe_num)
1539-
*pipe_num = pipe;
1537+
if (*pipe_num != RF24_NO_FETCH_PIPE)
1538+
*pipe_num = (get_status() >> RX_P_NO) & 0x07;
15401539

15411540
return 1;
15421541
}

RF24_config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
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+
4750
//ATXMega
4851
#if defined(__AVR_ATxmega64D3__) || defined(__AVR_ATxmega128D3__) || defined(__AVR_ATxmega192D3__) || defined(__AVR_ATxmega256D3__) || defined(__AVR_ATxmega384D3__)
4952
// In order to be available both in Windows and Linux this should take presence here.

0 commit comments

Comments
 (0)