Skip to content

Commit e5a3acf

Browse files
committed
\r\n sequence escape
1 parent cb65ab3 commit e5a3acf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/components/i2c/drivers/WipperSnapper_I2C_Driver_Out_CharLcd.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,23 @@ class WipperSnapper_I2C_Driver_Out_CharLcd
124124
WS_DEBUG_PRINTLN(" ");
125125
if (c == '\\' && cur_idx + 1 < message_length &&
126126
(message[cur_idx + 1] == 'n' || message[cur_idx + 1] == 'r')) {
127-
cur_idx += 2; // Skip the '\n' or '\r' character in the buffer
128-
break; // and move to the next row
127+
WS_DEBUG_PRINTLN("CharLCD: Detected newline sequence");
128+
// Handle \r\n sequence as a single newline
129+
if (message[cur_idx + 1] == 'r' && cur_idx + 3 < message_length &&
130+
message[cur_idx + 2] == '\\' && message[cur_idx + 3] == 'n') {
131+
cur_idx += 4; // Skip \r\n and don't move the cursor two rows
132+
} else {
133+
cur_idx += 2; // Skip either the \n or \r
134+
}
135+
break; // and move to the next row
129136
} else if ((c == 0x0A || c == 0x0D) && cur_idx + 1 < message_length) {
130-
cur_idx += 1; // Skip the UTF-8 sequence for \n or \r
131-
break; // and move to the next row
137+
if (c == 0x0A && cur_idx + 1 < message_length &&
138+
message[cur_idx + 1] == 0x0D) {
139+
cur_idx += 2; // Skip both LF and CR characters
140+
} else {
141+
cur_idx += 1; // Skip single newline character
142+
}
143+
break; // and move to the next row
132144
} else if (c == 194 && cur_idx + 1 < message_length &&
133145
message[cur_idx + 1] == 176) {
134146
cur_idx += 2; // Skip the degree symbol sequence in the buffer

0 commit comments

Comments
 (0)