This commit is contained in:
MichaelDvP
2022-05-04 16:04:46 +02:00
15 changed files with 86 additions and 37 deletions

View File

@@ -670,12 +670,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
// handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) {
auto value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7];
obj["v"] = Helpers::render_boolean(s, value_b);
}
char s[7];
obj["v"] = Helpers::render_boolean(s, value_b, true);
}
// handle TEXT strings
@@ -748,8 +744,8 @@ void EMSdevice::generate_values_web(JsonObject & output) {
} else if (dv.type == DeviceValueType::BOOL) {
JsonArray l = obj.createNestedArray("l");
char result[10];
l.add(Helpers::render_boolean(result, false));
l.add(Helpers::render_boolean(result, true));
l.add(Helpers::render_boolean(result, false, true));
l.add(Helpers::render_boolean(result, true, true));
}
// add command help template
else if (dv.type == DeviceValueType::STRING || dv.type == DeviceValueType::CMD) {
@@ -789,12 +785,8 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
// handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) {
auto value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7];
obj["v"] = Helpers::render_boolean(s, value_b);
}
char s[7];
obj["v"] = Helpers::render_boolean(s, value_b, true);
}
// handle TEXT strings

View File

@@ -176,8 +176,8 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
// work out how to display booleans
// for strings only
char * Helpers::render_boolean(char * result, bool value) {
uint8_t bool_format_ = EMSESP::system_.bool_format();
char * Helpers::render_boolean(char * result, const bool value, const bool dashboard) {
uint8_t bool_format_ = dashboard ? EMSESP::system_.bool_dashboard() : EMSESP::system_.bool_format();
if (bool_format_ == BOOL_FORMAT_ONOFF_STR) {
strlcpy(result, value ? read_flash_string(F_(on)).c_str() : read_flash_string(F_(off)).c_str(), 5);
} else if (bool_format_ == BOOL_FORMAT_ONOFF_STR_CAP) {

View File

@@ -37,7 +37,7 @@ class Helpers {
static char * render_value(char * result, const uint32_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const int16_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_value(char * result, const int32_t value, const int8_t format, const uint8_t fahrenheit = 0);
static char * render_boolean(char * result, bool value);
static char * render_boolean(char * result, const bool value, const bool dashboard = false);
static char * hextoa(char * result, const uint8_t value);
static char * hextoa(char * result, const uint16_t value);

View File

@@ -332,10 +332,11 @@ void System::reload_settings() {
syslog_host_ = settings.syslog_host;
syslog_port_ = settings.syslog_port;
fahrenheit_ = settings.fahrenheit;
bool_format_ = settings.bool_format;
enum_format_ = settings.enum_format;
readonly_mode_ = settings.readonly_mode;
fahrenheit_ = settings.fahrenheit;
bool_format_ = settings.bool_format;
bool_dashboard_ = settings.bool_dashboard;
enum_format_ = settings.enum_format;
readonly_mode_ = settings.readonly_mode;
phy_type_ = settings.phy_type;
eth_power_ = settings.eth_power;
@@ -1016,6 +1017,7 @@ bool System::command_settings(const char * value, const int8_t id, JsonObject &
node["fahrenheit"] = settings.fahrenheit;
node["dallas_parasite"] = settings.dallas_parasite;
node["bool_format"] = settings.bool_format;
node["bool_dashboard"] = settings.bool_dashboard;
node["enum_format"] = settings.enum_format;
node["analog_enabled"] = settings.analog_enabled;
node["telnet_enabled"] = settings.telnet_enabled;

View File

@@ -115,6 +115,10 @@ class System {
return bool_format_;
}
uint8_t bool_dashboard() {
return bool_dashboard_;
}
// see default_settings.h
// BOOL_FORMAT_ONOFF_STR = 1,
// BOOL_FORMAT_ONOFF_STR_CAP = 2
@@ -126,6 +130,10 @@ class System {
bool_format_ = format;
}
void bool_dashboard(uint8_t format) {
bool_dashboard_ = format;
}
uint8_t enum_format() {
return enum_format_;
}
@@ -250,6 +258,7 @@ class System {
String syslog_host_;
uint16_t syslog_port_;
bool fahrenheit_;
uint8_t bool_dashboard_;
uint8_t bool_format_;
uint8_t enum_format_;
bool readonly_mode_;

View File

@@ -66,6 +66,7 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) {
root["board_profile"] = settings.board_profile;
root["fahrenheit"] = settings.fahrenheit;
root["bool_format"] = settings.bool_format;
root["bool_dashboard"] = settings.bool_dashboard;
root["enum_format"] = settings.enum_format;
root["weblog_level"] = settings.weblog_level;
root["weblog_buffer"] = settings.weblog_buffer;
@@ -225,6 +226,9 @@ StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings)
settings.bool_format = root["bool_format"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_format(settings.bool_format);
settings.bool_dashboard = root["bool_dashboard"] | EMSESP_DEFAULT_BOOL_FORMAT;
EMSESP::system_.bool_dashboard(settings.bool_dashboard);
settings.enum_format = root["enum_format"] | EMSESP_DEFAULT_ENUM_FORMAT;
EMSESP::system_.enum_format(settings.enum_format);

View File

@@ -57,6 +57,7 @@ class WebSettings {
uint8_t solar_maxflow;
String board_profile;
uint8_t bool_format;
uint8_t bool_dashboard;
uint8_t enum_format;
int8_t weblog_level;
uint8_t weblog_buffer;

View File

@@ -190,21 +190,31 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
void WebStatusService::mDNS_start() const {
#ifndef EMSESP_STANDALONE
MDNS.end();
if (!MDNS.begin(EMSESP::system_.hostname().c_str())) {
EMSESP::logger().warning(F("Failed to start mDNS responder service"));
return;
}
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
if (!MDNS.begin(EMSESP::system_.hostname().c_str())) {
EMSESP::logger().warning(F("Failed to start mDNS responder service"));
return;
}
std::string address_s = EMSESP::system_.hostname() + ".local";
std::string address_s = EMSESP::system_.hostname() + ".local";
MDNS.addService("http", "tcp", 80); // add our web server and rest API
MDNS.addService("telnet", "tcp", 23); // add our telnet console
MDNS.addService("http", "tcp", 80); // add our web server and rest API
MDNS.addService("telnet", "tcp", 23); // add our telnet console
MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION);
MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str());
MDNS.addServiceTxt("http", "tcp", "version", EMSESP_APP_VERSION);
MDNS.addServiceTxt("http", "tcp", "address", address_s.c_str());
EMSESP::logger().info(F("mDNS responder service started"));
}
});
#else
EMSESP::esp8266React.getNetworkSettingsService()->read([&](NetworkSettings & networkSettings) {
if (networkSettings.enableMDNS) {
EMSESP::logger().info(F("mDNS responder service started"));
}
});
#endif
EMSESP::logger().info(F("mDNS responder service started"));
}
} // namespace emsesp