From d6c7ea921a4e1748e9bbb559538e7e2cdd95f266 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 6 Nov 2021 10:03:10 -0500 Subject: [PATCH 1/2] Added always_powered preference --- bin/regen-protos.bat | 1 + src/PowerFSM.cpp | 5 +++++ src/mesh/generated/admin.pb.h | 2 +- src/mesh/generated/mesh.pb.c | 1 + src/mesh/generated/radioconfig.pb.h | 13 ++++++++----- 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 bin/regen-protos.bat diff --git a/bin/regen-protos.bat b/bin/regen-protos.bat new file mode 100644 index 00000000..a386433e --- /dev/null +++ b/bin/regen-protos.bat @@ -0,0 +1 @@ +cd proto && ..\nanopb-0.4.4\generator-bin\protoc.exe --nanopb_out=-v:..\src\mesh\generated -I=..\proto *.proto diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index 91248c4e..df1d74d6 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -11,6 +11,11 @@ /// Should we behave as if we have AC power now? static bool isPowered() { + // Completely circumvents the battery / power sensing logic and assumes constant power source + if (radioConfig.preferences.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 diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index a1cc1f41..ad07b358 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -79,7 +79,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 417 +#define AdminMessage_size 420 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/mesh.pb.c b/src/mesh/generated/mesh.pb.c index 1e900039..6f5c55eb 100644 --- a/src/mesh/generated/mesh.pb.c +++ b/src/mesh/generated/mesh.pb.c @@ -51,3 +51,4 @@ PB_BIND(ToRadio_PeerInfo, ToRadio_PeerInfo, AUTO) + diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index e30ea3f8..b43313cb 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -145,6 +145,7 @@ typedef struct _RadioConfig_UserPreferences { uint32_t environmental_measurement_plugin_sensor_pin; bool store_forward_plugin_enabled; uint32_t position_flags; + bool always_powered; } RadioConfig_UserPreferences; typedef struct _RadioConfig { @@ -189,9 +190,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, _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, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _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, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 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, _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, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _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, _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define RadioConfig_UserPreferences_position_broadcast_secs_tag 1 @@ -252,6 +253,7 @@ extern "C" { #define RadioConfig_UserPreferences_environmental_measurement_plugin_sensor_pin_tag 147 #define RadioConfig_UserPreferences_store_forward_plugin_enabled_tag 148 #define RadioConfig_UserPreferences_position_flags_tag 150 +#define RadioConfig_UserPreferences_always_powered_tag 151 #define RadioConfig_preferences_tag 1 /* Struct field encoding specification for nanopb */ @@ -319,7 +321,8 @@ X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_display_fare X(a, STATIC, SINGULAR, UENUM, environmental_measurement_plugin_sensor_type, 146) \ X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_sensor_pin, 147) \ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_enabled, 148) \ -X(a, STATIC, SINGULAR, UINT32, position_flags, 150) +X(a, STATIC, SINGULAR, UINT32, position_flags, 150) \ +X(a, STATIC, SINGULAR, BOOL, always_powered, 151) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -331,8 +334,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 414 -#define RadioConfig_UserPreferences_size 411 +#define RadioConfig_size 417 +#define RadioConfig_UserPreferences_size 414 #ifdef __cplusplus } /* extern "C" */ From 2d939d26eec082aba3e42b484fb988f95197ec8c Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 6 Nov 2021 12:11:22 -0500 Subject: [PATCH 2/2] Renamed to is_always_powered for convention --- src/PowerFSM.cpp | 2 +- src/mesh/generated/radioconfig.pb.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp index df1d74d6..e4cf8fae 100644 --- a/src/PowerFSM.cpp +++ b/src/PowerFSM.cpp @@ -12,7 +12,7 @@ static bool isPowered() { // Completely circumvents the battery / power sensing logic and assumes constant power source - if (radioConfig.preferences.always_powered) { + if (radioConfig.preferences.is_always_powered) { return true; } diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index b43313cb..c9207220 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -145,7 +145,7 @@ typedef struct _RadioConfig_UserPreferences { uint32_t environmental_measurement_plugin_sensor_pin; bool store_forward_plugin_enabled; uint32_t position_flags; - bool always_powered; + bool is_always_powered; } RadioConfig_UserPreferences; typedef struct _RadioConfig { @@ -253,7 +253,7 @@ extern "C" { #define RadioConfig_UserPreferences_environmental_measurement_plugin_sensor_pin_tag 147 #define RadioConfig_UserPreferences_store_forward_plugin_enabled_tag 148 #define RadioConfig_UserPreferences_position_flags_tag 150 -#define RadioConfig_UserPreferences_always_powered_tag 151 +#define RadioConfig_UserPreferences_is_always_powered_tag 151 #define RadioConfig_preferences_tag 1 /* Struct field encoding specification for nanopb */ @@ -322,7 +322,7 @@ X(a, STATIC, SINGULAR, UENUM, environmental_measurement_plugin_sensor_type, X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_sensor_pin, 147) \ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_enabled, 148) \ X(a, STATIC, SINGULAR, UINT32, position_flags, 150) \ -X(a, STATIC, SINGULAR, BOOL, always_powered, 151) +X(a, STATIC, SINGULAR, BOOL, is_always_powered, 151) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL