Skip to content

Commit

Permalink
Added an indication of which pipe a message came from. Fixed a bug wh…
Browse files Browse the repository at this point in the history
…ere pipes 2+ were not

getting enabled.
  • Loading branch information
maniacbug committed Apr 2, 2011
1 parent 37d8e8b commit c8ed556
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
43 changes: 36 additions & 7 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ void RF24::printDetails(void)
printf("%02x",*bufptr);
printf("\n\r");

status = read_register(RX_ADDR_P2,buffer,1);
printf("RX_ADDR_P2 = 0x%02x",*buffer);
printf("\n\r");

status = read_register(RX_ADDR_P3,buffer,1);
printf("RX_ADDR_P3 = 0x%02x",*buffer);
printf("\n\r");

status = read_register(TX_ADDR,buffer,5);
printf("TX_ADDR = 0x",buffer);
bufptr = buffer + 5;
Expand Down Expand Up @@ -350,10 +358,16 @@ boolean RF24::write( const void* buf, uint8_t len )

return result;
}

/******************************************************************/

boolean RF24::available(void)
{
return available(NULL);
}

/******************************************************************/

boolean RF24::available(uint8_t* pipe_num)
{
uint8_t status = get_status();
boolean result = ( status & _BV(RX_DR) );
Expand All @@ -362,7 +376,15 @@ boolean RF24::available(void)
{
IF_SERIAL_DEBUG(print_status(status));

// If the caller wants the pipe number, include that
if ( pipe_num )
*pipe_num = ( status >> RX_P_NO ) & B111;

// Clear the status bit

// ??? Should this REALLY be cleared now? Or wait until we
// actually READ the payload?

write_register(STATUS,_BV(RX_DR) );
}

Expand Down Expand Up @@ -408,18 +430,25 @@ void RF24::openReadingPipe(uint8_t child, uint64_t value)
const uint8_t child_payload_size[] = {
RX_PW_P1, RX_PW_P2, RX_PW_P3, RX_PW_P4, RX_PW_P5 };
const uint8_t child_pipe_enable[] = {
ENAA_P1, ENAA_P2, ENAA_P3, ENAA_P4, ENAA_P5 };
ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5 };

if (--child < 5)
{
write_register(child_pipe[child], reinterpret_cast<uint8_t*>(&value), 5);
// For pipes 2-5, only write the LSB
if ( !child )
write_register(child_pipe[child], reinterpret_cast<uint8_t*>(&value), 5);
else
write_register(child_pipe[child], reinterpret_cast<uint8_t*>(&value), 1);

write_register(child_payload_size[child],payload_size);

// Note this is kind of an inefficient way to set up these enable bits, bit I thought it made
// the calling code more simple
uint8_t en_aa;
read_register(EN_AA,&en_aa,1);
en_aa |= _BV(child_pipe_enable[child]);
write_register(EN_AA,en_aa);
uint8_t en_rx;
read_register(EN_RXADDR,&en_rx,1);
en_rx |= _BV(child_pipe_enable[child]);
write_register(EN_RXADDR,en_rx);
}
}
// vim:ai sts=2 sw=2 ft=cpp

11 changes: 9 additions & 2 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,21 @@ class RF24
*/
boolean available(void) ;

/**
* Test whether there are bytes available to be read
*
* @param[out] pipe_num Which pipe has the payload available
* @return True if there is a payload available, false if none is
*/
boolean available(uint8_t* pipe_num);

/**
* Read the payload
*
* Return the last payload received
*
* The size of data read is the fixed payload size, see getPayloadSize()
*
* @todo Indicate which pipe it came from
*
* @note I specifically chose 'void*' as a data type to make it easier
* for beginners to use. No casting needed.
*
Expand Down Expand Up @@ -323,4 +329,5 @@ class RF24
*/

#endif // __RF24_H__
// vim:ai sts=2 sw=2 ft=cpp

0 comments on commit c8ed556

Please sign in to comment.