mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Get and set real serial speed in config/debug
This commit is contained in:
parent
76d4aa14db
commit
b3b9661aef
@ -85,6 +85,18 @@ bool configSet(uint16_t& value, const JsonVariant& setting, const __FlashStringH
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
|
||||
{
|
||||
if(!setting.isNull()) {
|
||||
int32_t val = setting.as<int32_t>();
|
||||
if(value != val) {
|
||||
confDebugSet(fstr_name);
|
||||
value = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name)
|
||||
{
|
||||
lv_color32_t c32;
|
||||
|
@ -28,6 +28,7 @@ bool configSet(bool& value, const JsonVariant& setting, const __FlashStringHelpe
|
||||
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);
|
||||
bool configSet(int32_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
|
||||
bool configSet(lv_color_t& value, const JsonVariant& setting, const __FlashStringHelper* fstr_name);
|
||||
void configMaskPasswords(JsonDocument& settings);
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#define debug_print(io, ...) io->printf(__VA_ARGS__)
|
||||
#define debug_newline(io) io->println()
|
||||
|
||||
// bool debugSerialStarted = false;
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -22,7 +21,6 @@
|
||||
#define debug_print(io, ...) fprintf(stdout, __VA_ARGS__)
|
||||
#define debug_newline(io) fprintf(stdout, "\n")
|
||||
|
||||
// bool debugSerialStarted = true;
|
||||
#endif
|
||||
|
||||
bool debugAnsiCodes = true;
|
||||
@ -125,24 +123,10 @@ void debugStart(void)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
if(debugSerialStarted) {
|
||||
|
||||
// Serial.println();
|
||||
// Serial.println(debugHaspHeader());
|
||||
// debug_flush();
|
||||
}
|
||||
|
||||
// prepare syslog configuration here (can be anywhere before first call of
|
||||
// log/logf method)
|
||||
*/
|
||||
}
|
||||
|
||||
void debugStop()
|
||||
{
|
||||
// if(debugSerialStarted) debug_flush();
|
||||
}
|
||||
{}
|
||||
|
||||
/* ===== Special Event Processors ===== */
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Enabled"
|
||||
#define D_SETTING_DISABLED "Disabled"
|
||||
#define D_SETTING_DEFAULT "Default"
|
||||
|
||||
#define D_NETWORK_IP_ADDRESS_RECEIVED "Received IP address %s"
|
||||
#define D_NETWORK_ONLINE "online"
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Habilitado" // New
|
||||
#define D_SETTING_DISABLED "Deshabilitado" // New
|
||||
#define D_SETTING_DEFAULT "Default" // New
|
||||
|
||||
#define D_NETWORK_IP_ADDRESS_RECEIVED "Se recibió la dirección IP: %s"
|
||||
#define D_NETWORK_ONLINE "en linea"
|
||||
@ -146,7 +147,9 @@
|
||||
#define D_HTTP_MAIN_MENU "Menú principal"
|
||||
#define D_HTTP_REBOOT "Reiniciar"
|
||||
#define D_HTTP_CONFIGURATION "Configuración"
|
||||
#define D_HTTP_CONFIG_CHANGED "La configuración ha cambiado, haga clic en <a href='/reboot'>Reiniciar</a> para guardar los cambios en la memoria flash."
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"La configuración ha cambiado, haga clic en <a href='/reboot'>Reiniciar</a> para guardar los cambios en la " \
|
||||
"memoria flash."
|
||||
#define D_HTTP_SENDING_PAGE "Se envió pagina %S a %s"
|
||||
#define D_HTTP_FOOTER "por Francis Van Roie"
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Activé"
|
||||
#define D_SETTING_DISABLED "Désactivé"
|
||||
#define D_SETTING_DEFAULT "Défaut"
|
||||
|
||||
#define D_NETWORK_IP_ADDRESS_RECEIVED "Adresse IP reçue %s"
|
||||
#define D_NETWORK_ONLINE "en ligne"
|
||||
@ -146,7 +147,9 @@
|
||||
#define D_HTTP_MAIN_MENU "Menu principal"
|
||||
#define D_HTTP_REBOOT "Redémarrer"
|
||||
#define D_HTTP_CONFIGURATION "Configuration"
|
||||
#define D_HTTP_CONFIG_CHANGED "La configuration a changé, cliquez sur <a href='/reboot'>Redémarrer</a> pour enregistrer les modifications dans le flash."
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"La configuration a changé, cliquez sur <a href='/reboot'>Redémarrer</a> pour enregistrer les modifications dans " \
|
||||
"le flash."
|
||||
#define D_HTTP_SENDING_PAGE "La page %S envoyée à %s"
|
||||
#define D_HTTP_FOOTER "par Francis Van Roie"
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#define D_FILE_SIZE_MEGABYTES "MiB"
|
||||
#define D_FILE_SIZE_GIGABYTES "GiB"
|
||||
#define D_FILE_SIZE_DIVIDER 1024
|
||||
#define D_DECIMAL_POINT ","
|
||||
#define D_DECIMAL_POINT ","
|
||||
|
||||
#define D_SERVICE_STARTING "Indítás..."
|
||||
#define D_SERVICE_STARTED "Elindítva"
|
||||
@ -40,6 +40,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Engedélyezve"
|
||||
#define D_SETTING_DISABLED "Letiltva"
|
||||
#define D_SETTING_DEFAULT "Alapértelmezett"
|
||||
|
||||
#define D_NETWORK_IP_ADDRESS_RECEIVED "Beállított IP-cím: %s"
|
||||
#define D_NETWORK_ONLINE "online"
|
||||
@ -146,7 +147,8 @@
|
||||
#define D_HTTP_MAIN_MENU "Főmenü"
|
||||
#define D_HTTP_REBOOT "Újraindítás"
|
||||
#define D_HTTP_CONFIGURATION "Beállítások"
|
||||
#define D_HTTP_CONFIG_CHANGED "A konfiguráció meg lett változtatva. <a href='/reboot'>Indítson újra</a> a beállítások mentéséhez!"
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"A konfiguráció meg lett változtatva. <a href='/reboot'>Indítson újra</a> a beállítások mentéséhez!"
|
||||
#define D_HTTP_SENDING_PAGE "%S oldal küldése %s-re"
|
||||
#define D_HTTP_FOOTER "készítette: Francis Van Roie"
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Ingeschakeld"
|
||||
#define D_SETTING_DISABLED "Uitgeschakeld"
|
||||
#define D_SETTING_DEFAULT "Standaard"
|
||||
|
||||
#define D_SERVICE_STARTING "Starten..."
|
||||
#define D_SERVICE_STARTED "Gestart"
|
||||
@ -146,7 +147,8 @@
|
||||
#define D_HTTP_MAIN_MENU "Hoofdmenu"
|
||||
#define D_HTTP_REBOOT "Herstarten"
|
||||
#define D_HTTP_CONFIGURATION "Configuratie"
|
||||
#define D_HTTP_CONFIG_CHANGED "De configuratie is gewijzigd, klik op <a href='/reboot'>Herstart</a> om de wijzigingen naar flash te schrijven."
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"De configuratie is gewijzigd, klik op <a href='/reboot'>Herstart</a> om de wijzigingen naar flash te schrijven."
|
||||
#define D_HTTP_SENDING_PAGE "Pagina %S verstuurd naar %s"
|
||||
#define D_HTTP_FOOTER "door Francis Van Roie"
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Ativado"
|
||||
#define D_SETTING_DISABLED "Desativado"
|
||||
#define D_SETTING_DEFAULT "Default" // New
|
||||
|
||||
#define D_NETWORK_IP_ADDRESS_RECEIVED "Foi atribuído endereço IP: %s"
|
||||
#define D_NETWORK_ONLINE "Online"
|
||||
@ -147,7 +148,8 @@
|
||||
#define D_HTTP_MAIN_MENU "Menu Principal"
|
||||
#define D_HTTP_REBOOT "Reiniciar"
|
||||
#define D_HTTP_CONFIGURATION "Configuração"
|
||||
#define D_HTTP_CONFIG_CHANGED "Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash." // New
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"Configuration has changed, please click <a href='/reboot'>Restart</a> to save changes to flash." // New
|
||||
#define D_HTTP_SENDING_PAGE "Foi enviado página %S a %s"
|
||||
#define D_HTTP_FOOTER "por Francis Van Roie"
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#define D_SETTING_ENABLED "Activ"
|
||||
#define D_SETTING_DISABLED "Inactiv"
|
||||
#define D_SETTING_DEFAULT "Implicit"
|
||||
|
||||
#define D_SERVICE_STARTING "Pornire..."
|
||||
#define D_SERVICE_STARTED "Pornit"
|
||||
@ -146,7 +147,8 @@
|
||||
#define D_HTTP_MAIN_MENU "Meniu principal"
|
||||
#define D_HTTP_REBOOT "Repornire"
|
||||
#define D_HTTP_CONFIGURATION "Setări"
|
||||
#define D_HTTP_CONFIG_CHANGED "Configurația s-a modificat, pentru a se salva, este necesară <a href='/reboot'>repornirea</a> dispozitivului."
|
||||
#define D_HTTP_CONFIG_CHANGED \
|
||||
"Configurația s-a modificat, pentru a se salva, este necesară <a href='/reboot'>repornirea</a> dispozitivului."
|
||||
#define D_HTTP_SENDING_PAGE "Pagina %S trimisă la %s"
|
||||
#define D_HTTP_FOOTER "de Francis Van Roie"
|
||||
|
||||
|
@ -83,8 +83,7 @@ WiFiUDP* syslogClient = NULL;
|
||||
// uint16_t serialInputIndex = 0; // Empty buffer
|
||||
// char serialInputBuffer[220] = "";
|
||||
// uint16_t historyIndex = sizeof(serialInputBuffer) - 1; // Empty buffer
|
||||
uint16_t debugSerialBaud = SERIAL_SPEED / 10; // Multiplied by 10
|
||||
// extern bool debugSerialStarted;
|
||||
int32_t debugSerialBaud = SERIAL_SPEED;
|
||||
extern bool debugAnsiCodes;
|
||||
|
||||
extern dispatch_conf_t dispatch_setings;
|
||||
@ -142,7 +141,7 @@ bool debugGetConfig(const JsonObject& settings)
|
||||
if(debugAnsiCodes != settings[FPSTR(FP_DEBUG_ANSI)]) changed = true;
|
||||
settings[FPSTR(FP_DEBUG_ANSI)] = (uint8_t)debugAnsiCodes;
|
||||
|
||||
if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>()) changed = true;
|
||||
if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)]) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_BAUD)] = debugSerialBaud;
|
||||
|
||||
if(dispatch_setings.teleperiod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true;
|
||||
@ -179,11 +178,23 @@ 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"));
|
||||
if(changed) { // baudrate was changed
|
||||
switch(debugSerialBaud) {
|
||||
case 960:
|
||||
case 1920:
|
||||
case 3840:
|
||||
case 5760:
|
||||
case 7488:
|
||||
case 11520:
|
||||
debugSerialBaud *= 10; // multiply old values
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ansi Code Settings */
|
||||
changed |= configSet(debugAnsiCodes, settings[FPSTR(FP_DEBUG_ANSI)], F("debugAnsi"));
|
||||
|
||||
/* Teleperiod Settings */
|
||||
changed |= configSet(dispatch_setings.teleperiod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
|
||||
@ -346,38 +357,31 @@ void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput)
|
||||
// Start Serial Port at correct
|
||||
void debugStartSerial()
|
||||
{
|
||||
uint32_t baudrate = 0;
|
||||
if(debugSerialBaud == 0) {
|
||||
baudrate = SERIAL_SPEED;
|
||||
} else {
|
||||
baudrate = debugSerialBaud * 10;
|
||||
if(debugSerialBaud < 0) {
|
||||
LOG_WARNING(TAG_DEBG, F(D_SERVICE_DISABLED " (%u Bps)"), debugSerialBaud);
|
||||
// return;
|
||||
}
|
||||
|
||||
if(baudrate >= 9600u) { /* the baudrates are stored divided by 10 */
|
||||
uint32_t baudrate = debugSerialBaud;
|
||||
if(baudrate < 9600) baudrate = SERIAL_SPEED;
|
||||
|
||||
#if defined(STM32F4xx) || defined(STM32F7xx)
|
||||
#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
|
||||
Serial.setRx(PA3); // User Serial2
|
||||
Serial.setTx(PA2);
|
||||
#ifndef STM32_SERIAL1 // Define what Serial port to use for log output
|
||||
Serial.setRx(PA3); // User Serial2
|
||||
Serial.setTx(PA2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Serial.begin(baudrate); /* prepare for possible serial debug */
|
||||
delay(10);
|
||||
Log.registerOutput(0, &Serial, HASP_LOG_LEVEL, true); // LOG_LEVEL_VERBOSE
|
||||
Serial.begin(baudrate); /* prepare for possible serial debug */
|
||||
delay(10);
|
||||
Log.registerOutput(0, &Serial, HASP_LOG_LEVEL, true); // LOG_LEVEL_VERBOSE
|
||||
|
||||
// debugSerialStarted = true;
|
||||
Serial.println();
|
||||
debugPrintHaspHeader(&Serial);
|
||||
Serial.flush();
|
||||
|
||||
Serial.println();
|
||||
debugPrintHaspHeader(&Serial);
|
||||
Serial.flush();
|
||||
|
||||
LOG_INFO(TAG_DEBG, F(D_SERVICE_STARTED " @ %u Bps"), baudrate);
|
||||
LOG_INFO(TAG_DEBG, F("Environment: " PIOENV));
|
||||
|
||||
} else {
|
||||
LOG_WARNING(TAG_DEBG, F(D_SERVICE_DISABLED " (%u Bps)"), baudrate);
|
||||
}
|
||||
LOG_INFO(TAG_DEBG, F(D_SERVICE_STARTED " @ %u bps"), debugSerialBaud);
|
||||
LOG_INFO(TAG_DEBG, F(D_INFO_ENVIRONMENT ": " PIOENV));
|
||||
}
|
||||
|
||||
// Do NOT call Log function before debugSetup is called
|
||||
@ -391,7 +395,9 @@ void debugSetup(JsonObject settings)
|
||||
Log.unregisterOutput(3);
|
||||
|
||||
#if HASP_USE_CONFIG > 0
|
||||
debugSerialBaud = settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>();
|
||||
if(!settings[FPSTR(FP_CONFIG_BAUD)].isNull()) {
|
||||
debugSerialBaud = settings[FPSTR(FP_CONFIG_BAUD)].as<int32_t>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -82,11 +82,10 @@ extern const uint8_t SCRIPT_JS_GZ_END[] asm("_binary_data_script_js_gz_end");
|
||||
|
||||
HTTPUpload* upload;
|
||||
|
||||
static const char HTTP_MENU_BUTTON[] PROGMEM =
|
||||
"<p><form method='GET' action='%s'><button type='submit'>%s</button></form></p>";
|
||||
// const char HTTP_MENU_BUTTON[] PROGMEM =
|
||||
// "<p><form method='GET' action='%s'><button type='submit'>%s</button></form></p>";
|
||||
|
||||
const char MAIN_MENU_BUTTON[] PROGMEM = "<a href='/'>" D_HTTP_MAIN_MENU "</a>";
|
||||
const char MIT_LICENSE[] PROGMEM = "</br>MIT License</p>";
|
||||
|
||||
const char HTTP_DOCTYPE[] PROGMEM = "<!DOCTYPE html><html lang=\"en\"><head><meta charset='utf-8'><meta "
|
||||
"name=\"viewport\" content=\"width=device-width,initial-scale=1\"/>";
|
||||
@ -598,9 +597,6 @@ static void webHandleAbout()
|
||||
if(!httpIsAuthenticated(F("about"))) return;
|
||||
|
||||
{ // Send Content
|
||||
String mitLicense((char*)0);
|
||||
mitLicense = FPSTR(MIT_LICENSE);
|
||||
|
||||
String httpMessage((char*)0);
|
||||
httpMessage.reserve(HTTP_PAGE_SIZE);
|
||||
|
||||
@ -1769,13 +1765,17 @@ static void webHandleDebugConfig()
|
||||
uint16_t baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>();
|
||||
httpMessage += F("<div class='row'><div class='col-25'><label for='baud'>Serial Port</label></div>");
|
||||
httpMessage += F("<div class='col-75'><select id='baud' name='baud'>");
|
||||
httpMessage += getOption(1, F(D_SETTING_DISABLED), baudrate); // Don't use 0 here which is default 115200
|
||||
httpMessage += getOption(960, F("9600"), baudrate);
|
||||
httpMessage += getOption(1920, F("19200"), baudrate);
|
||||
httpMessage += getOption(3840, F("38400"), baudrate);
|
||||
httpMessage += getOption(5760, F("57600"), baudrate);
|
||||
httpMessage += getOption(7488, F("74880"), baudrate);
|
||||
httpMessage += getOption(11520, F("115200"), baudrate);
|
||||
httpMessage += getOption(-1, F(D_SETTING_DISABLED), baudrate); // Don't use 0 here which is default 115200
|
||||
httpMessage += getOption(0, F(D_SETTING_DEFAULT), baudrate); // Don't use 0 here which is default 115200
|
||||
httpMessage += getOption(9600, F("9600"), baudrate);
|
||||
httpMessage += getOption(19200, F("19200"), baudrate);
|
||||
httpMessage += getOption(38400, F("38400"), baudrate);
|
||||
httpMessage += getOption(57600, F("57600"), baudrate);
|
||||
httpMessage += getOption(74880, F("74880"), baudrate);
|
||||
httpMessage += getOption(115200, F("115200"), baudrate);
|
||||
httpMessage += getOption(230400, F("230400"), baudrate);
|
||||
httpMessage += getOption(460800, F("460800"), baudrate);
|
||||
httpMessage += getOption(921600, F("921600"), baudrate);
|
||||
httpMessage += F("</select></div></div>");
|
||||
|
||||
// Telemetry Period
|
||||
|
@ -96,8 +96,8 @@ AsyncWebSocket ws("/ws"); // access at ws://[esp ip]/ws
|
||||
|
||||
// HTTPUpload* upload;
|
||||
|
||||
static const char HTTP_MENU_BUTTON[] PROGMEM =
|
||||
"<p><form method='GET' action='%s'><button type='submit'>%s</button></form></p>";
|
||||
// static const char HTTP_MENU_BUTTON[] PROGMEM =
|
||||
// "<p><form method='GET' action='%s'><button type='submit'>%s</button></form></p>";
|
||||
|
||||
const char MAIN_MENU_BUTTON[] PROGMEM =
|
||||
"</p><p><form method='GET' action='/'><button type='submit'>" D_HTTP_MAIN_MENU "</button></form>";
|
||||
|
Loading…
x
Reference in New Issue
Block a user