From aac2c3dba33b163521dc6a00bdb7d81761af1fbc Mon Sep 17 00:00:00 2001 From: Greg Copeland Date: Tue, 21 Jun 2011 14:58:19 -0500 Subject: [PATCH] Added two default values to the RF24 constructor; speed and channel. Some additional constantness cleanup. --- RF24.cpp | 11 +++++------ RF24.h | 11 ++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 155908a..c23b18b 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -208,14 +208,17 @@ void RF24::print_observe_tx(uint8_t value) const /******************************************************************/ -RF24::RF24(uint8_t _cepin, uint8_t _cspin): +RF24::RF24(const uint8_t _cepin, const uint8_t _cspin, + const rf24_datarate_e speed, const uint8_t channel): wide_band(true), ce_pin(_cepin), csn_pin(_cspin), payload_size(32), ack_payload_available(false) { + setDataRate( speed ) ; + setChannel( channel ) ; } /******************************************************************/ -void RF24::setChannel(uint8_t channel) +void RF24::setChannel(const uint8_t channel) { if( wide_band ) { write_register(RF_CH,min(channel,127)); @@ -316,10 +319,6 @@ void RF24::begin(void) // Flush buffers flush_rx(); flush_tx(); - - // Set up default configuration. Callers can always change it later. - // Hardware default is channel 2 - even spacing implied. - setChannel(64); } /******************************************************************/ diff --git a/RF24.h b/RF24.h index ffe6554..956fa27 100644 --- a/RF24.h +++ b/RF24.h @@ -188,8 +188,17 @@ public: * * @param _cepin The pin attached to Chip Enable on the RF module * @param _cspin The pin attached to Chip Select + * @param speed The desired data rate of this network; default is 2Mbs + * @param channel The channel to use for this network; default is 64 + * + * @warning Addition features enabled/set in the begin method should be + * migrated into our constructor. Basically features which are network + * specific should be variable and assignable here; including timeouts, + * retries, and CRC length. */ - RF24(uint8_t _cepin, uint8_t _cspin); + RF24(const uint8_t _cepin, const uint8_t _cspin, + const rf24_datarate_e speed=RF24_2MBPS, + const uint8_t channel=64 ) ; /** * Begin operation of the chip