This commit is contained in:
maniacbug 2011-07-10 08:26:49 -07:00
parent 42bf3e8cd2
commit 20e91ab82b
1 changed files with 45 additions and 44 deletions

View File

@ -24,7 +24,7 @@
#undef PSTR #undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) #define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
/******************************************************************/ /****************************************************************************/
void RF24::csn(int mode) void RF24::csn(int mode)
{ {
@ -33,14 +33,14 @@ void RF24::csn(int mode)
digitalWrite(csn_pin,mode); digitalWrite(csn_pin,mode);
} }
/******************************************************************/ /****************************************************************************/
void RF24::ce(int mode) void RF24::ce(int mode)
{ {
digitalWrite(ce_pin,mode); digitalWrite(ce_pin,mode);
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len) uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
{ {
@ -56,7 +56,7 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::read_register(uint8_t reg) uint8_t RF24::read_register(uint8_t reg)
{ {
@ -68,7 +68,7 @@ uint8_t RF24::read_register(uint8_t reg)
return result; return result;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len) uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
{ {
@ -84,7 +84,7 @@ uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::write_register(uint8_t reg, uint8_t value) uint8_t RF24::write_register(uint8_t reg, uint8_t value)
{ {
@ -100,7 +100,7 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::write_payload(const void* buf, uint8_t len) uint8_t RF24::write_payload(const void* buf, uint8_t len)
{ {
@ -127,7 +127,7 @@ uint8_t RF24::write_payload(const void* buf, uint8_t len)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::read_payload(void* buf, uint8_t len) uint8_t RF24::read_payload(void* buf, uint8_t len)
{ {
@ -154,7 +154,7 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::flush_rx(void) uint8_t RF24::flush_rx(void)
{ {
@ -167,7 +167,7 @@ uint8_t RF24::flush_rx(void)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::flush_tx(void) uint8_t RF24::flush_tx(void)
{ {
@ -180,7 +180,7 @@ uint8_t RF24::flush_tx(void)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::get_status(void) uint8_t RF24::get_status(void)
{ {
@ -193,7 +193,7 @@ uint8_t RF24::get_status(void)
return status; return status;
} }
/******************************************************************/ /****************************************************************************/
void RF24::print_status(uint8_t status) void RF24::print_status(uint8_t status)
{ {
@ -207,7 +207,7 @@ void RF24::print_status(uint8_t status)
); );
} }
/******************************************************************/ /****************************************************************************/
void RF24::print_observe_tx(uint8_t value) void RF24::print_observe_tx(uint8_t value)
{ {
@ -218,7 +218,7 @@ void RF24::print_observe_tx(uint8_t value)
); );
} }
/******************************************************************/ /****************************************************************************/
void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty) void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty)
{ {
@ -229,7 +229,7 @@ void RF24::print_byte_register(prog_char* name, uint8_t reg, uint8_t qty)
printf_P(PSTR("\n\r")); printf_P(PSTR("\n\r"));
} }
/******************************************************************/ /****************************************************************************/
void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty) void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
{ {
@ -250,35 +250,35 @@ void RF24::print_address_register(prog_char* name, uint8_t reg, uint8_t qty)
printf_P(PSTR("\n\r")); printf_P(PSTR("\n\r"));
} }
/******************************************************************/ /****************************************************************************/
RF24::RF24(uint8_t _cepin, uint8_t _cspin): RF24::RF24(uint8_t _cepin, uint8_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false) ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false)
{ {
} }
/******************************************************************/ /****************************************************************************/
void RF24::setChannel(uint8_t channel) void RF24::setChannel(uint8_t channel)
{ {
write_register(RF_CH,min(channel,127)); write_register(RF_CH,min(channel,127));
} }
/******************************************************************/ /****************************************************************************/
void RF24::setPayloadSize(uint8_t size) void RF24::setPayloadSize(uint8_t size)
{ {
payload_size = min(size,32); payload_size = min(size,32);
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::getPayloadSize(void) uint8_t RF24::getPayloadSize(void)
{ {
return payload_size; return payload_size;
} }
/******************************************************************/ /****************************************************************************/
void RF24::printDetails(void) void RF24::printDetails(void)
{ {
@ -296,7 +296,7 @@ void RF24::printDetails(void)
print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2); print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2);
} }
/******************************************************************/ /****************************************************************************/
void RF24::begin(void) void RF24::begin(void)
{ {
@ -328,7 +328,7 @@ void RF24::begin(void)
setChannel(1); setChannel(1);
} }
/******************************************************************/ /****************************************************************************/
void RF24::startListening(void) void RF24::startListening(void)
{ {
@ -348,21 +348,21 @@ void RF24::startListening(void)
delayMicroseconds(130); delayMicroseconds(130);
} }
/******************************************************************/ /****************************************************************************/
void RF24::stopListening(void) void RF24::stopListening(void)
{ {
ce(LOW); ce(LOW);
} }
/******************************************************************/ /****************************************************************************/
void RF24::powerDown(void) void RF24::powerDown(void)
{ {
write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP)); write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP));
} }
/******************************************************************/ /****************************************************************************/
bool RF24::write( const void* buf, uint8_t len ) bool RF24::write( const void* buf, uint8_t len )
{ {
@ -423,7 +423,7 @@ bool RF24::write( const void* buf, uint8_t len )
return result; return result;
} }
/******************************************************************/ /****************************************************************************/
void RF24::startWrite( const void* buf, uint8_t len ) void RF24::startWrite( const void* buf, uint8_t len )
{ {
@ -440,7 +440,7 @@ void RF24::startWrite( const void* buf, uint8_t len )
ce(LOW); ce(LOW);
} }
/******************************************************************/ /****************************************************************************/
uint8_t RF24::getDynamicPayloadSize(void) uint8_t RF24::getDynamicPayloadSize(void)
{ {
@ -454,20 +454,21 @@ uint8_t RF24::getDynamicPayloadSize(void)
return result; return result;
} }
/******************************************************************/ /****************************************************************************/
bool RF24::available(void) bool RF24::available(void)
{ {
return available(NULL); return available(NULL);
} }
/******************************************************************/ /****************************************************************************/
bool RF24::available(uint8_t* pipe_num) bool RF24::available(uint8_t* pipe_num)
{ {
uint8_t status = get_status(); uint8_t status = get_status();
// Too noisy, enable if you really want lots o data!! IF_SERIAL_DEBUG(print_status(status)); // Too noisy, enable if you really want lots o data!!
//IF_SERIAL_DEBUG(print_status(status));
bool result = ( status & _BV(RX_DR) ); bool result = ( status & _BV(RX_DR) );
@ -494,7 +495,7 @@ bool RF24::available(uint8_t* pipe_num)
return result; return result;
} }
/******************************************************************/ /****************************************************************************/
bool RF24::read( void* buf, uint8_t len ) bool RF24::read( void* buf, uint8_t len )
{ {
@ -505,7 +506,7 @@ bool RF24::read( void* buf, uint8_t len )
return read_register(FIFO_STATUS) & _BV(RX_EMPTY); return read_register(FIFO_STATUS) & _BV(RX_EMPTY);
} }
/******************************************************************/ /****************************************************************************/
void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready) void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
{ {
@ -518,7 +519,7 @@ void RF24::whatHappened(bool& tx_ok,bool& tx_fail,bool& rx_ready)
rx_ready = status & _BV(RX_DR); rx_ready = status & _BV(RX_DR);
} }
/******************************************************************/ /****************************************************************************/
void RF24::openWritingPipe(uint64_t value) void RF24::openWritingPipe(uint64_t value)
{ {
@ -530,7 +531,7 @@ void RF24::openWritingPipe(uint64_t value)
write_register(RX_PW_P0,min(payload_size,32)); write_register(RX_PW_P0,min(payload_size,32));
} }
/******************************************************************/ /****************************************************************************/
void RF24::openReadingPipe(uint8_t child, uint64_t value) void RF24::openReadingPipe(uint8_t child, uint64_t value)
{ {
@ -570,7 +571,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t value)
} }
} }
/******************************************************************/ /****************************************************************************/
void RF24::toggle_features(void) void RF24::toggle_features(void)
{ {
@ -580,7 +581,7 @@ void RF24::toggle_features(void)
csn(HIGH); csn(HIGH);
} }
/******************************************************************/ /****************************************************************************/
void RF24::enableDynamicPayloads(void) void RF24::enableDynamicPayloads(void)
{ {
@ -604,7 +605,7 @@ void RF24::enableDynamicPayloads(void)
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P5) | _BV(DPL_P4) | _BV(DPL_P3) | _BV(DPL_P2) | _BV(DPL_P1) | _BV(DPL_P0)); write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P5) | _BV(DPL_P4) | _BV(DPL_P3) | _BV(DPL_P2) | _BV(DPL_P1) | _BV(DPL_P0));
} }
/******************************************************************/ /****************************************************************************/
void RF24::enableAckPayload(void) void RF24::enableAckPayload(void)
{ {
@ -631,7 +632,7 @@ void RF24::enableAckPayload(void)
write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P1) | _BV(DPL_P0)); write_register(DYNPD,read_register(DYNPD) | _BV(DPL_P1) | _BV(DPL_P0));
} }
/******************************************************************/ /****************************************************************************/
void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
{ {
@ -646,7 +647,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
csn(HIGH); csn(HIGH);
} }
/******************************************************************/ /****************************************************************************/
bool RF24::isAckPayloadAvailable(void) bool RF24::isAckPayloadAvailable(void)
{ {
@ -655,7 +656,7 @@ bool RF24::isAckPayloadAvailable(void)
return result; return result;
} }
/******************************************************************/ /****************************************************************************/
void RF24::setAutoAck(bool enable) void RF24::setAutoAck(bool enable)
{ {
@ -665,14 +666,14 @@ void RF24::setAutoAck(bool enable)
write_register(EN_AA, 0); write_register(EN_AA, 0);
} }
/******************************************************************/ /****************************************************************************/
bool RF24::testCarrier(void) bool RF24::testCarrier(void)
{ {
return ( read_register(CD) & 1 ); return ( read_register(CD) & 1 );
} }
/******************************************************************/ /****************************************************************************/
void RF24::setDataRate(rf24_datarate_e speed) void RF24::setDataRate(rf24_datarate_e speed)
{ {
@ -683,7 +684,7 @@ void RF24::setDataRate(rf24_datarate_e speed)
} }
/******************************************************************/ /****************************************************************************/
void RF24::setCRCLength(rf24_crclength_e length) void RF24::setCRCLength(rf24_crclength_e length)
{ {
@ -693,7 +694,7 @@ void RF24::setCRCLength(rf24_crclength_e length)
write_register(CONFIG,config); write_register(CONFIG,config);
} }
/******************************************************************/ /****************************************************************************/
void RF24::setRetries(uint8_t delay, uint8_t count) void RF24::setRetries(uint8_t delay, uint8_t count)
{ {