From 02ac97b07ef4910aa41c162236bcf0fcb569aaff Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 29 Dec 2019 12:21:14 +0100 Subject: [PATCH] [SX126x] Added option to change sleep mode (cold/warm start) --- src/modules/SX126x/SX126x.cpp | 8 ++++++-- src/modules/SX126x/SX126x.h | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index ffd84d44..33d7fcb7 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -370,8 +370,12 @@ int16_t SX126x::scanChannel() { return(ERR_UNKNOWN); } -int16_t SX126x::sleep() { - uint8_t data[] = {SX126X_SLEEP_START_COLD | SX126X_SLEEP_RTC_OFF}; +int16_t SX126x::sleep(bool retainConfig) { + uint8_t sleepMode = SX126X_SLEEP_START_WARM; + if(!retainConfig) { + sleepMode = SX126X_SLEEP_START_COLD; + } + uint8_t data[] = {sleepMode | SX126X_SLEEP_RTC_OFF}; int16_t state = SPIwriteCommand(SX126X_CMD_SET_SLEEP, data, 1, false); // wait for SX126x to safely enter sleep mode diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index ff282cca..bfcccbfa 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -452,9 +452,11 @@ class SX126x: public PhysicalLayer { /*! \brief Sets the module to sleep mode. + \param retainConfig Set to true to retain configuration of the currently active modem ("warm start") or to false to discard current configuration ("cold start"). Defaults to true. + \returns \ref status_codes */ - int16_t sleep(); + int16_t sleep(bool retainConfig = true); /*! \brief Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator).