Commit 1cc7454d authored by TMRh20's avatar TMRh20

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
parent 4340d933
...@@ -564,18 +564,30 @@ void RF24::startWrite( const void* buf, uint8_t len ) ...@@ -564,18 +564,30 @@ void RF24::startWrite( const void* buf, uint8_t len )
ce(LOW); ce(LOW);
} }
bool RF24::txStandBy(){ bool RF24::txStandBy(){
txStandBy(0);
}
if ( (read_register(FIFO_STATUS) & _BV(TX_EMPTY))){ bool RF24::txStandBy(bool block){
ce(LOW);
return 1; while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
} if( get_status() & _BV(MAX_RT)){
if( get_status() & _BV(MAX_RT)){ write_register(STATUS,_BV(MAX_RT) );
write_register(STATUS,_BV(MAX_RT) ); if(block){
return 0; ce(LOW); //Set re-transmit
ce(HIGH);
delayMicroseconds(15);
}else{
flush_tx(); //Non blocking, flush the data
ce(LOW); //Set STANDBY-I mode
return 0;
}
}
} }
return 0; ce(LOW); //Set STANDBY-I mode
return 1;
} }
/****************************************************************************/ /****************************************************************************/
......
...@@ -382,32 +382,18 @@ public: ...@@ -382,32 +382,18 @@ public:
* radio.writeFast(&buf,32); * radio.writeFast(&buf,32);
* radio.writeFast(&buf,32); * radio.writeFast(&buf,32);
* radio.writeFast(&buf,32); //Fills the FIFO buffers up * radio.writeFast(&buf,32); //Fills the FIFO buffers up
* while( !txStandBy() ){} //Waits for TX complete or timeout * bool ok = txStandBy(0); //Returns 0 if failed. 1 if success.
* //Blocks only until timeout or success. Data flushed on fail.
*
* Using txStandBy(1) will not return until the data is transmitted. It will never return 0.
* *
* @endcode * @endcode
* *
* @return True if transmission is finished and the radio has been commanded * @return True if transmission is successful
* to enter STANDBY-I operating mode.
* *
*/ */
bool txStandBy(); bool txStandBy();
bool txStandBy(bool block);
/**
* Optimization: New Command
*
* This function is mainly used internally to take advantage of the auto payload
* re-use functionality of the chip, but can be beneficial to users as well.
*
* The function will instruct the radio to re-use the data in the FIFO buffers,
* and instructs the radio to re-send once the timeout limit has been reached.
* Used by writeFast and writeBlocking to initiate retries when a TX failure
* occurs. Retries are automatically initiated except with the standard write().
* This way, data is not flushed from the buffer until switching between modes.
*
* @note This is to be used AFTER auto-retry fails if wanting to resend
* using the built-in payload reuse features.
*/
void reUseTX();
/** /**
* Test whether there are bytes available to be read * Test whether there are bytes available to be read
...@@ -689,19 +675,6 @@ public: ...@@ -689,19 +675,6 @@ public:
*/ */
void powerUp(void) ; void powerUp(void) ;
/**
* Test whether there are bytes available to be read in the
* FIFO buffers. This optimized version does not rely on interrupt
* flags, but checks the actual FIFO buffers.
*
* @note Optimization: Interrupt flags are no longer cleared when available is called,
* but will be reset only when the data is read from the FIFO buffers.
*
* @param[out] pipe_num Which pipe has the payload available
* @return True if there is a payload available, false if none is
*/
bool available(uint8_t* pipe_num);
/** /**
* Non-blocking write to the open writing pipe * Non-blocking write to the open writing pipe
* *
...@@ -721,6 +694,23 @@ public: ...@@ -721,6 +694,23 @@ public:
*/ */
void startWrite( const void* buf, uint8_t len ); void startWrite( const void* buf, uint8_t len );
/**
* Optimization: New Command
*
* This function is mainly used internally to take advantage of the auto payload
* re-use functionality of the chip, but can be beneficial to users as well.
*
* The function will instruct the radio to re-use the data in the FIFO buffers,
* and instructs the radio to re-send once the timeout limit has been reached.
* Used by writeFast and writeBlocking to initiate retries when a TX failure
* occurs. Retries are automatically initiated except with the standard write().
* This way, data is not flushed from the buffer until switching between modes.
*
* @note This is to be used AFTER auto-retry fails if wanting to resend
* using the built-in payload reuse features.
*/
void reUseTX();
/** /**
* Write an ack payload for the specified pipe * Write an ack payload for the specified pipe
* *
...@@ -751,6 +741,19 @@ public: ...@@ -751,6 +741,19 @@ public:
*/ */
bool isAckPayloadAvailable(void); bool isAckPayloadAvailable(void);
/**
* Test whether there are bytes available to be read in the
* FIFO buffers. This optimized version does not rely on interrupt
* flags, but checks the actual FIFO buffers.
*
* @note Optimization: Interrupt flags are no longer cleared when available is called,
* but will be reset only when the data is read from the FIFO buffers.
*
* @param[out] pipe_num Which pipe has the payload available
* @return True if there is a payload available, false if none is
*/
bool available(uint8_t* pipe_num);
/** /**
* Call this when you get an interrupt to find out why * Call this when you get an interrupt to find out why
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment