Allow ANSI codes to be disabled #261

This commit is contained in:
fvanroie 2021-12-31 16:06:14 +01:00
parent cacdb34df8
commit de83fa8a9d
4 changed files with 31 additions and 4 deletions

View File

@ -37,6 +37,18 @@ void confDebugSet(const __FlashStringHelper* fstr_name)
LOG_VERBOSE(TAG_CONF, F(D_BULLET "%S set"), fstr_name);
}
bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
{
if(!setting.isNull()) {
bool val = setting.as<bool>();
if(value != val) {
confDebugSet(fstr_name);
value = val;
return true;
}
}
return false;
}
bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
{
if(!setting.isNull()) {

View File

@ -24,6 +24,7 @@ void configOutput(const JsonObject& settings, uint8_t tag = TAG_CONF);
bool configClearEeprom(void);
/* ===== Getter and Setter Functions ===== */
bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(int8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(uint8_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
@ -60,6 +61,7 @@ const char FP_GUI_CALIBRATION[] PROGMEM = "calibration";
const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl";
const char FP_GUI_POINTER[] PROGMEM = "cursor";
const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele";
const char FP_DEBUG_ANSI[] PROGMEM = "ansi";
const char FP_GPIO_CONFIG[] PROGMEM = "config";
const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json";

View File

@ -139,6 +139,9 @@ bool debugGetConfig(const JsonObject& settings)
{
bool changed = false;
if(debugAnsiCodes != settings[FPSTR(FP_DEBUG_ANSI)].as<bool>()) changed = true;
settings[FPSTR(FP_DEBUG_ANSI)] = debugAnsiCodes;
if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>()) changed = true;
settings[FPSTR(FP_CONFIG_BAUD)] = debugSerialBaud;
@ -176,6 +179,9 @@ bool debugSetConfig(const JsonObject& settings)
configOutput(settings, TAG_DEBG);
bool changed = false;
/* Ansi Code Settings */
changed |= configSet(debugAnsiCodes, settings[FPSTR(FP_DEBUG_ANSI)], F("debugAnsi"));
/* Serial Settings */
changed |= configSet(debugSerialBaud, settings[FPSTR(FP_CONFIG_BAUD)], F("debugSerialBaud"));

View File

@ -324,6 +324,7 @@ void saveConfig()
guiSetConfig(settings.as<JsonObject>());
} else if(save == String(PSTR("debug"))) {
settings[FPSTR(FP_DEBUG_ANSI)] = webServer.hasArg(PSTR("ansi"));
debugSetConfig(settings.as<JsonObject>());
} else if(save == String(PSTR("http"))) {
@ -1739,12 +1740,18 @@ static void webHandleDebugConfig()
httpMessage += F("</select></div></div>");
// Telemetry Period
httpMessage += F("<div class='row gap'><div class='col-25'><label for='tele'>Telemetry Period</label></div>");
httpMessage += F("<div class='row'><div class='col-25'><label for='tele'>Telemetry Period</label></div>");
httpMessage += F("<div class='col-75'><input type='number' id='tele' name='tele' min='0' max='65535' "
"value='");
httpMessage += settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<String>();
httpMessage += F("'></div></div>");
// Invert
httpMessage += F("<div class='row gap'><div class='col-25'><label for='ansi'></label></div>");
httpMessage += F("<div class='col-75'><input type='checkbox' id='ansi' name='ansi'");
if(settings[FPSTR(FP_DEBUG_ANSI)].as<bool>()) httpMessage += F(" checked");
httpMessage += F(">Use ANSI Colors</div></div>");
#if HASP_USE_SYSLOG > 0
// Syslog host
httpMessage += F("<div class='row'><div class='col-25'><label for='host'>Syslog Server</label></div>");