From 32286888e5d1bb29333b67e16b39b4fc9e2e06c7 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Tue, 1 Feb 2022 18:21:30 +0100 Subject: [PATCH] PinManager, cleanup and tmp2 out --- wled00/ir.cpp | 2 +- wled00/json.cpp | 4 +-- wled00/wled_serial.cpp | 81 +++++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 40 deletions(-) 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 27a989dc5..10a106e0f 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/wled_serial.cpp b/wled00/wled_serial.cpp index eda2c6a82..8afcad239 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -19,14 +19,20 @@ enum class AdaState { TPM2_Header_CountLo, }; -void update_baud_rate(int rate){ - if (!pinManager.isPinAllocated(1)){ - Serial.print("ATTENTION! Baud rate is changing to "); Serial.println(rate); - delay(100); - Serial.end(); - Serial.begin(rate); - } +uint16_t currentBaud = 1152; //default baudrate 115200 (divided by 100) + +void updateBaudRate(int rate){ + uint16_t rate100 = rate/100; + if (rate100 == currentBaud) 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() { @@ -58,39 +64,40 @@ void handleSerial() } else if (next == 'v') { Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION); - } else if ( next == 0xB0 ){ update_baud_rate( 115200 ); - } else if ( next == 0xB1 ){ update_baud_rate( 230400 ); - } else if ( next == 0xB2 ){ update_baud_rate( 460800 ); - } else if ( next == 0xB3 ){ update_baud_rate( 500000 ); - } else if ( next == 0xB4 ){ update_baud_rate( 576000 ); - } else if ( next == 0xB5 ){ update_baud_rate( 921600 ); - } else if ( next == 0xB6 ){ update_baud_rate( 1000000 ); - } else if ( next == 0xB7 ){ update_baud_rate( 1500000 ); + } 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'){ // LED Data return in JSON blob. Slow, but easy to use on the other end. - if (!pinManager.isPinAllocated(1)){ + } 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.print("["); - 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 @@ -106,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);