Skip to content

Commit f9606d4

Browse files
committed
Remove carriage return processing. Just do newline. Simplify write().
1 parent 17a04a4 commit f9606d4

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lcd/lcd.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@ def set_cursor_pos(self, row, col):
184184
def print(self, string):
185185
"""
186186
Write the specified unicode string to the display.
187-
188-
To control multiline behavior, use newline (``\\n``) and carriage
189-
return (``\\r``) characters. Newline moves to the next row without
190-
resetting the column to the left or right side. Carriage return
191-
moves to the left or right side of the current row.
192-
187+
A newline ('\n') will advance to the left side of the next row.
193188
Lines that are too long automatically continue on next line.
194189
195190
Only characters with an ``ord()`` value between 0 and 255 are currently
@@ -198,11 +193,8 @@ def print(self, string):
198193
"""
199194
for char in string:
200195
if char == '\n':
201-
# Advance to next row, at same column position
202-
self.set_cursor_pos((self._row + 1) % self.num_rows, self._col)
203-
elif char == '\r':
204-
# Return to left side of current row.
205-
self.set_cursor_pos(self._row, 0)
196+
# Advance to next row, at left side. Wrap around to top row if at bottom.
197+
self.set_cursor_pos((self._row + 1) % self.num_rows, 0)
206198
else:
207199
self.write(ord(char))
208200

@@ -290,9 +282,8 @@ def write(self, value):
290282
self._col += 1
291283
else:
292284
# At end of line: go to left side next row. Wrap around to first row if on last row.
293-
self.set_cursor_pos((self._row + 1) % self.num_rows, 0)
285+
self._row = (self._row + 1) % self.num_rows
286+
self._col = 0
294287

295-
# Internal increment may put cursor at wrong place. Reset to where we
296-
# want the next character to go.
297288
self.set_cursor_pos(self._row, self._col)
298289

0 commit comments

Comments
 (0)