Commit b62e179a authored by TMRh20's avatar TMRh20

Further tweaks per #9

- moved radio.flush_tx(); to public
- adjusted call_response example to use tx_flush();
- adjusted write_payload, read_payload
parent 5ec5b06b
...@@ -129,7 +129,8 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len, const uint8_t writeTyp ...@@ -129,7 +129,8 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len, const uint8_t writeTyp
while ( blank_len-- ) while ( blank_len-- )
*ptx++ = 0; *ptx++ = 0;
bcm2835_spi_transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
bcm2835_spi_transfernbd( (char *) spi_txbuff, (char *) spi_rxbuff, size);
status = *prx; // status is 1st byte of receive buffer status = *prx; // status is 1st byte of receive buffer
...@@ -163,8 +164,11 @@ uint8_t RF24::read_payload(void* buf, uint8_t len) ...@@ -163,8 +164,11 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
// Size has been lost during while, re affect // Size has been lost during while, re affect
size = data_len + blank_len + 1; // Add register value to transmit buffer size = data_len + blank_len + 1; // Add register value to transmit buffer
if(dynamic_payloads_enabled){
bcm2835_spi_transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
}else{
bcm2835_spi_transfernbd( (char *) spi_txbuff, (char *) spi_rxbuff, size); bcm2835_spi_transfernbd( (char *) spi_txbuff, (char *) spi_rxbuff, size);
}
// 1st byte is status // 1st byte is status
status = *prx++; status = *prx++;
......
...@@ -144,13 +144,6 @@ protected: ...@@ -144,13 +144,6 @@ protected:
*/ */
uint8_t flush_rx(void); uint8_t flush_rx(void);
/**
* Empty the transmit buffer
*
* @return Current value of status register
*/
uint8_t flush_tx(void);
/** /**
* Retrieve the current status of the chip * Retrieve the current status of the chip
* *
...@@ -346,6 +339,13 @@ public: ...@@ -346,6 +339,13 @@ public:
void openReadingPipe(uint8_t number, const uint8_t *address); void openReadingPipe(uint8_t number, const uint8_t *address);
/**
* Empty the transmit buffer
*
* @return Current value of status register
*/
uint8_t flush_tx(void);
/**@}*/ /**@}*/
/** /**
* @name Optional Configurators * @name Optional Configurators
......
...@@ -116,6 +116,7 @@ while (1){ ...@@ -116,6 +116,7 @@ while (1){
}else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed }else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed
sleep(1); // Try again later sleep(1); // Try again later
//delay(250);
} }
/****************** Pong Back Role ***************************/ /****************** Pong Back Role ***************************/
...@@ -123,11 +124,14 @@ while (1){ ...@@ -123,11 +124,14 @@ while (1){
if ( role == role_pong_back ) { if ( role == role_pong_back ) {
uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received
while( radio.available(&pipeNo)){ // Read all available payloads while( radio.available(&pipeNo)){ // Read all available payloads
radio.flush_tx(); // Clear any unused ACK payloads
radio.read( &gotByte, 1 ); radio.read( &gotByte, 1 );
// Since this is a call-response. Respond directly with an ack payload. // Since this is a call-response. Respond directly with an ack payload.
// Ack payloads are much more efficient than switching to transmit mode to respond to a call // Ack payloads are much more efficient than switching to transmit mode to respond to a call
radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads. radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads.
printf("Sent response %d \n\r", gotByte); printf("Sent response %d \n\r", gotByte);
} }
} }
......
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