From 22fbb0e35b4d65b624e7066903d6025995bbae5b Mon Sep 17 00:00:00 2001 From: ChuckMash <86080247+ChuckMash@users.noreply.github.com> Date: Fri, 28 Jan 2022 23:35:40 -0800 Subject: [PATCH] Update wled_serial.cpp Adds serial functionality Can now change baud rate during runtime to be faster Retrieve LED strip data as JSON blob Retrieve LED strip data as BYTES (fast!) --- wled00/wled_serial.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/wled00/wled_serial.cpp b/wled00/wled_serial.cpp index 0e531dbd7..eda2c6a82 100644 --- a/wled00/wled_serial.cpp +++ b/wled00/wled_serial.cpp @@ -19,6 +19,15 @@ 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); + } + } + void handleSerial() { if (pinManager.isPinAllocated(3)) return; @@ -30,6 +39,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 +57,40 @@ void handleSerial() return; } 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 == 'l'){ // LED Data return in JSON blob. Slow, but easy to use on the other end. + if (!pinManager.isPinAllocated(1)){ + uint16_t used = strip.getLengthTotal(); + Serial.print("["); + for (uint16_t i=0; i