diff --git a/flipcontrol_esp32/src/main.cpp b/flipcontrol_esp32/src/main.cpp index 86f6899..1baa0e7 100644 --- a/flipcontrol_esp32/src/main.cpp +++ b/flipcontrol_esp32/src/main.cpp @@ -335,22 +335,28 @@ bool controlHandler(const HomieRange& range, const String& value) { bool textHandler(const HomieRange& range, const String& value) { Serial.print("Text payload="); Serial.println(value); + String row1; + String row2; + uint8_t linebreakindex=value.indexOf("\n"); //search for "\n" in string. 255 if not found Serial.print("Linebreakindex="); Serial.println(linebreakindex); + if (linebreakindex!=255) { //found linebreak + row1=value.substring(0,linebreakindex); + row2=value.substring(linebreakindex+1); + }else{ - String row1=value.substring(0,flip.getW()/6); - String row2=value.substring(flip.getW()/6); - row2.trim(); //remove leading and trailing whitespaces - String overflow=row2.substring(flip.getW()/6); //save text that did not fit - row2=row2.substring(0,flip.getW()/6); + row1=value.substring(0,flip.getW()/6); + row2=value.substring(flip.getW()/6); + row2.trim(); //remove leading and trailing whitespaces + String overflow=row2.substring(flip.getW()/6); //save text that did not fit + row2=row2.substring(0,flip.getW()/6); - - - - if (overflow.length()>0) { - error="Text overflow:"+overflow; - Serial.println("Text overflow"); + if (overflow.length()>0) { + error="Text overflow:"+overflow; + Serial.println("Text overflow"); + } } + Serial.print("Row1="); Serial.println(row1); Serial.print("Row2="); Serial.println(row2);