diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 755c39b4..d3c6bb58 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -243,11 +243,6 @@ int16_t SX1272::setOutputPower(int8_t power) { } int16_t SX1272::setGain(uint8_t gain) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - // check allowed range if(gain > 6) { return(ERR_INVALID_GAIN); @@ -256,14 +251,30 @@ int16_t SX1272::setGain(uint8_t gain) { // set mode to standby int16_t state = SX127x::standby(); - // set gain - if(gain == 0) { - // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1272_AGC_AUTO_ON, 2, 2); - } else { - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1272_AGC_AUTO_OFF, 2, 2); - state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); + // get modem + int16_t modem = getActiveModem(); + if(modem == SX127X_LORA){ + // set gain + if(gain == 0) { + // gain set to 0, enable AGC loop + state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1272_AGC_AUTO_ON, 2, 2); + } else { + state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1272_AGC_AUTO_OFF, 2, 2); + state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); + } + + } else if(modem == SX127X_FSK_OOK) { + // set gain + if(gain == 0) { + // gain set to 0, enable AGC loop + state |= _mod->SPIsetRegValue(SX127X_REG_RX_CONFIG, SX127X_AGC_AUTO_ON, 3, 3); + } else { + state |= _mod->SPIsetRegValue(SX127X_REG_RX_CONFIG, SX127X_AGC_AUTO_ON, 3, 3); + state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); + } + } + return(state); } @@ -330,7 +341,7 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) { return(state); } -float SX1272::getRSSI(bool skip_activation) { +float SX1272::getRSSI(bool skipReceive) { if(getActiveModem() == SX127X_LORA) { // RSSI calculation uses different constant for low-frequency and high-frequency ports float lastPacketRSSI = -139 + _mod->SPIgetRegValue(SX127X_REG_PKT_RSSI_VALUE); @@ -346,13 +357,17 @@ float SX1272::getRSSI(bool skip_activation) { } else { // enable listen mode - startReceive(); + if(!skipReceive) { + startReceive(); + } // read the value for FSK float rssi = (float)_mod->SPIgetRegValue(SX127X_REG_RSSI_VALUE_FSK) / -2.0; // set mode back to standby - standby(); + if(!skipReceive) { + standby(); + } // return the value return(rssi); diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 6ec58071..60fcf7e7 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -240,11 +240,11 @@ class SX1272: public SX127x { /*! \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. - \param skip_activation in OOK/FSK mode this function will put receiver in receive mode and then in standby. Make it TRUE if you don't want this behaviour. + \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode. \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem. */ - float getRSSI(bool skip_activation = false); + float getRSSI(bool skipReceive = false); /*! \brief Enables/disables CRC check of received packets. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 3e708bb3..fbf2f766 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -315,8 +315,6 @@ int16_t SX1278::setOutputPower(int8_t power) { } int16_t SX1278::setGain(uint8_t gain) { - int16_t modem = getActiveModem(); - // check allowed range if(gain > 6) { return(ERR_INVALID_GAIN); @@ -325,6 +323,8 @@ int16_t SX1278::setGain(uint8_t gain) { // set mode to standby int16_t state = SX127x::standby(); + // get modem + int16_t modem = getActiveModem(); if(modem == SX127X_LORA){ // set gain if(gain == 0) { @@ -334,8 +334,8 @@ int16_t SX1278::setGain(uint8_t gain) { state |= _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_AGC_AUTO_OFF, 2, 2); state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); } - } - else if(modem == SX127X_FSK_OOK) { + + } else if(modem == SX127X_FSK_OOK) { // set gain if(gain == 0) { // gain set to 0, enable AGC loop @@ -344,8 +344,9 @@ int16_t SX1278::setGain(uint8_t gain) { state |= _mod->SPIsetRegValue(SX127X_REG_RX_CONFIG, SX127X_AGC_AUTO_ON, 3, 3); state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); } + } - + return(state); } @@ -411,7 +412,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) { return(state); } -float SX1278::getRSSI(bool skip_activation) { +float SX1278::getRSSI(bool skipReceive) { if(getActiveModem() == SX127X_LORA) { // for LoRa, get RSSI of the last packet float lastPacketRSSI; @@ -434,15 +435,17 @@ float SX1278::getRSSI(bool skip_activation) { } else { // enable listen mode - if(!skip_activation) + if(!skipReceive) { startReceive(); + } // read the value for FSK float rssi = (float)_mod->SPIgetRegValue(SX127X_REG_RSSI_VALUE_FSK) / -2.0; // set mode back to standby - if(!skip_activation) + if(!skipReceive) { standby(); + } // return the value return(rssi); diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 40bcab66..1a68a47e 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -248,11 +248,11 @@ class SX1278: public SX127x { /*! \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. - \param skip_activation in OOK/FSK mode this function will put receiver in receive mode and then in standby. Make it TRUE if you don't want this behaviour. + \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode. \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem. */ - float getRSSI(bool skip_activation=false); + float getRSSI(bool skipReceive = false); /*! \brief Enables/disables CRC check of received packets. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index a9127da9..b508cd7c 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -841,11 +841,7 @@ int16_t SX127x::setOokThresholdType(uint8_t type) { if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); } - - int16_t state = ERR_NONE; - state = _mod->SPIsetRegValue(SX127X_REG_OOK_PEAK, type, 4, 3, 5); - - return(state); + return(_mod->SPIsetRegValue(SX127X_REG_OOK_PEAK, type, 4, 3, 5)); } int16_t SX127x::setOokFixedOrFloorThreshold(uint8_t value) { @@ -853,11 +849,7 @@ int16_t SX127x::setOokFixedOrFloorThreshold(uint8_t value) { if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); } - - int16_t state = ERR_NONE; - state = _mod->SPIsetRegValue(SX127X_REG_OOK_FIX, value, 7, 0, 5); - - return(state); + return(_mod->SPIsetRegValue(SX127X_REG_OOK_FIX, value, 7, 0, 5)); } int16_t SX127x::setOokPeakThresholdDecrement(uint8_t value) { @@ -865,15 +857,9 @@ int16_t SX127x::setOokPeakThresholdDecrement(uint8_t value) { if(getActiveModem() != SX127X_FSK_OOK) { return(ERR_WRONG_MODEM); } - - int16_t state = ERR_NONE; - state = _mod->SPIsetRegValue(SX127X_REG_OOK_AVG, value, 7, 5, 5); - - return(state); + return(_mod->SPIsetRegValue(SX127X_REG_OOK_AVG, value, 7, 5, 5)); } - - int16_t SX127x::setOOK(bool enableOOK) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index c1d53f0f..5ed17ddb 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -860,28 +860,27 @@ class SX127x: public PhysicalLayer { int16_t setOOK(bool enableOOK); /*! - \brief Selects the type of threshold in the OOK data slicer + \brief Selects the type of threshold in the OOK data slicer. - \param type SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_AVERAGE + \param type Threshold type: SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_AVERAGE \returns \ref status_codes */ int16_t setOokThresholdType(uint8_t type); /*! - \brief Period of decrement of the RSSI threshold in the OOK demodulator + \brief Period of decrement of the RSSI threshold in the OOK demodulator. - \param value use defines SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP + \param value Use defines SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP \returns \ref status_codes */ int16_t setOokPeakThresholdDecrement(uint8_t value); /*! - \brief Fixed threshold for the Data Slicer in OOK mode - Floor threshold for the Data Slicer in OOK when Peak mode is used + \brief Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used. - \param value calculation is (128 - value/2) + \param value The actual value used by teh data slicer is (128 - value/2). \returns \ref status_codes */