Skip to content

Commit 1cc7454

Browse files
committed
txStandby() function modified completely
txStandBy() now either works in two modes. The main mode will block until success or fail. Using txStandBy(1) will block and retry forever until succesful. Using a while loop with the function is no longer required. See the updated class reference at http://tmrh20.github.io/RF24/class_r_f24.html
1 parent 4340d93 commit 1cc7454

File tree

2 files changed

+57
-42
lines changed

2 files changed

+57
-42
lines changed

RF24.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -564,18 +564,30 @@ void RF24::startWrite( const void* buf, uint8_t len )
564564
ce(LOW);
565565
}
566566

567-
568567
bool RF24::txStandBy(){
568+
txStandBy(0);
569+
}
569570

570-
if ( (read_register(FIFO_STATUS) & _BV(TX_EMPTY))){
571-
ce(LOW);
572-
return 1;
573-
}
574-
if( get_status() & _BV(MAX_RT)){
575-
write_register(STATUS,_BV(MAX_RT) );
576-
return 0;
571+
bool RF24::txStandBy(bool block){
572+
573+
while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
574+
if( get_status() & _BV(MAX_RT)){
575+
write_register(STATUS,_BV(MAX_RT) );
576+
if(block){
577+
ce(LOW); //Set re-transmit
578+
ce(HIGH);
579+
delayMicroseconds(15);
580+
581+
}else{
582+
flush_tx(); //Non blocking, flush the data
583+
ce(LOW); //Set STANDBY-I mode
584+
return 0;
585+
}
586+
}
577587
}
578-
return 0;
588+
ce(LOW); //Set STANDBY-I mode
589+
return 1;
590+
579591
}
580592

581593
/****************************************************************************/

RF24.h

+36-33
Original file line numberDiff line numberDiff line change
@@ -382,32 +382,18 @@ class RF24
382382
* radio.writeFast(&buf,32);
383383
* radio.writeFast(&buf,32);
384384
* radio.writeFast(&buf,32); //Fills the FIFO buffers up
385-
* while( !txStandBy() ){} //Waits for TX complete or timeout
385+
* bool ok = txStandBy(0); //Returns 0 if failed. 1 if success.
386+
* //Blocks only until timeout or success. Data flushed on fail.
387+
*
388+
* Using txStandBy(1) will not return until the data is transmitted. It will never return 0.
386389
*
387390
* @endcode
388391
*
389-
* @return True if transmission is finished and the radio has been commanded
390-
* to enter STANDBY-I operating mode.
392+
* @return True if transmission is successful
391393
*
392394
*/
393395
bool txStandBy();
394-
395-
/**
396-
* Optimization: New Command
397-
*
398-
* This function is mainly used internally to take advantage of the auto payload
399-
* re-use functionality of the chip, but can be beneficial to users as well.
400-
*
401-
* The function will instruct the radio to re-use the data in the FIFO buffers,
402-
* and instructs the radio to re-send once the timeout limit has been reached.
403-
* Used by writeFast and writeBlocking to initiate retries when a TX failure
404-
* occurs. Retries are automatically initiated except with the standard write().
405-
* This way, data is not flushed from the buffer until switching between modes.
406-
*
407-
* @note This is to be used AFTER auto-retry fails if wanting to resend
408-
* using the built-in payload reuse features.
409-
*/
410-
void reUseTX();
396+
bool txStandBy(bool block);
411397

412398
/**
413399
* Test whether there are bytes available to be read
@@ -689,19 +675,6 @@ class RF24
689675
*/
690676
void powerUp(void) ;
691677

692-
/**
693-
* Test whether there are bytes available to be read in the
694-
* FIFO buffers. This optimized version does not rely on interrupt
695-
* flags, but checks the actual FIFO buffers.
696-
*
697-
* @note Optimization: Interrupt flags are no longer cleared when available is called,
698-
* but will be reset only when the data is read from the FIFO buffers.
699-
*
700-
* @param[out] pipe_num Which pipe has the payload available
701-
* @return True if there is a payload available, false if none is
702-
*/
703-
bool available(uint8_t* pipe_num);
704-
705678
/**
706679
* Non-blocking write to the open writing pipe
707680
*
@@ -721,6 +694,23 @@ class RF24
721694
*/
722695
void startWrite( const void* buf, uint8_t len );
723696

697+
/**
698+
* Optimization: New Command
699+
*
700+
* This function is mainly used internally to take advantage of the auto payload
701+
* re-use functionality of the chip, but can be beneficial to users as well.
702+
*
703+
* The function will instruct the radio to re-use the data in the FIFO buffers,
704+
* and instructs the radio to re-send once the timeout limit has been reached.
705+
* Used by writeFast and writeBlocking to initiate retries when a TX failure
706+
* occurs. Retries are automatically initiated except with the standard write().
707+
* This way, data is not flushed from the buffer until switching between modes.
708+
*
709+
* @note This is to be used AFTER auto-retry fails if wanting to resend
710+
* using the built-in payload reuse features.
711+
*/
712+
void reUseTX();
713+
724714
/**
725715
* Write an ack payload for the specified pipe
726716
*
@@ -751,6 +741,19 @@ class RF24
751741
*/
752742
bool isAckPayloadAvailable(void);
753743

744+
/**
745+
* Test whether there are bytes available to be read in the
746+
* FIFO buffers. This optimized version does not rely on interrupt
747+
* flags, but checks the actual FIFO buffers.
748+
*
749+
* @note Optimization: Interrupt flags are no longer cleared when available is called,
750+
* but will be reset only when the data is read from the FIFO buffers.
751+
*
752+
* @param[out] pipe_num Which pipe has the payload available
753+
* @return True if there is a payload available, false if none is
754+
*/
755+
bool available(uint8_t* pipe_num);
756+
754757
/**
755758
* Call this when you get an interrupt to find out why
756759
*

0 commit comments

Comments
 (0)