diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 392992191..1548ed9f8 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -1,8 +1,8 @@ -#include "configuration.h" #include "PowerFSM.h" #include "GPS.h" #include "MeshService.h" #include "NodeDB.h" +#include "configuration.h" #include "graphics/Screen.h" #include "main.h" #include "sleep.h" @@ -15,7 +15,7 @@ static bool isPowered() if (radioConfig.preferences.is_always_powered) { return true; } - + bool isRouter = radioConfig.preferences.is_router; // If we are not a router and we already have AC power go to POWER state after init, otherwise go to ON @@ -221,7 +221,8 @@ static void screenPress() screen->onPress(); } -static void bootEnter() { +static void bootEnter() +{ DEBUG_MSG("Enter state: BOOT\n"); } @@ -248,8 +249,10 @@ void PowerFSM_setup() // if we are a router node, we go to NB (no need for bluetooth) otherwise we go to DARK (so we can send message to phone) powerFSM.add_transition(&stateLS, isRouter ? &stateNB : &stateDARK, EVENT_WAKE_TIMER, NULL, "Wake timer"); - // We need this transition, because we might not transition if we were waiting to enter light-sleep, because when we wake from light sleep we _always_ transition to NB or dark and - powerFSM.add_transition(&stateLS, isRouter ? &stateNB : &stateDARK, EVENT_PACKET_FOR_PHONE, NULL, "Received packet, exiting light sleep"); + // We need this transition, because we might not transition if we were waiting to enter light-sleep, because when we wake from + // light sleep we _always_ transition to NB or dark and + powerFSM.add_transition(&stateLS, isRouter ? &stateNB : &stateDARK, EVENT_PACKET_FOR_PHONE, NULL, + "Received packet, exiting light sleep"); powerFSM.add_transition(&stateNB, &stateNB, EVENT_PACKET_FOR_PHONE, NULL, "Received packet, resetting win wake"); // Handle press events - note: we ignore button presses when in API mode @@ -334,15 +337,23 @@ void PowerFSM_setup() #ifndef NRF52_SERIES // We never enter light-sleep or NB states on NRF52 (because the CPU uses so little power normally) - // I don't think this transition is correct, turning off for now - @geeksville - // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + // See: https://github.com/meshtastic/Meshtastic-device/issues/1071 + if (radioConfig.preferences.is_power_saving) { + + // I don't think this transition is correct, turning off for now - @geeksville + // powerFSM.add_timed_transition(&stateDARK, &stateNB, getPref_phone_timeout_secs() * 1000, NULL, "Phone timeout"); + powerFSM.add_timed_transition(&stateNB, &stateLS, getPref_min_wake_secs() * 1000, NULL, "Min wake timeout"); + powerFSM.add_timed_transition(&stateDARK, &stateLS, getPref_wait_bluetooth_secs() * 1000, NULL, "Bluetooth timeout"); + meshSds = getPref_mesh_sds_timeout_secs(); + + } else { + + meshSds = UINT32_MAX; + } - powerFSM.add_timed_transition(&stateNB, &stateLS, getPref_min_wake_secs() * 1000, NULL, "Min wake timeout"); - powerFSM.add_timed_transition(&stateDARK, &stateLS, getPref_wait_bluetooth_secs() * 1000, NULL, "Bluetooth timeout"); - meshSds = getPref_mesh_sds_timeout_secs(); #else lowPowerState = &stateDARK; - meshSds = UINT32_MAX; //Workaround for now: Don't go into deep sleep on the RAK4631 + meshSds = UINT32_MAX; // Workaround for now: Don't go into deep sleep on the RAK4631 #endif if (meshSds != UINT32_MAX) diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index d75c2b418..2fced6a29 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -86,7 +86,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 532 +#define AdminMessage_size 535 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index 9eb6fa875..255b5a88e 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -156,6 +156,7 @@ typedef struct _RadioConfig_UserPreferences { char mqtt_username[32]; char mqtt_password[32]; bool is_lora_tx_disabled; + bool is_power_saving; } RadioConfig_UserPreferences; typedef struct _RadioConfig { @@ -200,9 +201,9 @@ extern "C" { /* Initializer values for message structs */ #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, 0, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, "", 0, _GpsCoordinateFormat_MIN, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -274,6 +275,7 @@ extern "C" { #define RadioConfig_UserPreferences_mqtt_username_tag 155 #define RadioConfig_UserPreferences_mqtt_password_tag 156 #define RadioConfig_UserPreferences_is_lora_tx_disabled_tag 157 +#define RadioConfig_UserPreferences_is_power_saving_tag 158 #define RadioConfig_preferences_tag 1 /* Struct field encoding specification for nanopb */ @@ -352,7 +354,8 @@ X(a, STATIC, SINGULAR, UINT32, on_battery_shutdown_after_secs, 153) \ X(a, STATIC, SINGULAR, UINT32, hop_limit, 154) \ X(a, STATIC, SINGULAR, STRING, mqtt_username, 155) \ X(a, STATIC, SINGULAR, STRING, mqtt_password, 156) \ -X(a, STATIC, SINGULAR, BOOL, is_lora_tx_disabled, 157) +X(a, STATIC, SINGULAR, BOOL, is_lora_tx_disabled, 157) \ +X(a, STATIC, SINGULAR, BOOL, is_power_saving, 158) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -364,8 +367,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_size 529 -#define RadioConfig_UserPreferences_size 526 +#define RadioConfig_size 532 +#define RadioConfig_UserPreferences_size 529 #ifdef __cplusplus } /* extern "C" */