diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index bf25174a..79212eee 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -449,20 +449,17 @@ int16_t SX126x::standby() { return(SX126x::standby(RADIOLIB_SX126X_STANDBY_RC)); } -int16_t SX126x::standby(uint8_t mode) { +int16_t SX126x::standby(uint8_t mode, bool wakeup) { // set RF switch (if present) this->mod->setRfSwitchState(Module::MODE_IDLE); - uint8_t data[] = { mode }; - int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1); - if(state == RADIOLIB_ERR_NONE) { - return(state); - } else if(state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) { - // the device might be in sleep mode, pull NSS low to wake up and try again + if(wakeup) { + // pull NSS low to wake up this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow); - return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1)); } - return(state); + + uint8_t data[] = { mode }; + return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1)); } void SX126x::setDio1Action(void (*func)(void)) { diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index f24fa807..e685338a 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -555,9 +555,10 @@ class SX126x: public PhysicalLayer { \brief Sets the module to standby mode. \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX126X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX126X_STANDBY_XOSC (32 MHz external crystal oscillator). + \param wakeup Whether to force the module to wake up. Setting to true will immediately attempt to wake up the module. \returns \ref status_codes */ - int16_t standby(uint8_t mode); + int16_t standby(uint8_t mode, bool wakeup = true); // interrupt methods