Factored out status-checking from write() into a public method
This commit is contained in:
parent
c62224ff86
commit
fbae441249
34
RF24.cpp
34
RF24.cpp
|
@ -391,28 +391,20 @@ boolean RF24::write( const void* buf, uint8_t len )
|
|||
// and then call this when you got an interrupt
|
||||
// ------------
|
||||
|
||||
// Read the status
|
||||
status = get_status();
|
||||
|
||||
// Reset the status
|
||||
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||
|
||||
// Call this when you get an interrupt
|
||||
// The status tells us three things
|
||||
// * The send was successful (TX_DS)
|
||||
// * The send failed, too many retries (MAX_RT)
|
||||
// * There is an ack packet waiting (RX_DR)
|
||||
bool tx_ok, tx_fail, ack_payload_available;
|
||||
whatHappened(tx_ok,tx_fail,ack_payload_available);
|
||||
|
||||
// What was the result of the send?
|
||||
if ( status & _BV(TX_DS) )
|
||||
result = true;
|
||||
|
||||
IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed"); if ( status & _BV(MAX_RT) ) Serial.print(" too many retries"));
|
||||
result = tx_ok;
|
||||
IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed"));
|
||||
|
||||
// Handle the ack packet
|
||||
ack_payload_available = ( status & _BV(RX_DR) );
|
||||
if ( ack_payload_available )
|
||||
{
|
||||
write_register(STATUS,_BV(RX_DR) );
|
||||
ack_payload_length = read_payload_length();
|
||||
IF_SERIAL_DEBUG(Serial.print("[AckPacket]/"));
|
||||
IF_SERIAL_DEBUG(Serial.println(ack_payload_length,DEC));
|
||||
|
@ -503,6 +495,22 @@ boolean RF24::read( void* buf, uint8_t len )
|
|||
|
||||
/******************************************************************/
|
||||
|
||||
void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
|
||||
{
|
||||
// Read the status
|
||||
uint8_t status = get_status();
|
||||
|
||||
// Reset the status
|
||||
write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||
|
||||
// Report to the user what happened
|
||||
tx_ok = status & _BV(TX_DS);
|
||||
tx_fail = status & _BV(MAX_RT);
|
||||
rx_ready = status & _BV(RX_DR);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
void RF24::openWritingPipe(uint64_t value)
|
||||
{
|
||||
// Note that AVR 8-bit uC's store this LSB first, and the NRF24L01
|
||||
|
|
12
RF24.h
12
RF24.h
|
@ -444,6 +444,18 @@ public:
|
|||
*/
|
||||
boolean isAckPayloadAvailable(void);
|
||||
|
||||
/**
|
||||
* Call this when you get an interrupt to find out why
|
||||
*
|
||||
* Tells you what caused the interrupt, and clears the state of
|
||||
* interrupts.
|
||||
*
|
||||
* @param[out] tx_ok The send was successful (TX_DS)
|
||||
* @param[out] tx_fail The send failed, too many retries (MAX_RT)
|
||||
* @param[out] rx_ready There is a message waiting to be read (RX_DS)
|
||||
*/
|
||||
void whatHappened(bool& tx_ok,bool& tx_fail,bool& rx);
|
||||
|
||||
/**
|
||||
* Enable or disable auto-acknowlede packets
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue