Skip to content

Commit f439fea

Browse files
committed
Ensure print() does not wrap with long inputs
Eg. if only 1 display is available, shouldn't try to print more than 4 characters Also fix initialization of display_RAM, should be zeros instead of spaces
1 parent 7a3106d commit f439fea

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

qwiic_alphanumeric.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class QwiicAlphanumeric(object):
232232
colon_on_off = 0 # Tracks the on/off state of the colon segment
233233
blink_rate = ALPHA_BLINK_RATE_NOBLINK # Tracks the current blinking status
234234

235-
display_RAM = [' '] * 16 * 4
235+
display_RAM = [0] * 16 * 4
236236
display_content = [' '] * (4 * 4 + 1)
237237

238238
def __init__(self, address=None, i2c_driver=None):
@@ -966,7 +966,7 @@ def print(self, print_string):
966966

967967
self.digit_position = 0
968968

969-
for i in range(0, len(print_string)):
969+
for i in range(0, min(len(print_string), self.number_of_displays * 4)):
970970
# For special characters like '.' or ':', do not increment the digit position
971971
if print_string[i] == '.':
972972
self.print_char('.', 0)
@@ -978,7 +978,6 @@ def print(self, print_string):
978978
self.display_content[i] = print_string[i]
979979

980980
self.digit_position = self.digit_position + 1
981-
self.digit_position = self.digit_position % (self.number_of_displays * 4)
982981

983982
self.update_display()
984983

0 commit comments

Comments
 (0)