As a just in case I misunderstood some of the constant-ness changes, I

completely took out all of the constant correctness enahcements. Also
added a powerUp() method.
This commit is contained in:
Greg Copeland 2011-07-19 11:05:18 -05:00
parent 542c46c0c6
commit 0c2515df19
2 changed files with 76 additions and 62 deletions

View File

@ -26,7 +26,7 @@
/******************************************************************/
void RF24::csn(int mode) const
void RF24::csn(int mode)
{
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
@ -36,14 +36,14 @@ void RF24::csn(int mode) const
/******************************************************************/
void RF24::ce(int level) const
void RF24::ce(int level)
{
digitalWrite(ce_pin,level);
}
/******************************************************************/
uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len) const
uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
{
uint8_t status;
@ -59,7 +59,7 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len) const
/******************************************************************/
uint8_t RF24::read_register(uint8_t reg) const
uint8_t RF24::read_register(uint8_t reg)
{
csn(LOW);
SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
@ -71,7 +71,7 @@ uint8_t RF24::read_register(uint8_t reg) const
/******************************************************************/
uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len) const
uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
{
uint8_t status;
@ -87,7 +87,7 @@ uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len) const
/******************************************************************/
uint8_t RF24::write_register(uint8_t reg, uint8_t value) const
uint8_t RF24::write_register(uint8_t reg, uint8_t value)
{
uint8_t status;
@ -145,7 +145,7 @@ uint8_t RF24::read_payload(void* buf, uint8_t len)
/******************************************************************/
uint8_t RF24::flush_rx(void) const
uint8_t RF24::flush_rx(void)
{
uint8_t status;
@ -158,7 +158,7 @@ uint8_t RF24::flush_rx(void) const
/******************************************************************/
uint8_t RF24::flush_tx(void) const
uint8_t RF24::flush_tx(void)
{
uint8_t status;
@ -171,7 +171,7 @@ uint8_t RF24::flush_tx(void) const
/******************************************************************/
uint8_t RF24::get_status(void) const
uint8_t RF24::get_status(void)
{
uint8_t status;
@ -184,7 +184,7 @@ uint8_t RF24::get_status(void) const
/******************************************************************/
void RF24::print_status(uint8_t status) const
void RF24::print_status(uint8_t status)
{
printf_P(PSTR("STATUS=%02x: RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\n\r"),
status,
@ -198,7 +198,7 @@ void RF24::print_status(uint8_t status) const
/******************************************************************/
void RF24::print_observe_tx(uint8_t value) const
void RF24::print_observe_tx(uint8_t value)
{
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\n\r"),
value,
@ -242,7 +242,7 @@ uint8_t RF24::getPayloadSize(void)
/******************************************************************/
void RF24::printDetails(void) const
void RF24::printDetails(void)
{
uint8_t buffer[5];
uint8_t status = read_register(RX_ADDR_P0,buffer,5);
@ -371,7 +371,7 @@ void RF24::begin(void)
/******************************************************************/
void RF24::startListening(void) const
void RF24::startListening(void)
{
write_register(CONFIG, read_register(CONFIG) | _BV(PWR_UP) | _BV(PRIM_RX));
write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
@ -391,20 +391,27 @@ void RF24::startListening(void) const
/******************************************************************/
void RF24::stopListening(void) const
void RF24::stopListening(void)
{
ce(LOW);
}
/******************************************************************/
void RF24::powerDown(void) const
void RF24::powerDown(void)
{
write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP));
}
/******************************************************************/
void RF24::powerUp(void)
{
write_register(CONFIG,read_register(CONFIG) | _BV(PWR_UP));
}
/******************************************************************/
boolean RF24::write( const void* buf, uint8_t len )
{
boolean result = false;
@ -483,14 +490,14 @@ uint8_t RF24::read_payload_length(void)
/******************************************************************/
boolean RF24::available(void) const
boolean RF24::available(void)
{
return available(NULL);
}
/******************************************************************/
boolean RF24::available(uint8_t* pipe_num) const
boolean RF24::available(uint8_t* pipe_num)
{
uint8_t status = get_status();
IF_SERIAL_DEBUG(print_status(status));
@ -587,7 +594,7 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address)
/******************************************************************/
void RF24::toggle_features(void) const
void RF24::toggle_features(void)
{
csn(LOW);
SPI.transfer( ACTIVATE );
@ -597,7 +604,7 @@ void RF24::toggle_features(void) const
/******************************************************************/
void RF24::enableAckPayload(void) const
void RF24::enableAckPayload(void)
{
//
// enable ack payload and dynamic payload features
@ -624,7 +631,7 @@ void RF24::enableAckPayload(void) const
/******************************************************************/
void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) const
void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
{
const uint8_t* current = (const uint8_t*)buf;
@ -648,13 +655,13 @@ boolean RF24::isAckPayloadAvailable(void)
/******************************************************************/
boolean RF24::isPVariant(void) const {
boolean RF24::isPVariant(void) {
return p_variant ;
}
/******************************************************************/
void RF24::setAutoAck(bool enable) const
void RF24::setAutoAck(bool enable)
{
if ( enable )
write_register(EN_AA, B111111);
@ -664,7 +671,7 @@ void RF24::setAutoAck(bool enable) const
/******************************************************************/
void RF24::setAutoAck( uint8_t pipe, bool enable ) const
void RF24::setAutoAck( uint8_t pipe, bool enable )
{
uint8_t en_aa = read_register( EN_AA ) ;
if( enable ) {
@ -677,21 +684,21 @@ void RF24::setAutoAck( uint8_t pipe, bool enable ) const
/******************************************************************/
boolean RF24::testCarrier(void) const
boolean RF24::testCarrier(void)
{
return ( read_register(CD) & 1 );
}
/******************************************************************/
boolean RF24::testRPD(void) const
boolean RF24::testRPD(void)
{
return ( read_register(RPD) & 1 ) ;
}
/******************************************************************/
void RF24::setPALevel(rf24_pa_dbm_e level) const
void RF24::setPALevel(rf24_pa_dbm_e level)
{
uint8_t setup = read_register(RF_SETUP) ;
setup &= ~(_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
@ -724,7 +731,7 @@ void RF24::setPALevel(rf24_pa_dbm_e level) const
/******************************************************************/
rf24_pa_dbm_e RF24::getPALevel(void) const
rf24_pa_dbm_e RF24::getPALevel(void)
{
rf24_pa_dbm_e result = RF24_PA_ERROR ;
uint8_t power = read_register(RF_SETUP) & (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;
@ -794,7 +801,7 @@ boolean RF24::setDataRate(rf24_datarate_e speed)
/******************************************************************/
rf24_datarate_e RF24::getDataRate( void ) const {
rf24_datarate_e RF24::getDataRate( void ) {
rf24_datarate_e result ;
uint8_t setup = read_register(RF_SETUP) ;
@ -821,7 +828,7 @@ rf24_datarate_e RF24::getDataRate( void ) const {
/******************************************************************/
void RF24::setCRCLength(rf24_crclength_e length) const
void RF24::setCRCLength(rf24_crclength_e length)
{
uint8_t config = read_register(CONFIG) & ~_BV(CRCO) ;
@ -839,7 +846,7 @@ void RF24::setCRCLength(rf24_crclength_e length) const
/******************************************************************/
void RF24::disableCRC( void ) const
void RF24::disableCRC( void )
{
uint8_t disable = read_register(CONFIG) & ~_BV(EN_CRC) ;
write_register( CONFIG, disable ) ;

71
RF24.h
View File

@ -50,7 +50,7 @@ protected:
*
* @param mode HIGH to take this unit off the SPI bus, LOW to put it on
*/
void csn(int mode) const ;
void csn(int mode) ;
/**
* Set chip enable
@ -58,7 +58,7 @@ protected:
* @param level HIGH to actively begin transmission or LOW to put in standby. Please see data sheet
* for a much more detailed description of this pin.
*/
void ce(int level) const ;
void ce(int level) ;
/**
* Read a chunk of data in from a register
@ -68,7 +68,7 @@ protected:
* @param len How many bytes of data to transfer
* @return Current value of status register
*/
uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len) const ;
uint8_t read_register(uint8_t reg, uint8_t* buf, uint8_t len) ;
/**
* Read single byte from a register
@ -76,7 +76,7 @@ protected:
* @param reg Which register. Use constants from nRF24L01.h
* @return Current value of register @p reg
*/
uint8_t read_register(uint8_t reg) const ;
uint8_t read_register(uint8_t reg) ;
/**
* Write a chunk of data to a register
@ -86,7 +86,7 @@ protected:
* @param len How many bytes of data to transfer
* @return Current value of status register
*/
uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len) const ;
uint8_t write_register(uint8_t reg, const uint8_t* buf, uint8_t len) ;
/**
* Write a single byte to a register
@ -95,7 +95,7 @@ protected:
* @param value The new value to write
* @return Current value of status register
*/
uint8_t write_register(uint8_t reg, uint8_t value) const ;
uint8_t write_register(uint8_t reg, uint8_t value) ;
/**
* Write the transmit payload
@ -134,21 +134,21 @@ protected:
*
* @return Current value of status register
*/
uint8_t flush_rx(void) const ;
uint8_t flush_rx(void) ;
/**
* Empty the transmit buffer
*
* @return Current value of status register
*/
uint8_t flush_tx(void) const ;
uint8_t flush_tx(void) ;
/**
* Retrieve the current status of the chip
*
* @return Current value of status register
*/
uint8_t get_status(void) const ;
uint8_t get_status(void) ;
/**
* Decode and print the given status to stdout
@ -157,7 +157,7 @@ protected:
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
*/
void print_status(uint8_t status) const ;
void print_status(uint8_t status) ;
/**
* Decode and print the given 'observe_tx' value to stdout
@ -166,7 +166,7 @@ protected:
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
*/
void print_observe_tx(uint8_t value) const ;
void print_observe_tx(uint8_t value) ;
/**
* Turn on or off the special features of the chip
@ -174,7 +174,7 @@ protected:
* The chip has certain 'features' which are only available when the 'features'
* are enabled. See the datasheet for details.
*/
void toggle_features(void) const ;
void toggle_features(void) ;
/**@}*/
public:
@ -211,14 +211,14 @@ public:
* in this mode, without first calling stopListening(). Call
* isAvailable() to check for incoming traffic, and read() to get it.
*/
void startListening(void) const ;
void startListening(void) ;
/**
* Stop listening for incoming messages
*
* Do this before calling write().
*/
void stopListening(void) const ;
void stopListening(void) ;
/**
* Write to the open writing pipe
@ -245,7 +245,7 @@ public:
*
* @return True if there is a payload available, false if none is
*/
boolean available(void) const ;
boolean available(void) ;
/**
* Read the payload
@ -351,15 +351,22 @@ public:
*
* @warning Does nothing if stdout is not defined. See fdevopen in stdio.h
*/
void printDetails(void) const ;
void printDetails(void) ;
/**
* Enter low-power mode
*
* To return to normal power mode, either write() some data or
* startListening().
* To return to normal power mode, either write() some data,
* startListening(), or powerUp().
*/
void powerDown(void) const ;
void powerDown(void) ;
/**
* Leave low-power mode - making radio more responsive
*
* To return to low power mode, call powerDown().
*/
void powerUp(void) ;
/**
* Test whether there are bytes available to be read
@ -370,7 +377,7 @@ public:
* @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) const ;
boolean available(uint8_t* pipe_num) ;
/**
* Enable custom payloads on the acknowledge packets
@ -380,7 +387,7 @@ public:
*
* @see examples/pingpair_pl/pingpair_pl.pde
*/
void enableAckPayload(void) const;
void enableAckPayload(void) ;
/**
* Write an ack payload for the specified pipe
@ -396,7 +403,7 @@ public:
* @param len Length of the data to send, up to 32 bytes max. Not affected
* by the static payload set by setPayloadSize().
*/
void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) const ;
void writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) ;
/**
* Determine if an ack payload was received in the most recent call to
@ -417,7 +424,7 @@ public:
* @return Returns true if the hardware is RF24L01P (or compatible) and false
* if its not.
*/
boolean isPVariant(void) const ;
boolean isPVariant(void) ;
/**
* Enable or disable auto-acknowlede packets
@ -427,7 +434,7 @@ public:
*
* @param enable Whether to enable (true) or disable (false) auto-acks
*/
void setAutoAck(bool enable) const ;
void setAutoAck(bool enable) ;
/**
* Enable or disable auto-acknowlede packets on a per pipeline basis.
@ -438,7 +445,7 @@ public:
* @param which pipeline to modify
* @param enable Whether to enable (true) or disable (false) auto-acks
*/
void setAutoAck( uint8_t pipe, bool enable ) const ;
void setAutoAck( uint8_t pipe, bool enable ) ;
/**
* Test whether there was a carrier on the line for the
@ -448,7 +455,7 @@ public:
*
* @return true if was carrier, false if not
*/
boolean testCarrier(void) const ;
boolean testCarrier(void) ;
/**
* Test whether a signal (carrier or otherwise) greater than
@ -460,7 +467,7 @@ public:
*
* @return true if signal => -64dBm, false if not
*/
boolean testRPD(void) const ;
boolean testRPD(void) ;
/**
* Set Power Amplifier (PA) level to one of four levels.
@ -471,7 +478,7 @@ public:
*
* @param Desired PA level.
*/
void setPALevel( rf24_pa_dbm_e level ) const ;
void setPALevel( rf24_pa_dbm_e level ) ;
/**
* Fetches the current PA level.
@ -481,7 +488,7 @@ public:
* by the enum mnemonics are negative dBm. See setPALevel for
* return value descriptions.
*/
rf24_pa_dbm_e getPALevel( void ) const ;
rf24_pa_dbm_e getPALevel( void ) ;
/**
* Set the transmission data rate
@ -497,20 +504,20 @@ public:
* is one of 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS, as defined in the
* rf24_datarate_e enum.
*/
rf24_datarate_e getDataRate( void ) const ;
rf24_datarate_e getDataRate( void ) ;
/**
* Set the CRC length
*
* @param length RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
*/
void setCRCLength(rf24_crclength_e length) const ;
void setCRCLength(rf24_crclength_e length) ;
/**
* Disable CRC validation
*
*/
void disableCRC( void ) const ;
void disableCRC( void ) ;
/**@}*/
};