Created a non-blocking write and an example for how to use it.

This commit is contained in:
maniacbug
2011-07-06 20:49:59 -07:00
parent bb37e88094
commit d3fff68a7c
3 changed files with 102 additions and 31 deletions

View File

@@ -356,17 +356,8 @@ boolean RF24::write( const void* buf, uint8_t len )
{
boolean result = false;
// Transmitter power-up
write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );
delay(2);
// Send the payload
write_payload( buf, len );
// Allons!
ce(HIGH);
delayMicroseconds(15);
ce(LOW);
// Begin the write
startWrite(buf,len);
// ------------
// At this point we could return from a non-blocking write, and then call
@@ -379,7 +370,7 @@ boolean RF24::write( const void* buf, uint8_t len )
uint8_t observe_tx;
uint8_t status;
uint32_t sent_at = millis();
const uint32_t timeout = 100; //ms to wait for timeout
const uint32_t timeout = 500; //ms to wait for timeout
do
{
status = read_register(OBSERVE_TX,&observe_tx,1);
@@ -420,6 +411,22 @@ boolean RF24::write( const void* buf, uint8_t len )
return result;
}
/******************************************************************/
void RF24::startWrite( const void* buf, uint8_t len )
{
// Transmitter power-up
write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );
delay(2);
// Send the payload
write_payload( buf, len );
// Allons!
ce(HIGH);
delayMicroseconds(15);
ce(LOW);
}
/******************************************************************/
@@ -507,6 +514,8 @@ void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
tx_ok = status & _BV(TX_DS);
tx_fail = status & _BV(MAX_RT);
rx_ready = status & _BV(RX_DR);
//print_status(status);
}
/******************************************************************/