Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made RF24::available() report whether there are bytes available to be read #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down