Merge master with static payload fixes

This commit is contained in:
maniacbug
2011-08-02 16:38:14 -07:00
10 changed files with 579 additions and 34 deletions

View File

@@ -109,20 +109,17 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len)
const uint8_t* current = reinterpret_cast<const uint8_t*>(buf);
uint8_t data_len = min(len,payload_size);
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
//printf("[Writing %u bytes %u blanks]",data_len,blank_len);
csn(LOW);
status = SPI.transfer( W_TX_PAYLOAD );
uint8_t data_len = min(len,payload_size);
while ( data_len-- )
SPI.transfer(*current++);
// This does not seem to be needed. Keeping it here in case
// removing it does cause problems for static payloads
//
// Send blanks out to the chip to finish off the payload
//uint8_t blank_len = payload_size - data_len;
//while ( blank_len-- )
// SPI.transfer(0);
while ( blank_len-- )
SPI.transfer(0);
csn(HIGH);
return status;
@@ -135,21 +132,17 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
uint8_t status;
uint8_t* current = reinterpret_cast<uint8_t*>(buf);
uint8_t data_len = min(len,payload_size);
uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
//printf("[Reading %u bytes %u blanks]",data_len,blank_len);
csn(LOW);
status = SPI.transfer( R_RX_PAYLOAD );
uint8_t data_len = min(len,payload_size);
while ( data_len-- )
*current++ = SPI.transfer(0xff);
// This does not seem to be needed. Keeping it here in case
// removing it does cause problems for static payloads
//
// Read the remaining payload off the chip, even though we will
// throw it away.
//uint8_t blank_len = payload_size - data_len;
//while ( blank_len-- )
// SPI.transfer(0xff);
while ( blank_len-- )
SPI.transfer(0xff);
csn(HIGH);
return status;
@@ -254,8 +247,8 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
/****************************************************************************/
RF24::RF24(uint8_t _cepin, uint8_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false),
payload_size(32), ack_payload_available(false)
ce_pin(_cepin), csn_pin(_cspin), wide_band(true), p_variant(false), payload_size(32),
ack_payload_available(false), dynamic_payloads_enabled(false)
{
}
@@ -363,6 +356,9 @@ void RF24::begin(void)
// Initialize CRC and request 2-byte (16bit) CRC
setCRCLength( RF24_CRC_16 ) ;
// Disable dynamic payloads, to match dynamic_payloads_enabled setting
write_register(DYNPD,0);
// Reset current status
// Notice reset and flush is the last thing we do
@@ -664,6 +660,8 @@ void RF24::enableDynamicPayloads(void)
// Not sure the use case of only having dynamic payload on certain
// pipes, so the library does not support it.
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P5) | _BV(DPL_P4) | _BV(DPL_P3) | _BV(DPL_P2) | _BV(DPL_P1) | _BV(DPL_P0));
dynamic_payloads_enabled = true;
}
/****************************************************************************/