PinManager, cleanup and tmp2 out

This commit is contained in:
cschwinne 2022-02-01 18:21:30 +01:00
parent 22fbb0e35b
commit 32286888e5
3 changed files with 47 additions and 40 deletions

View File

@ -661,7 +661,7 @@ void handleIR()
{ {
if (results.value != 0) // only print results if anything is received ( != 0 ) 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); Serial.printf_P(PSTR("IR recv: 0x%lX\n"), (unsigned long)results.value);
} }
decodeIR(results.value); decodeIR(results.value);

View File

@ -433,9 +433,9 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
} }
char tmpcol[22]; char tmpcol[22];
sprintf_P(tmpcol, format, (unsigned)c[0], (unsigned)c[1], (unsigned)c[2], (unsigned)c[3]); 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["col"] = serialized(colstr);
root["fx"] = seg.mode; root["fx"] = seg.mode;

View File

@ -19,14 +19,20 @@ enum class AdaState {
TPM2_Header_CountLo, TPM2_Header_CountLo,
}; };
void update_baud_rate(int rate){ uint16_t currentBaud = 1152; //default baudrate 115200 (divided by 100)
if (!pinManager.isPinAllocated(1)){
Serial.print("ATTENTION! Baud rate is changing to "); Serial.println(rate); void updateBaudRate(int rate){
delay(100); uint16_t rate100 = rate/100;
Serial.end(); if (rate100 == currentBaud) return;
Serial.begin(rate); 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() void handleSerial()
{ {
@ -58,39 +64,40 @@ void handleSerial()
} else if (next == 'v') { } else if (next == 'v') {
Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION); Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION);
} else if ( next == 0xB0 ){ update_baud_rate( 115200 ); } else if (next == 0xB0) {updateBaudRate( 115200);
} else if ( next == 0xB1 ){ update_baud_rate( 230400 ); } else if (next == 0xB1) {updateBaudRate( 230400);
} else if ( next == 0xB2 ){ update_baud_rate( 460800 ); } else if (next == 0xB2) {updateBaudRate( 460800);
} else if ( next == 0xB3 ){ update_baud_rate( 500000 ); } else if (next == 0xB3) {updateBaudRate( 500000);
} else if ( next == 0xB4 ){ update_baud_rate( 576000 ); } else if (next == 0xB4) {updateBaudRate( 576000);
} else if ( next == 0xB5 ){ update_baud_rate( 921600 ); } else if (next == 0xB5) {updateBaudRate( 921600);
} else if ( next == 0xB6 ){ update_baud_rate( 1000000 ); } else if (next == 0xB6) {updateBaudRate(1000000);
} else if ( next == 0xB7 ){ update_baud_rate( 1500000 ); } 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. } 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)){ if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut){
uint16_t used = strip.getLengthTotal(); uint16_t used = strip.getLengthTotal();
Serial.print("["); Serial.write('[');
for (uint16_t i=0; i<used; i+=1){ for (uint16_t i=0; i<used; i+=1) {
Serial.print(strip.getPixelColor(i)); Serial.print(strip.getPixelColor(i));
if (i != used-1) {Serial.print(",");}} if (i != used-1) Serial.write(',');
Serial.println("]");} }
Serial.println("]");
} else if (next == 'L'){ // LED Data returned as bytes. Faster, and slightly less easy to use on the other end. }
if (!pinManager.isPinAllocated(1)){ } else if (next == 'L') { //RGB LED data returned as bytes in tpm2 format. Faster, and slightly less easy to use on the other end.
// first byte sent back denotes number of color bytes. 0x00 RGB, 0x01 RGBW, 0x02 ??? etc if (!pinManager.isPinAllocated(1) || pinManager.getPinOwner(1) == PinOwner::DebugOut) {
if (strip.isRgbw){ // alternate idea, merge the white channel down into RGB like recent websocket update. or perhaps 0x02 should be merged white chanel Serial.write(0xC9); Serial.write(0xDA);
Serial.write(0x01);
nBytes = 4;}
else{
Serial.write(0x00);
nBytes = 3;}
uint16_t used = strip.getLengthTotal(); uint16_t used = strip.getLengthTotal();
for (uint16_t i=0; i<used; i+=1){ uint16_t len = used*3;
uint32_t thing = strip.getPixelColor(i); Serial.write((len << 8) & 0xFF);
Serial.write((byte *) &thing, nBytes);} Serial.write( len & 0xFF);
Serial.println();} for (uint16_t i=0; i < used; i++) {
uint32_t c = strip.getPixelColor(i);
Serial.write(qadd8(W(c), R(c))); //R, add white channel to RGB channels as a simple RGBW -> 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 } else if (next == '{') { //JSON API
bool verboseResponse = false; bool verboseResponse = false;
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
@ -106,7 +113,7 @@ void handleSerial()
} }
verboseResponse = deserializeState(doc.as<JsonObject>()); verboseResponse = deserializeState(doc.as<JsonObject>());
//only send response if TX pin is unused for other purposes //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(); doc.clear();
JsonObject state = doc.createNestedObject("state"); JsonObject state = doc.createNestedObject("state");
serializeState(state); serializeState(state);