From 77cf9ec5a45c38b237d5a521e795b702cb06620d Mon Sep 17 00:00:00 2001 From: FesterBesterTester Date: Sun, 25 May 2014 01:02:19 -0400 Subject: [PATCH] RF24::available() should report, but not change, data availability. --- RF24.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 9471583d..e8fe43a4 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -549,26 +549,13 @@ bool RF24::available(uint8_t* pipe_num) // Too noisy, enable if you really want lots o data!! //IF_SERIAL_DEBUG(print_status(status)); - bool result = ( status & _BV(RX_DR) ); + bool result = !(read_register(FIFO_STATUS) & _BV(RX_EMPTY)); if (result) { // If the caller wants the pipe number, include that if ( pipe_num ) *pipe_num = ( status >> RX_P_NO ) & B111; - - // Clear the status bit - - // ??? Should this REALLY be cleared now? Or wait until we - // actually READ the payload? - - write_register(STATUS,_BV(RX_DR) ); - - // Handle ack payload receipt - if ( status & _BV(TX_DS) ) - { - write_register(STATUS,_BV(TX_DS)); - } } return result; @@ -578,9 +565,21 @@ bool RF24::available(uint8_t* pipe_num) bool RF24::read( void* buf, uint8_t len ) { + uint8_t status = get_status(); + // Fetch the payload read_payload( buf, len ); + // Clear the status bit + + write_register(STATUS,_BV(RX_DR)); + + // Handle ack payload receipt + if ( status & _BV(TX_DS) ) + { + write_register(STATUS,_BV(TX_DS)); + } + // was this the last of the data available? return read_register(FIFO_STATUS) & _BV(RX_EMPTY); }