Got ack payloads working. Renamed from 'ackpacket'

This commit is contained in:
maniacbug 2011-05-10 14:39:01 -07:00
parent 39b15c8b55
commit ffc7d099ed
2 changed files with 36 additions and 14 deletions

View File

@ -202,7 +202,7 @@ void RF24::print_observe_tx(uint8_t value)
/******************************************************************/
RF24::RF24(uint8_t _cepin, uint8_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_packet_available(false)
ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false)
{
}
@ -371,17 +371,13 @@ boolean RF24::write( const void* buf, uint8_t len )
IF_SERIAL_DEBUG(Serial.print(result?"...OK.":"...Failed"));
ack_packet_available = ( status & _BV(RX_DR) );
uint8_t pl_len = 0;
if ( ack_packet_available )
ack_payload_available = ( status & _BV(RX_DR) );
if ( ack_payload_available )
{
write_register(STATUS,_BV(RX_DR) );
csn(LOW);
SPI.transfer( R_RX_PL_WID );
pl_len = SPI.transfer(0xff);
csn(HIGH);
ack_payload_length = read_payload_length();
IF_SERIAL_DEBUG(Serial.print("[AckPacket]/"));
IF_SERIAL_DEBUG(Serial.println(pl_len,DEC));
IF_SERIAL_DEBUG(Serial.println(ack_payload_length,DEC));
}
// Yay, we are done.
@ -398,6 +394,21 @@ boolean RF24::write( const void* buf, uint8_t len )
return result;
}
/******************************************************************/
uint8_t RF24::read_payload_length(void)
{
uint8_t result = 0;
csn(LOW);
SPI.transfer( R_RX_PL_WID );
result = SPI.transfer(0xff);
csn(HIGH);
return result;
}
/******************************************************************/
boolean RF24::available(void)
@ -552,8 +563,8 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
boolean RF24::isAckPayloadAvailable(void)
{
boolean result = ack_packet_available;
ack_packet_available = false;
boolean result = ack_payload_available;
ack_payload_available = false;
return result;
}

17
RF24.h
View File

@ -21,7 +21,8 @@ private:
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */
uint8_t payload_size; /**< Fixed size of payloads */
boolean ack_packet_available; /**< Whether there is an ack packet waiting */
boolean ack_payload_available; /**< Whether there is an ack payload waiting */
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. Note: not used. */
protected:
/**
@ -98,7 +99,17 @@ protected:
* @return Current value of status register
*/
uint8_t read_payload(void* buf, uint8_t len) ;
public:
/**
* Read the payload length
*
* For dynamic payloads, this pulls the size of the payload off
* the chip
*
* @return Payload length of last-received dynamic payload
*/
uint8_t read_payload_length(void);
/**
* Empty the receive buffer
*
@ -112,7 +123,7 @@ public:
* @return Current value of status register
*/
uint8_t flush_tx(void);
protected:
/**
* Retrieve the current status of the chip
*