[LPM] Add capability to deactivate the function at build time (#1449)

To enable boards with the constant power supply to don't build this function.
Change the default behavior for the mode not to be built by default.
Only the boards with batteries are keeping it
This commit is contained in:
Florian authored and GitHub committed 2023-02-10 17:07:28 -06:00
1 parent 7c0fafd48e
commit 5bcf214d68
4 files changed
+17 -3

No files matched your search

+5 -1
View File
@@ -336,7 +336,7 @@ build_flags =
'-DLED_SEND_RECEIVE_ON=0' '-DLED_SEND_RECEIVE_ON=0'
'-DGateway_Name="OpenMQTTGateway_LOLIN32LITE_BLE"' '-DGateway_Name="OpenMQTTGateway_LOLIN32LITE_BLE"'
;; Low power parameters, uncomment and fill credentials ;; Low power parameters, uncomment and fill credentials
; '-DDEFAULT_LOW_POWER_MODE=2' '-DDEFAULT_LOW_POWER_MODE=2'
; '-DTimeBtwRead=155000' ; '-DTimeBtwRead=155000'
; '-DScan_duration=2000' ; '-DScan_duration=2000'
; '-DAttemptBLEConnect=false' ; '-DAttemptBLEConnect=false'
@@ -460,6 +460,7 @@ build_flags =
'-DLED_SEND_RECEIVE_ON=1' '-DLED_SEND_RECEIVE_ON=1'
'-DTRIGGER_GPIO=35' '-DTRIGGER_GPIO=35'
'-DIR_EMITTER_GPIO=17' '-DIR_EMITTER_GPIO=17'
'-DDEFAULT_LOW_POWER_MODE=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_BLE_IR"' '-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_BLE_IR"'
board_upload.speed = 921600 board_upload.speed = 921600
custom_description = Expandable module with BLE gateway, display, and little IR emitter custom_description = Expandable module with BLE gateway, display, and little IR emitter
@@ -484,6 +485,7 @@ build_flags =
'-DTRIGGER_GPIO=37' '-DTRIGGER_GPIO=37'
'-DSLEEP_BUTTON=38' '-DSLEEP_BUTTON=38'
'-DINPUT_GPIO=39' '-DINPUT_GPIO=39'
'-DDEFAULT_LOW_POWER_MODE=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_M5STACK_BLE"' '-DGateway_Name="OpenMQTTGateway_ESP32_M5STACK_BLE"'
board_upload.speed = 921600 board_upload.speed = 921600
custom_description = Expandable module with BLE gateway and display custom_description = Expandable module with BLE gateway and display
@@ -533,6 +535,7 @@ build_flags =
'-DTRIGGER_GPIO=39' '-DTRIGGER_GPIO=39'
'-DIR_EMITTER_INVERTED=true' '-DIR_EMITTER_INVERTED=true'
'-DIR_EMITTER_GPIO=9' '-DIR_EMITTER_GPIO=9'
'-DDEFAULT_LOW_POWER_MODE=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_C_BLE_IR"' '-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_C_BLE_IR"'
board_upload.speed = 1500000 board_upload.speed = 1500000
custom_description = Expandable module with BLE gateway, display, and little IR emitter custom_description = Expandable module with BLE gateway, display, and little IR emitter
@@ -563,6 +566,7 @@ build_flags =
'-DTRIGGER_GPIO=39' '-DTRIGGER_GPIO=39'
'-DIR_EMITTER_INVERTED=true' '-DIR_EMITTER_INVERTED=true'
'-DIR_EMITTER_GPIO=9' '-DIR_EMITTER_GPIO=9'
'-DDEFAULT_LOW_POWER_MODE=0'
'-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_CP_BLE_IR"' '-DGateway_Name="OpenMQTTGateway_ESP32_M5STICK_CP_BLE_IR"'
board_upload.speed = 1500000 board_upload.speed = 1500000
custom_description = Expandable module with BLE gateway, display, and little IR emitter custom_description = Expandable module with BLE gateway, display, and little IR emitter
+2 -1
View File
@@ -287,12 +287,13 @@ static_assert(MQTT_SECURE_SELF_SIGNED_INDEX_DEFAULT < (sizeof(certs_array) / siz
#endif #endif
/*------------------DEEP SLEEP parameters ------------------*/ /*------------------DEEP SLEEP parameters ------------------*/
//DEFAULT_LOW_POWER_MODE -1 to normal mode, low power mode can't be used on this build
//DEFAULT_LOW_POWER_MODE 0 to normal mode (no power consumption optimisations) //DEFAULT_LOW_POWER_MODE 0 to normal mode (no power consumption optimisations)
//DEFAULT_LOW_POWER_MODE 1 to activate deep sleep //DEFAULT_LOW_POWER_MODE 1 to activate deep sleep
//DEFAULT_LOW_POWER_MODE 2 to activate deep sleep (LCD is turned OFF) //DEFAULT_LOW_POWER_MODE 2 to activate deep sleep (LCD is turned OFF)
#ifdef ESP32 #ifdef ESP32
# ifndef DEFAULT_LOW_POWER_MODE # ifndef DEFAULT_LOW_POWER_MODE
# define DEFAULT_LOW_POWER_MODE 0 # define DEFAULT_LOW_POWER_MODE -1
# endif # endif
int lowpowermode = DEFAULT_LOW_POWER_MODE; int lowpowermode = DEFAULT_LOW_POWER_MODE;
#endif #endif
+8 -1
View File
@@ -741,12 +741,13 @@ void coreTask(void* pvParameters) {
BLEconnect(); BLEconnect();
} }
dumpDevices(); dumpDevices();
Log.trace(F("CoreTask stack free: %u" CR), uxTaskGetStackHighWaterMark(xCoreTaskHandle));
xSemaphoreGive(semaphoreBLEOperation); xSemaphoreGive(semaphoreBLEOperation);
} else { } else {
Log.error(F("Failed to start scan - BLE busy" CR)); Log.error(F("Failed to start scan - BLE busy" CR));
} }
} }
if (lowpowermode) { if (lowpowermode > 0) {
lowPowerESP32(); lowPowerESP32();
int scan = atomic_exchange_explicit(&forceBTScan, 0, ::memory_order_seq_cst); // is this enough, it will wait the full deepsleep... int scan = atomic_exchange_explicit(&forceBTScan, 0, ::memory_order_seq_cst); // is this enough, it will wait the full deepsleep...
if (scan == 1) BTforceScan(); if (scan == 1) BTforceScan();
@@ -764,6 +765,7 @@ void coreTask(void* pvParameters) {
} }
} }
# if DEFAULT_LOW_POWER_MODE != -1
void lowPowerESP32() { // low power mode void lowPowerESP32() { // low power mode
Log.trace(F("Going to deep sleep for: %l s" CR), (TimeBtwRead / 1000)); Log.trace(F("Going to deep sleep for: %l s" CR), (TimeBtwRead / 1000));
deepSleep(TimeBtwRead * 1000); deepSleep(TimeBtwRead * 1000);
@@ -786,8 +788,12 @@ void deepSleep(uint64_t time_in_us) {
esp_wifi_stop(); esp_wifi_stop();
esp_deep_sleep(time_in_us); esp_deep_sleep(time_in_us);
} }
# else
void lowPowerESP32() {}
# endif
void changelowpowermode(int newLowPowerMode) { void changelowpowermode(int newLowPowerMode) {
# if DEFAULT_LOW_POWER_MODE != -1
Log.notice(F("Changing LOW POWER mode to: %d" CR), newLowPowerMode); Log.notice(F("Changing LOW POWER mode to: %d" CR), newLowPowerMode);
# if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH) # if defined(ZboardM5STACK) || defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5TOUGH)
if (lowpowermode == 2) { if (lowpowermode == 2) {
@@ -809,6 +815,7 @@ void changelowpowermode(int newLowPowerMode) {
preferences.end(); preferences.end();
// Publish the states to update the controller switch status // Publish the states to update the controller switch status
stateMeasures(); stateMeasures();
# endif
} }
void setupBT() { void setupBT() {
+2
View File
@@ -1029,6 +1029,7 @@ void pubMqttDiscovery() {
stateClassNone, //State Class stateClassNone, //State Class
"false", "true" //state_off, state_on "false", "true" //state_off, state_on
); );
# if DEFAULT_LOW_POWER_MODE != -1
createDiscovery("switch", //set Type createDiscovery("switch", //set Type
subjectSYStoMQTT, "SYS: Low Power Mode command", (char*)getUniqueId("lowpowermode", "").c_str(), //set state_topic,name,uniqueId subjectSYStoMQTT, "SYS: Low Power Mode command", (char*)getUniqueId("lowpowermode", "").c_str(), //set state_topic,name,uniqueId
"", "", "{{ value_json.lowpowermode | bool }}", //set availability_topic,device_class,value_template, "", "", "{{ value_json.lowpowermode | bool }}", //set availability_topic,device_class,value_template,
@@ -1041,5 +1042,6 @@ void pubMqttDiscovery() {
); );
# endif # endif
# endif # endif
# endif
} }
#endif #endif