From a11d59344c6be646a7307aa194416680c67103a1 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 26 Oct 2024 03:39:46 -0700 Subject: [PATCH] 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)`. --- RF24.cpp | 18 ++++++------------ RF24_config.h | 3 --- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index f0f7a087..c542e1bb 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1488,23 +1488,18 @@ uint8_t RF24::getDynamicPayloadSize(void) bool RF24::available(void) { - uint8_t pipe = RF24_NO_FETCH_PIPE; - return available(&pipe); + return (read_register(FIFO_STATUS) & 1) == 0; } /****************************************************************************/ bool RF24::available(uint8_t* pipe_num) { - if (read_register(FIFO_STATUS) & 1) { // if RX FIFO is empty - return 0; - } - - // If the caller wants the pipe number, include that - if (*pipe_num != RF24_NO_FETCH_PIPE) + if (available()) { // if RX FIFO is not empty *pipe_num = (get_status() >> RX_P_NO) & 0x07; - - return 1; + return 1; + } + return 0; } /****************************************************************************/ @@ -1756,8 +1751,7 @@ bool RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) bool RF24::isAckPayloadAvailable(void) { - uint8_t pipe = RF24_NO_FETCH_PIPE; - return available(&pipe); + return available(); } /****************************************************************************/ diff --git a/RF24_config.h b/RF24_config.h index 8fbc7fb2..156f71bd 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -44,9 +44,6 @@ #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.