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 21dceb50a..4086e9eee 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -287,6 +287,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/ir.cpp b/wled00/ir.cpp index 77d1266db..79ebdbe4e 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -661,7 +661,7 @@ void handleIR() { if (results.value != 0) // only print results if anything is received ( != 0 ) { - if (!pinManager.isPinAllocated(1)) //GPIO 1 - Serial TX pin + if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut) //GPIO 1 - Serial TX pin Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value); } decodeIR(results.value); diff --git a/wled00/json.cpp b/wled00/json.cpp index a67367dd0..58ce9195b 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -433,9 +433,9 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo } char tmpcol[22]; sprintf_P(tmpcol, format, (unsigned)c[0], (unsigned)c[1], (unsigned)c[2], (unsigned)c[3]); - strcat(colstr, i<2 ? strcat_P(tmpcol, PSTR(",")) : tmpcol); + strcat(colstr, i<2 ? strcat(tmpcol, ",") : tmpcol); } - strcat_P(colstr, PSTR("]")); + strcat(colstr, "]"); root["col"] = serialized(colstr); root["fx"] = seg.mode; 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 3f88bd28e..b34ed7972 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 0e531dbd7..11a3bb00c 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -19,6 +19,21 @@ enum class AdaState { TPM2_Header_CountLo, }; +uint16_t currentBaud = 1152; //default baudrate 115200 (divided by 100) + +void updateBaudRate(uint32_t rate){ + uint16_t rate100 = rate/100; + if (rate100 == currentBaud || rate100 < 96) return; + currentBaud = rate100; + + if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){ + Serial.print(F("Baud is now ")); Serial.println(rate); + } + + Serial.flush(); + Serial.begin(rate); +} + void handleSerial() { if (pinManager.isPinAllocated(3)) return; @@ -30,6 +45,8 @@ void handleSerial() static byte check = 0x00; static byte red = 0x00; static byte green = 0x00; + + uint16_t nBytes = 0; while (Serial.available() > 0) { @@ -46,6 +63,41 @@ void handleSerial() return; } else if (next == 'v') { Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION); + + } else if (next == 0xB0) {updateBaudRate( 115200); + } else if (next == 0xB1) {updateBaudRate( 230400); + } else if (next == 0xB2) {updateBaudRate( 460800); + } else if (next == 0xB3) {updateBaudRate( 500000); + } else if (next == 0xB4) {updateBaudRate( 576000); + } else if (next == 0xB5) {updateBaudRate( 921600); + } else if (next == 0xB6) {updateBaudRate(1000000); + } else if (next == 0xB7) {updateBaudRate(1500000); + + } else if (next == 'l') { //RGB(W) LED data return as JSON array. Slow, but easy to use on the other end. + if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){ + uint16_t used = strip.getLengthTotal(); + Serial.write('['); + for (uint16_t i=0; i RGB map + Serial.write(qadd8(W(c), G(c))); //G + Serial.write(qadd8(W(c), B(c))); //B + } + Serial.write(0x36); Serial.write('\n'); + } } else if (next == '{') { //JSON API bool verboseResponse = false; #ifdef WLED_USE_DYNAMIC_JSON @@ -61,7 +113,7 @@ void handleSerial() } verboseResponse = deserializeState(doc.as()); //only send response if TX pin is unused for other purposes - if (verboseResponse && !pinManager.isPinAllocated(1)) { + if (verboseResponse && (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut)) { doc.clear(); JsonObject state = doc.createNestedObject("state"); serializeState(state); 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)