diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index e9e36700..0de4e2e6 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -89,7 +89,9 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po RADIOLIB_ASSERT(state); // set default sync word - state = setSyncWord(0x12, 0xAD, 0, false); + //state = setSyncWord(0x12, 0xAD, 0, false); + uint8_t sw[2] = RADIOLIB_CC1101_DEFAULT_SW; + state = setSyncWord(sw[0], sw[1], 0, false); RADIOLIB_ASSERT(state); // flush FIFOs @@ -470,7 +472,8 @@ int16_t CC1101::setBitRate(float br) { int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, e, 3, 0); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG3, m); if(state == RADIOLIB_ERR_NONE) { - CC1101::_br = br; + //CC1101::_br = br; + _br = br; } return(state); } @@ -487,8 +490,16 @@ int16_t CC1101::setRxBandwidth(float rxBw) { float point = (RADIOLIB_CC1101_CRYSTAL_FREQ * 1000000.0)/(8 * (m + 4) * ((uint32_t)1 << e)); if(fabs((rxBw * 1000.0) - point) <= 1000) { // set Rx channel filter bandwidth - return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4)); + //return(SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4)); + uint16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG4, (e << 6) | (m << 4), 7, 4); + + if(state == ERR_NONE) { + _rxBw = rxBw; + } + + return(state); } + } } @@ -515,6 +526,13 @@ int16_t CC1101::setFrequencyDeviation(float freqDev) { // set frequency deviation value int16_t state = SPIsetRegValue(RADIOLIB_CC1101_REG_DEVIATN, (e << 4), 6, 4); state |= SPIsetRegValue(RADIOLIB_CC1101_REG_DEVIATN, m, 2, 0); + + if(state == ERR_NONE) { + _freqDev = freqDev; + } + + + return(state); } @@ -606,7 +624,7 @@ int16_t CC1101::setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits, } } - _syncWordLength = len; + //_syncWordLength = len; // enable sync word filtering int16_t state = enableSyncWordFiltering(maxErrBits, requireCarrierSense); @@ -657,7 +675,13 @@ int16_t CC1101::setPreambleLength(uint8_t preambleLength) { } - return SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4); + //return SPIsetRegValue(RADIOLIB_CC1101_REG_MDMCFG1, value, 6, 4); + uint16_t state = SPIsetRegValue(CC1101_REG_MDMCFG1, value, 6, 4); + if(state == ERR_NONE) { + _preambleLen = preambleLength; + } + + return(state); } diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index a661107f..037ee091 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -499,6 +499,16 @@ #define RADIOLIB_CC1101_GDO2_ACTIVE 0b00000100 // 2 2 GDO2 is active/asserted #define RADIOLIB_CC1101_GDO0_ACTIVE 0b00000001 // 0 0 GDO0 is active/asserted +//Defaults +#define RADIOLIB_CC1101_DEFAULT_FREQ 434.0 +#define RADIOLIB_CC1101_DEFAULT_BR 48.0 +#define RADIOLIB_CC1101_DEFAULT_FREQDEV 48.0 +#define RADIOLIB_CC1101_DEFAULT_RXBW 135.0 +#define RADIOLIB_CC1101_DEFAULT_POWER 10 +#define RADIOLIB_CC1101_DEFAULT_PREAMBLELEN 16 +#define RADIOLIB_CC1101_DEFAULT_SW {0x12, 0xAD} +#define RADIOLIB_CC1101_DEFAULT_SW_LEN 2 + /*! \class CC1101 @@ -966,8 +976,14 @@ class CC1101: public PhysicalLayer { protected: #endif - float _freq = 0; - float _br = 0; + float _freq = RADIOLIB_CC1101_DEFAULT_FREQ; + float _br = RADIOLIB_CC1101_DEFAULT_BR; + float _freqDev = RADIOLIB_CC1101_DEFAULT_FREQDEV; + float _rxBw = RADIOLIB_CC1101_DEFAULT_RXBW; + int8_t _power = RADIOLIB_CC1101_DEFAULT_POWER; + uint8_t _preambleLen = RADIOLIB_CC1101_DEFAULT_PREAMBLELEN; + //float _freq = 0; + //float _br = 0; uint8_t _rawRSSI = 0; uint8_t _rawLQI = 0; uint8_t _modulation = RADIOLIB_CC1101_MOD_FORMAT_2_FSK; @@ -980,8 +996,9 @@ class CC1101: public PhysicalLayer { bool _crcOn = true; bool _directMode = true; - uint8_t _syncWordLength = 2; - int8_t _power = 0; + //uint8_t _syncWordLength = 2; + //int8_t _power = 0; + uint8_t _syncWordLength = RADIOLIB_CC1101_DEFAULT_SW_LEN; int16_t config(); int16_t transmitDirect(bool sync, uint32_t frf); diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 9867b576..f1bba510 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -59,7 +59,8 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe RADIOLIB_ASSERT(state); // configure bitrate - _rxBw = 125.0; + //_rxBw = 125.0; + _rxBw = rxBw; state = setBitRate(br); RADIOLIB_ASSERT(state); @@ -84,7 +85,8 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe RADIOLIB_ASSERT(state); // set default sync word - uint8_t syncWord[] = {0x12, 0xAD}; + //uint8_t syncWord[] = {0x12, 0xAD}; + uint8_t syncWord[] = RADIOLIB_RF69_DEFAULT_SW; state = setSyncWord(syncWord, sizeof(syncWord)); RADIOLIB_ASSERT(state); @@ -551,7 +553,8 @@ int16_t RF69::setBitRate(float br) { int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); if(state == RADIOLIB_ERR_NONE) { - RF69::_br = br; + //RF69::_br = br; + _br = br; } return(state); } @@ -574,7 +577,8 @@ int16_t RF69::setRxBandwidth(float rxBw) { // set Rx bandwidth state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, (m << 3) | e, 4, 0); if(state == RADIOLIB_ERR_NONE) { - RF69::_rxBw = rxBw; + //RF69::_rxBw = rxBw; + _rxBw = rxBw; } return(state); } @@ -604,6 +608,9 @@ int16_t RF69::setFrequencyDeviation(float freqDev) { uint32_t fdev = (newFreqDev * (base << 19)) / 32000; int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, (fdev & 0xFF00) >> 8, 5, 0); state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, fdev & 0x00FF, 7, 0); + if (state == ERR_NONE) { + _freqDev = freqDev; + } return(state); } @@ -659,14 +666,19 @@ int16_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) { } } - _syncWordLength = len; + //_syncWordLength = len; int16_t state = enableSyncWordFiltering(maxErrBits); RADIOLIB_ASSERT(state); // set sync word register _mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_SYNC_VALUE_1, syncWord, len); - return(RADIOLIB_ERR_NONE); + //return(RADIOLIB_ERR_NONE); + if(state == ERR_NONE) { + _syncWordLength = len; + } + + return(state); } int16_t RF69::setPreambleLength(uint8_t preambleLen) { @@ -677,7 +689,14 @@ int16_t RF69::setPreambleLength(uint8_t preambleLen) { uint8_t preLenBytes = preambleLen / 8; _mod->SPIwriteRegister(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0x00); - return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes)); + //return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes)); + uint16_t state = _mod->SPIsetRegValue(RF69_REG_PREAMBLE_LSB, preLenBytes); + + if (state == ERR_NONE) { + _preambleLen = preambleLen; + } + + return (state); } int16_t RF69::setNodeAddress(uint8_t nodeAddr) { @@ -818,6 +837,10 @@ int16_t RF69::setPromiscuousMode(bool promiscuous) { // enable CRC filtering state = setCrcFiltering(true); } + if(state == ERR_NONE) { + _promiscuous = promiscuous; + } + return(state); } diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index e1d3acf7..3be0a8e9 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -462,6 +462,15 @@ #define RADIOLIB_RF69_PA2_NORMAL 0x70 // 7 0 PA_BOOST: none #define RADIOLIB_RF69_PA2_20_DBM 0x7C // 7 0 +20 dBm +// Defaults +#define RADIOLIB_RF69_DEFAULT_FREQ 434.0 +#define RADIOLIB_RF69_DEFAULT_BR 48.0 +#define RADIOLIB_RF69_DEFAULT_FREQDEV 50.0 +#define RADIOLIB_RF69_DEFAULT_RXBW 125.0 +#define RADIOLIB_RF69_DEFAULT_POWER 10 +#define RADIOLIB_RF69_DEFAULT_PREAMBLELEN 16 +#define RADIOLIB_RF69_DEFAULT_SW {0x12, 0xAD} +#define RADIOLIB_RF69_DEFAULT_SW_LEN 2 /*! \class RF69 @@ -503,8 +512,14 @@ class RF69: public PhysicalLayer { \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16); - + //int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16); + int16_t begin( + float freq = RADIOLIB_RF69_DEFAULT_FREQ, + float br = RADIOLIB_RF69_DEFAULT_BR, + float freqDev = RADIOLIB_RF69_DEFAULT_FREQDEV, + float rxBw = RADIOLIB_RF69_DEFAULT_RXBW, + int8_t power = RADIOLIB_RF69_DEFAULT_POWER, + uint8_t preambleLen = RADIOLIB_RF69_DEFAULT_PREAMBLELEN); /*! \brief Reset method. Will reset the chip to the default state using RST pin. */ @@ -1030,20 +1045,29 @@ class RF69: public PhysicalLayer { protected: #endif - float _freq = 0; - float _br = 0; - float _rxBw = 0; - bool _ook = false; - int16_t _tempOffset = 0; - int8_t _power = 0; + //float _freq = 0; + //float _br = 0; + //float _rxBw = 0; + //bool _ook = false; + //int16_t _tempOffset = 0; + //int8_t _power = 0; + float _freq = RADIOLIB_RF69_DEFAULT_FREQ; + float _br = RADIOLIB_RF69_DEFAULT_BR; + float _freqDev = RADIOLIB_RF69_DEFAULT_FREQDEV; + float _rxBw = RADIOLIB_RF69_DEFAULT_RXBW; + int8_t _power = RADIOLIB_RF69_DEFAULT_POWER; + uint8_t _preambleLen = RADIOLIB_RF69_DEFAULT_PREAMBLELEN; size_t _packetLength = 0; bool _packetLengthQueried = false; uint8_t _packetLengthConfig = RADIOLIB_RF69_PACKET_FORMAT_VARIABLE; bool _promiscuous = false; + bool _ook = false; + int16_t _tempOffset = 0; - uint8_t _syncWordLength = 2; + //uint8_t _syncWordLength = 2; + uint8_t _syncWordLength = RADIOLIB_RF69_DEFAULT_SW_LEN; bool _bitSync = true; diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 3b90ba70..f4a07066 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -251,7 +251,14 @@ int16_t nRF24::setFrequency(int16_t freq) { // set frequency uint8_t freqRaw = freq - 2400; - return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0)); + //return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0)); + uint16_t state = _mod->SPIsetRegValue(NRF24_REG_RF_CH, freqRaw, 6, 0); + + if(state == ERR_NONE) { + _freq = freq; + } + + return(state); } int16_t nRF24::setDataRate(int16_t dataRate) { @@ -272,6 +279,11 @@ int16_t nRF24::setDataRate(int16_t dataRate) { } else { return(RADIOLIB_ERR_INVALID_DATA_RATE); } + + if(state == ERR_NONE) { + _dataRate = dataRate; + } + return(state); } @@ -302,6 +314,12 @@ int16_t nRF24::setOutputPower(int8_t power) { // write new register value state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1); + + if(state == ERR_NONE) { + _power = power; + } + + return(state); } @@ -331,7 +349,10 @@ int16_t nRF24::setAddressWidth(uint8_t addrWidth) { } // save address width - _addrWidth = addrWidth; + //_addrWidth = addrWidth; + if(state == ERR_NONE) { + _addrWidth = addrWidth; + } return(state); } diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 8b6226dc..b51fb3a7 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -171,6 +171,13 @@ #define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default) #define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled +// Defaults +#define RADIOLIB_NRF24_DEFAULT_FREQ 2400 +#define RADIOLIB_NRF24_DEFAULT_DR 1000 +#define RADIOLIB_NRF24_DEFAULT_POWER -12 +#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5 + + /*! \class nRF24 @@ -208,8 +215,12 @@ class nRF24: public PhysicalLayer { \returns \ref status_codes */ - int16_t begin(int16_t freq = 2400, int16_t dataRate = 1000, int8_t power = -12, uint8_t addrWidth = 5); - + //int16_t begin(int16_t freq = 2400, int16_t dataRate = 1000, int8_t power = -12, uint8_t addrWidth = 5); + int16_t begin( + int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ, + int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR, + int8_t power = RADIOLIB_NRF24_DEFAULT_POWER, + uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH); /*! \brief Sets the module to sleep mode. @@ -502,7 +513,12 @@ class nRF24: public PhysicalLayer { protected: #endif - uint8_t _addrWidth = 0; + //uint8_t _addrWidth = 0; + int16_t _freq = RADIOLIB_NRF24_DEFAULT_FREQ; + int16_t _dataRate = RADIOLIB_NRF24_DEFAULT_DR; + int8_t _power = RADIOLIB_NRF24_DEFAULT_POWER; + uint8_t _addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH; + int16_t config(); void clearIRQ();