diff --git a/src/TypeDef.h b/src/TypeDef.h index 0ac5d2ef..49a29f78 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -213,6 +213,11 @@ */ #define RADIOLIB_ERR_INVALID_DIO_PIN (-26) +/*! + \brief The supplied RSSI threshold is invalid. +*/ +#define RADIOLIB_ERR_INVALID_RSSI_THRESHOLD (-27) + // RF69-specific status codes /*! diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 9fc69ef2..9867b576 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -872,6 +872,12 @@ float RF69::getRSSI() { return(-1.0 * (_mod->SPIgetRegValue(RADIOLIB_RF69_REG_RSSI_VALUE)/2.0)); } +int16_t RF69::setRSSIThreshold(float dbm) { + RADIOLIB_CHECK_RANGE(dbm, -127.5, 0, RADIOLIB_ERR_INVALID_RSSI_THRESHOLD); + + return _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0); +} + void RF69::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { _mod->setRfSwitchPins(rxEn, txEn); } diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index ef9969e2..e1d3acf7 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -961,6 +961,15 @@ class RF69: public PhysicalLayer { */ float getRSSI(); + /*! + \brief Sets the RSSI value above which the RSSI interrupt is signaled + + \param dbm A dBm value between -127.5 and 0 inclusive + + \returns \ref status_codes + */ + int16_t setRSSIThreshold(float dbm); + /*! \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 29980071..6734b1b5 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -1184,6 +1184,12 @@ int16_t SX127x::setCrcFiltering(bool crcOn) { } } +int16_t SX127x::setRSSIThreshold(float dbm) { + RADIOLIB_CHECK_RANGE(dbm, -127.5, 0, RADIOLIB_ERR_INVALID_RSSI_THRESHOLD); + + return _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0); +} + int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) { // check active modem if(getActiveModem() != RADIOLIB_SX127X_FSK_OOK) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 996776c9..87be55e6 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -1227,6 +1227,15 @@ class SX127x: public PhysicalLayer { */ int16_t setDIOPreambleDetect(bool usePreambleDetect); + /*! + \brief Sets the RSSI value above which the RSSI interrupt is signaled + + \param dbm A dBm value between -127.5 and 0 inclusive + + \returns \ref status_codes + */ + int16_t setRSSIThreshold(float dbm); + #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) protected: #endif