From 6db47d6ed4fe6af8ef2cf28fc2290f21fd0b821b Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Mon, 14 Aug 2023 03:06:12 -0700 Subject: [PATCH] fix #913 Essentially, this reverts the algorithm used to satisfy #650 as it has proved erroneous on fast MCUs. --- RF24.cpp | 17 ++++++++--------- RF24_config.h | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index c0cc7326..4d92aeba 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1521,7 +1521,7 @@ uint8_t RF24::getDynamicPayloadSize(void) bool RF24::available(void) { - uint8_t pipe = 0; + uint8_t pipe = RF24_NO_FETCH_PIPE; return available(&pipe); } @@ -1529,16 +1529,15 @@ bool RF24::available(void) bool RF24::available(uint8_t* pipe_num) { - // get implied RX FIFO empty flag from status byte - uint8_t pipe = (get_status() >> RX_P_NO) & 0x07; - if (pipe > 5) - return 0; + if (!isFifo(false, true)) { // if RX FIFO is not empty + // If the caller wants the pipe number, include that + if (*pipe_num != RF24_NO_FETCH_PIPE) + *pipe_num = (get_status() >> RX_P_NO) & 0x07; - // If the caller wants the pipe number, include that - if (pipe_num) - *pipe_num = pipe; + return 1; + } - return 1; + return 0; } /****************************************************************************/ diff --git a/RF24_config.h b/RF24_config.h index 49b02407..2c836cab 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -44,6 +44,9 @@ #define RF24_SPI_SPEED 10000000 #endif +/// A sentinel used to control fetching the pipe info in `RF24::available()`. +#define RF24_NO_FETCH_PIPE 0XFF + //ATXMega #if defined(__AVR_ATxmega64D3__) || defined(__AVR_ATxmega128D3__) || defined(__AVR_ATxmega192D3__) || defined(__AVR_ATxmega256D3__) || defined(__AVR_ATxmega384D3__) // In order to be available both in Windows and Linux this should take presence here.