Skip to content

Commit

Permalink
Now caches the reading pipe 0 and re-sets it when starting to listen.
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed May 15, 2011
1 parent e86c6b0 commit 1d28d28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ void RF24::startListening(void)
{
write_register(CONFIG, _BV(EN_CRC) | _BV(PWR_UP) | _BV(PRIM_RX));
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

// Restore the pipe0 adddress
write_register(RX_ADDR_P0, reinterpret_cast<uint8_t*>(&pipe0_reading_address), 5);

// Flush buffers
flush_rx();
Expand Down Expand Up @@ -495,6 +498,12 @@ void RF24::openReadingPipe(uint8_t child, uint64_t value)
const uint8_t child_pipe_enable[] = {
ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5 };

// If this is pipe 0, cache the address. This is needed because
// openWritingPipe() will overwrite the pipe 0 address, so
// startListening() will have to restore it.
if (child == 0)
pipe0_reading_address = value;

if (child < 5)
{
// For pipes 2-5, only write the LSB
Expand Down
1 change: 1 addition & 0 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class RF24
uint8_t payload_size; /**< Fixed size of payloads */
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. */
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */

protected:
/**
Expand Down

0 comments on commit 1d28d28

Please sign in to comment.