Skip to content

Commit

Permalink
Allow ANSI codes to be disabled #261
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanroie committed Dec 31, 2021
1 parent cacdb34 commit de83fa8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/hasp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions src/hasp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down
12 changes: 9 additions & 3 deletions src/log/hasp_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -176,13 +179,16 @@ bool debugSetConfig(const JsonObject& settings)
configOutput(settings, TAG_DEBG);
bool changed = false;

/* Serial Settings*/
/* 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"));

/* Teleperiod Settings*/
/* Teleperiod Settings */
changed |= configSet(dispatch_setings.teleperiod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod"));

/* Syslog Settings*/
/* Syslog Settings */
#if HASP_USE_SYSLOG > 0
if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) {
changed |= strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)]) != 0;
Expand Down
9 changes: 8 additions & 1 deletion src/sys/svc/hasp_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))) {
Expand Down Expand Up @@ -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>");
Expand Down

0 comments on commit de83fa8

Please sign in to comment.