From e2225f53e47330ad2374751c8e6c2ed66f92fbd8 Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 12:21:36 -0400 Subject: [PATCH 1/7] Patch - \r handling --- .../i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h | 4 ++++ .../i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index 8e3ce8265..01dc3ccba 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -120,6 +120,10 @@ class WipperSnapper_I2C_Driver_Out_CharLcd message[cur_idx + 1] == 'n') { cur_idx += 2; // Skip the '\n' character in the buffer break; // and move to the next row + } else if (c == '\\' && cur_idx + 1 < message_length && + message[cur_idx + 1] == 'r') { + cur_idx += 2; // Skip the '\r' character in the buffer + continue; // and continue writing on the same row } else if (c == 194 && cur_idx + 1 < message_length && message[cur_idx + 1] == 176) { cur_idx += 2; // Skip the degree symbol sequence in the buffer diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h index c3bd93870..b9319d824 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h @@ -127,6 +127,11 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306 // Skip to the next possible line y_idx += line_height; _display->setCursor(0, y_idx); + } else if (message[i] == '\\' && i + 1 < msg_size && + message[i + 1] == 'r') { + // skip the \r character, continue to the next character + i++; + continue; } else if (message[i] == 0xC2 && message[i + 1] == 0xB0) { _display->write(char(248)); _display->display(); From cb65ab35bb4243a7a3c331292bcc775346072cb1 Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 13:37:49 -0400 Subject: [PATCH 2/7] Patch #2 --- platformio.ini | 1 + .../WipperSnapper_I2C_Driver_Out_CharLcd.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index e1262d953..bddb00c06 100644 --- a/platformio.ini +++ b/platformio.ini @@ -374,6 +374,7 @@ extra_scripts = pre:rename_usb_config.py extends = common:esp32 board = adafruit_qtpy_esp32s3_n4r2 build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2 -DBOARD_HAS_PSRAM +board_build.partitions = tinyuf2-partitions-4MB-noota.csv extra_scripts = pre:rename_usb_config.py [env:adafruit_qtpy_esp32s3_with_psram_debug] diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index 01dc3ccba..603f2a1f2 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -116,14 +116,19 @@ class WipperSnapper_I2C_Driver_Out_CharLcd for (int cur_col = 0; cur_col < _cols && cur_idx < message_length; cur_col++) { char c = message[cur_idx]; + WS_DEBUG_PRINTLN("CharLCD: Writing char: "); + WS_DEBUG_PRINT(c); + WS_DEBUG_PRINT(" | hex:0x"); + // print hex + WS_DEBUG_PRINTHEX(c); + WS_DEBUG_PRINTLN(" "); if (c == '\\' && cur_idx + 1 < message_length && - message[cur_idx + 1] == 'n') { - cur_idx += 2; // Skip the '\n' character in the buffer + (message[cur_idx + 1] == 'n' || message[cur_idx + 1] == 'r')) { + cur_idx += 2; // Skip the '\n' or '\r' character in the buffer + break; // and move to the next row + } else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) { + cur_idx += 1; // Skip the UTF-8 sequence for \n or \r break; // and move to the next row - } else if (c == '\\' && cur_idx + 1 < message_length && - message[cur_idx + 1] == 'r') { - cur_idx += 2; // Skip the '\r' character in the buffer - continue; // and continue writing on the same row } else if (c == 194 && cur_idx + 1 < message_length && message[cur_idx + 1] == 176) { cur_idx += 2; // Skip the degree symbol sequence in the buffer From e5a3acfb39f810ded099f1bfa33aca77646e7a9b Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 13:52:21 -0400 Subject: [PATCH 3/7] \r\n sequence escape --- .../WipperSnapper_I2C_Driver_Out_CharLcd.h | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index 603f2a1f2..5ce057dac 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -124,11 +124,23 @@ class WipperSnapper_I2C_Driver_Out_CharLcd WS_DEBUG_PRINTLN(" "); if (c == '\\' && cur_idx + 1 < message_length && (message[cur_idx + 1] == 'n' || message[cur_idx + 1] == 'r')) { - cur_idx += 2; // Skip the '\n' or '\r' character in the buffer - break; // and move to the next row + WS_DEBUG_PRINTLN("CharLCD: Detected newline sequence"); + // Handle \r\n sequence as a single newline + if (message[cur_idx + 1] == 'r' && cur_idx + 3 < message_length && + message[cur_idx + 2] == '\\' && message[cur_idx + 3] == 'n') { + cur_idx += 4; // Skip \r\n and don't move the cursor two rows + } else { + cur_idx += 2; // Skip either the \n or \r + } + break; // and move to the next row } else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) { - cur_idx += 1; // Skip the UTF-8 sequence for \n or \r - break; // and move to the next row + if (c == 0x0A && cur_idx + 1 < message_length && + message[cur_idx + 1] == 0x0D) { + cur_idx += 2; // Skip both LF and CR characters + } else { + cur_idx += 1; // Skip single newline character + } + break; // and move to the next row } else if (c == 194 && cur_idx + 1 < message_length && message[cur_idx + 1] == 176) { cur_idx += 2; // Skip the degree symbol sequence in the buffer From 6333e8e8d2ac039dec8ab25ac1d06d6a3202bc26 Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 16:37:00 -0400 Subject: [PATCH 4/7] Fix \r display --- .../WipperSnapper_I2C_Driver_Out_CharLcd.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index 5ce057dac..edf00e507 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -130,9 +130,16 @@ class WipperSnapper_I2C_Driver_Out_CharLcd message[cur_idx + 2] == '\\' && message[cur_idx + 3] == 'n') { cur_idx += 4; // Skip \r\n and don't move the cursor two rows } else { - cur_idx += 2; // Skip either the \n or \r + cur_idx += 2; // Skip the \n or \r + WS_DEBUG_PRINTLN("CharLCD: Detected single character"); + if (c == '\\' && message[cur_idx + 1] == 'n') { + WS_DEBUG_PRINTLN("CharLCD: Detected newline character"); + _lcd->write('\\'); + _lcd->write('n'); + } else { + break; + } } - break; // and move to the next row } else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) { if (c == 0x0A && cur_idx + 1 < message_length && message[cur_idx + 1] == 0x0D) { @@ -141,6 +148,13 @@ class WipperSnapper_I2C_Driver_Out_CharLcd cur_idx += 1; // Skip single newline character } break; // and move to the next row + } else if (c == 0x0D || + (c == 'r' && c == '\\') && cur_idx + 1 < message_length) { + // write \r to the lcd + WS_DEBUG_PRINTLN("CharLCD: Detected carriage return sequence"); + _lcd->write('\\'); + _lcd->write('r'); + cur_idx += 2; } else if (c == 194 && cur_idx + 1 < message_length && message[cur_idx + 1] == 176) { cur_idx += 2; // Skip the degree symbol sequence in the buffer From ed75830d681e33f5b9a3bdc0b43050b5f1622192 Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 16:44:20 -0400 Subject: [PATCH 5/7] Show non japanese set for / --- .../WipperSnapper_I2C_Driver_Out_CharLcd.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index edf00e507..4238cab49 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -116,28 +116,20 @@ class WipperSnapper_I2C_Driver_Out_CharLcd for (int cur_col = 0; cur_col < _cols && cur_idx < message_length; cur_col++) { char c = message[cur_idx]; - WS_DEBUG_PRINTLN("CharLCD: Writing char: "); - WS_DEBUG_PRINT(c); - WS_DEBUG_PRINT(" | hex:0x"); - // print hex - WS_DEBUG_PRINTHEX(c); - WS_DEBUG_PRINTLN(" "); if (c == '\\' && cur_idx + 1 < message_length && (message[cur_idx + 1] == 'n' || message[cur_idx + 1] == 'r')) { - WS_DEBUG_PRINTLN("CharLCD: Detected newline sequence"); // Handle \r\n sequence as a single newline if (message[cur_idx + 1] == 'r' && cur_idx + 3 < message_length && message[cur_idx + 2] == '\\' && message[cur_idx + 3] == 'n') { cur_idx += 4; // Skip \r\n and don't move the cursor two rows + break; // Move to the next row } else { cur_idx += 2; // Skip the \n or \r - WS_DEBUG_PRINTLN("CharLCD: Detected single character"); - if (c == '\\' && message[cur_idx + 1] == 'n') { - WS_DEBUG_PRINTLN("CharLCD: Detected newline character"); - _lcd->write('\\'); - _lcd->write('n'); + if (c == '\\' && message[cur_idx + 1] == 'r') { + _lcd->write(0x2F); + _lcd->write('r'); } else { - break; + break; // Move to the next row } } } else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) { @@ -151,7 +143,6 @@ class WipperSnapper_I2C_Driver_Out_CharLcd } else if (c == 0x0D || (c == 'r' && c == '\\') && cur_idx + 1 < message_length) { // write \r to the lcd - WS_DEBUG_PRINTLN("CharLCD: Detected carriage return sequence"); _lcd->write('\\'); _lcd->write('r'); cur_idx += 2; From 159cf772b5947fb5e5c460d910a98d33cc2fa8d8 Mon Sep 17 00:00:00 2001 From: brentru Date: Tue, 17 Jun 2025 17:06:14 -0400 Subject: [PATCH 6/7] Fix again \r not showing --- .../WipperSnapper_I2C_Driver_Out_CharLcd.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h index 4238cab49..e00572c81 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h @@ -122,14 +122,15 @@ class WipperSnapper_I2C_Driver_Out_CharLcd if (message[cur_idx + 1] == 'r' && cur_idx + 3 < message_length && message[cur_idx + 2] == '\\' && message[cur_idx + 3] == 'n') { cur_idx += 4; // Skip \r\n and don't move the cursor two rows - break; // Move to the next row + break; // Move to the next row } else { - cur_idx += 2; // Skip the \n or \r - if (c == '\\' && message[cur_idx + 1] == 'r') { - _lcd->write(0x2F); + if (message[cur_idx + 1] == 'r') { + _lcd->write('\\'); _lcd->write('r'); + cur_idx += 2; // Skip the \r } else { - break; // Move to the next row + cur_idx += 2; // Skip the \n + break; // Move to the next row } } } else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) { @@ -140,12 +141,6 @@ class WipperSnapper_I2C_Driver_Out_CharLcd cur_idx += 1; // Skip single newline character } break; // and move to the next row - } else if (c == 0x0D || - (c == 'r' && c == '\\') && cur_idx + 1 < message_length) { - // write \r to the lcd - _lcd->write('\\'); - _lcd->write('r'); - cur_idx += 2; } else if (c == 194 && cur_idx + 1 < message_length && message[cur_idx + 1] == 176) { cur_idx += 2; // Skip the degree symbol sequence in the buffer From b9a33a73973dba7bc13a5db0568ac246dcb5526e Mon Sep 17 00:00:00 2001 From: brentru Date: Wed, 18 Jun 2025 12:31:15 -0400 Subject: [PATCH 7/7] Fix for SSD1306 --- .../WipperSnapper_I2C_Driver_Out_Ssd1306.h | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h index b9319d824..40bfd95bb 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_Ssd1306.h @@ -121,17 +121,21 @@ class WipperSnapper_I2C_Driver_Out_Ssd1306 uint16_t c_idx = 0; size_t msg_size = strlen(message); for (size_t i = 0; i < msg_size && c_idx < msg_size; i++) { - if (message[i] == '\\' && i + 1 < msg_size && message[i + 1] == 'n') { - // detected a newline char sequence (\n) - i++; - // Skip to the next possible line - y_idx += line_height; - _display->setCursor(0, y_idx); - } else if (message[i] == '\\' && i + 1 < msg_size && - message[i + 1] == 'r') { - // skip the \r character, continue to the next character - i++; - continue; + if (message[i] == '\\' && i + 1 < msg_size && + (message[i + 1] == 'n' || message[i + 1] == 'r')) { + // Handle \r\n sequence as a single newline + if (message[i + 1] == 'r' && i + 3 < msg_size && + message[i + 2] == '\\' && message[i + 3] == 'n') { + // Skip to the next line + y_idx += line_height; + _display->setCursor(0, y_idx); + i += 3; + } else if (message[i + 1] == 'n') { + // Skip to the next line + y_idx += line_height; + _display->setCursor(0, y_idx); + i++; + } } else if (message[i] == 0xC2 && message[i + 1] == 0xB0) { _display->write(char(248)); _display->display();