Load ratios after boot + show pwr defaults with get (#2241)

* emon: configure ratios without reboot

* settings: serialize() support

* debug: use vsnprintf from newlib, not from sdk

* settings/experimental: show defaults via `get`

* emon: override base methods, fix defaults

* sensor/emon: expose internal index calculation

- refactor configuration to use the correct index when accessing indexed
  sensor methods. store index value on magnitude, refactor loops to
  accomodate this new functionality
- rename slot(index) -> description(index), since we use 'slot' as
  numeric value
This commit is contained in:
Max Prokhorov
2020-05-12 21:17:01 +03:00
committed by GitHub
parent a2a44c28d4
commit 025e8c82ab
53 changed files with 562 additions and 245 deletions

View File

@@ -29,6 +29,8 @@ char _udp_syslog_header[40] = {0};
bool _debug_enabled = false;
// -----------------------------------------------------------------------------
// printf-like debug methods
// -----------------------------------------------------------------------------
@@ -41,7 +43,7 @@ void _debugSendInternal(const char * message, bool add_timestamp = DEBUG_ADD_TIM
void _debugSend(const char * format, va_list args) {
char temp[DEBUG_SEND_STRING_BUFFER_SIZE];
int len = ets_vsnprintf(temp, sizeof(temp), format, args);
int len = vsnprintf(temp, sizeof(temp), format, args);
// strlen(...) + '\0' already in temp buffer, avoid using malloc when possible
if (len < DEBUG_SEND_STRING_BUFFER_SIZE) {
@@ -54,7 +56,7 @@ void _debugSend(const char * format, va_list args) {
if (!buffer) {
return;
}
ets_vsnprintf(buffer, len, format, args);
vsnprintf(buffer, len, format, args);
_debugSendInternal(buffer);
free(buffer);
@@ -282,19 +284,29 @@ void debugSetup() {
}
String _debugLogModeSerialize(DebugLogMode value) {
namespace settings {
namespace internal {
template<>
String serialize(const DebugLogMode& value) {
String result;
switch (value) {
case DebugLogMode::Disabled:
return "0";
result = "0";
break;
case DebugLogMode::SkipBoot:
return "2";
result = "2";
break;
default:
case DebugLogMode::Enabled:
return "1";
result = "1";
break;
}
return result;
}
DebugLogMode _debugLogModeDeserialize(const String& value) {
template<>
DebugLogMode convert(const String& value) {
switch (value.toInt()) {
case 0:
return DebugLogMode::Disabled;
@@ -306,13 +318,16 @@ DebugLogMode _debugLogModeDeserialize(const String& value) {
}
}
}
}
void debugConfigureBoot() {
static_assert(
std::is_same<int, std::underlying_type<DebugLogMode>::type>::value,
"should be able to match DebugLogMode with int"
);
const auto mode = getSetting<DebugLogMode, _debugLogModeDeserialize>("dbgLogMode", DEBUG_LOG_MODE);
const auto mode = getSetting("dbgLogMode", DEBUG_LOG_MODE);
switch (mode) {
case DebugLogMode::SkipBoot:
schedule_function([]() {