From 00dbdc226727ed3c0c968b1c531856c2caeff1b0 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 1 Feb 2022 20:02:46 +0100 Subject: [PATCH] Baud rate setting --- wled00/cfg.cpp | 6 ++++++ wled00/data/settings_sync.htm | 16 +++++++++++++++- wled00/fcn_declare.h | 1 + wled00/html_settings.h | 10 ++++++++-- wled00/set.cpp | 4 ++++ wled00/wled.h | 10 ++++++---- wled00/wled_serial.cpp | 4 ++-- wled00/xml.cpp | 1 + 8 files changed, 43 insertions(+), 9 deletions(-) diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 18d5d2a77..f033909c6 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -211,6 +211,10 @@ bool deserializeConfig(JsonObject doc, bool fromFS) { rlyMde = !relay["rev"]; } + CJSON(serialBaud, hw[F("baud")]); + if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152; + updateBaudRate(serialBaud *100); + //int hw_status_pin = hw[F("status")]["pin"]; // -1 JsonObject light = doc[F("light")]; @@ -630,6 +634,8 @@ void serializeConfig() { hw_relay["pin"] = rlyPin; hw_relay["rev"] = !rlyMde; + hw[F("baud")] = serialBaud; + //JsonObject hw_status = hw.createNestedObject("status"); //hw_status["pin"] = -1; diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index 0eb0cfb63..bb5b740e7 100644 --- a/wled00/data/settings_sync.htm +++ b/wled00/data/settings_sync.htm @@ -160,7 +160,21 @@ Hue Bridge IP:

Press the pushlink button on the bridge, after that save this page!
(when first connecting)
-Hue status: Disabled in this build
+Hue status: Disabled in this build +

Serial

+Baud rate: +
+Keep at 115200 to use Improv. Some boards may not support high rates. +
diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index a139cb2f7..6ad7cb57d 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -280,6 +280,7 @@ void clearEEPROM(); //wled_serial.cpp void handleSerial(); +void updateBaudRate(uint32_t rate); //wled_server.cpp bool isIp(String str); diff --git a/wled00/html_settings.h b/wled00/html_settings.h index d29dac60a..84d859e68 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -340,8 +340,14 @@ class="s" min="0" max="255"> . .
Press the pushlink button on the bridge, after that save this page!
(when first connecting)
Hue status: Disabled in this build -
)====="; +

Serial

Baud rate:
+Keep at 115200 to use Improv. Some boards may not support high rates.
+)====="; // Autogenerated from wled00/data/settings_time.htm, do not edit!! diff --git a/wled00/set.cpp b/wled00/set.cpp index 0b74f8ab6..ff1652144 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -309,6 +309,10 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) hueStoreAllowed = true; reconnectHue(); #endif + + t = request->arg(F("BD")).toInt(); + if (t >= 96 && t <= 15000) serialBaud = t; + updateBaudRate(serialBaud *100); } //TIME diff --git a/wled00/wled.h b/wled00/wled.h index 281562c44..3f64fb491 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -370,11 +370,13 @@ WLED_GLOBAL bool hueApplyBri _INIT(true); WLED_GLOBAL bool hueApplyColor _INIT(true); #endif +WLED_GLOBAL uint16_t serialBaud _INIT(1152); // serial baud rate, multiply by 100 + // Time CONFIG -WLED_GLOBAL bool ntpEnabled _INIT(false); // get internet time. Only required if you use clock overlays or time-activated macros -WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format -WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino -WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation +WLED_GLOBAL bool ntpEnabled _INIT(false); // get internet time. Only required if you use clock overlays or time-activated macros +WLED_GLOBAL bool useAMPM _INIT(false); // 12h/24h clock format +WLED_GLOBAL byte currentTimezone _INIT(0); // Timezone ID. Refer to timezones array in wled10_ntp.ino +WLED_GLOBAL int utcOffsetSecs _INIT(0); // Seconds to offset from UTC before timzone calculation WLED_GLOBAL byte overlayDefault _INIT(0); // 0: no overlay 1: analog clock 2: single-digit clock 3: cronixie WLED_GLOBAL byte overlayMin _INIT(0), overlayMax _INIT(DEFAULT_LED_COUNT - 1); // boundaries of overlay mode diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 8afcad239..11a3bb00c 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -21,9 +21,9 @@ enum class AdaState { uint16_t currentBaud = 1152; //default baudrate 115200 (divided by 100) -void updateBaudRate(int rate){ +void updateBaudRate(uint32_t rate){ uint16_t rate100 = rate/100; - if (rate100 == currentBaud) return; + if (rate100 == currentBaud || rate100 < 96) return; currentBaud = rate100; if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){ diff --git a/wled00/xml.cpp b/wled00/xml.cpp index 21afab9b8..ed32a0538 100644 --- a/wled00/xml.cpp +++ b/wled00/xml.cpp @@ -551,6 +551,7 @@ void getSettingsJS(byte subPage, char* dest) sappends('m',SET_F("(\"sip\")[0]"),hueErrorString); #endif + sappend('v',SET_F("BD"),serialBaud); } if (subPage == 5)