fix linebreak in text

This commit is contained in:
interfisch 2023-11-25 14:42:59 +01:00
parent 2c44f2aeb4
commit ee5ea34ad2
1 changed files with 17 additions and 11 deletions

View File

@ -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);