Skip to content

Commit ce60b70

Browse files
committed
Update qwiic_alphanumeric.py
1 parent 5147642 commit ce60b70

File tree

1 file changed

+128
-12
lines changed

1 file changed

+128
-12
lines changed

qwiic_alphanumeric.py

Lines changed: 128 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class QwiicAlphanumeric(object):
233233
blink_rate = ALPHA_BLINK_RATE_NOBLINK # Tracks the current blinking status
234234

235235
# TODO: Not sure this will work
236-
displayRAM[16 * 4]
236+
display_RAM[16 * 4]
237237
display_content[4 * 4 + 1] = ""
238238

239239
def __init__(self, address=None, i2c_driver=None):
@@ -880,7 +880,7 @@ def illuminate_segment(self, segment, digit):
880880

881881
# Determine the address
882882
if row > 7:
883-
adr++
883+
adr = adr + 1
884884

885885
# Determine the data bit
886886
if row > 7:
@@ -905,7 +905,7 @@ def illuminate_char(self, segments_to_turn_on, digit):
905905
:rtype: Void
906906
"""
907907
for i in range(0, 14):
908-
if (self.segments_to_turn_on >> i) & 0b1:
908+
if (segments_to_turn_on >> i) & 0b1:
909909
self.illuminate_segment('A' + i, digit) # Convert the segment number to a letter
910910

911911
# ---------------------------------------------------------------------------------
@@ -940,18 +940,134 @@ def print_char(self, display_char, digit):
940940
if character_position == 65532: # unknown character
941941
character_position = self.SFE_ALPHANUM_UNKNOWN_CHAR
942942

943-
segments_to_turn_on = self.get_segments_to_turn_on(character_position)
943+
self.illuminate_char(self.alphanumeric_segs[character_position], digit)
944+
945+
# ---------------------------------------------------------------------------------
946+
# display_print(print_string)
947+
#
948+
# Print a whole string to the alphanumeric display(s)
949+
def display_print(self, print_string):
950+
"""
951+
Print a whole string to the alphanumeric display(s)
952+
953+
:param print_string: string to be printed
954+
:return: true if update_display() is successful, false otherwise
955+
:rtype: bool
956+
"""
957+
# Clear the display_RAM array
958+
for i in range(0, 16 * self.number_of_displays):
959+
self.display_RAM[i] = 0
960+
961+
self.digit_position = 0
944962

945-
self.illuminate_char(segments_to_turn_on, digit)
963+
for i in range(0, len(print_string)):
964+
# For special characters like '.' or ':', do not increment the digit position
965+
if print_string[i] == '.':
966+
self.print_char('.', 0)
967+
elif print_string[i] == ':':
968+
self.print_char(':', 0)
969+
else:
970+
self.print_char(print_string[i], self.digit_position)
971+
# Record to internal list
972+
self.display_content[self.digit_position] = print_string[i]
973+
974+
self.digit_position = self.digit_position + 1
975+
self.digit_position = self.digit_position % (self.number_of_displays * 4)
976+
977+
self.update_display()
978+
979+
# ---------------------------------------------------------------------------------
980+
# update_display()
981+
#
982+
# Push the contents of display_RAM out to the various displays in 16 byte chunks
983+
def update_display(self):
984+
"""
985+
Push the contents of display_RAM out on to the various displays in 16 byte chunks
986+
987+
:return: true if displays are updated successfully, false otherwise.
988+
:rtype: bool
989+
"""
990+
status = True
991+
992+
for i in range(1, self.number_of_displays):
993+
if self.write_RAM(self.look_up_display_address(i), 0, self.display_RAM) == False:
994+
status = False
995+
996+
return status
946997

947998
# ---------------------------------------------------------------------------------
948-
# define_char(display_char, segments_to_turn_on)
999+
# shift_right(shift_amt)
1000+
#
1001+
# Shift the display content to the right a number of digits
1002+
def shift_right(self, shift_amt = 1):
1003+
"""
1004+
Shift the display content to the right a number of digits
1005+
1006+
:param shift_amt: the number of digits to shift the string
1007+
:return: true if display updates successfully, false otherwise.
1008+
:rtype: bool
1009+
"""
1010+
for x in range(4 * slef.number_of_displays - shift_amt, shift_amt, -1):
1011+
self.display_content[x] = self.display_content[x - shift_amt]
1012+
1013+
# Clear the leading characters
1014+
for x in range(0, shift_amt):
1015+
if x + shift_amt > (4 * self.number_of_displays):
1016+
break # Error check
1017+
1018+
self.display_content[0 + x] = ' '
1019+
1020+
return self.display_print(self.display_content)
1021+
1022+
# ---------------------------------------------------------------------------------
1023+
# shift_left(shift_amt)
9491024
#
950-
# Update the list of characters to define a new segments display for a particular/custom character
951-
def define_char(self, display_char, segments_to_turn_on):
1025+
# Shift the display content to the left a number of digits
1026+
def shift_left(self, shift_amt = 1):
9521027
"""
953-
Update the list of characters to define a new segments display for a particular/custom character
1028+
Shift the display content to the left a number of digits
9541029
955-
:param display_char: the character to update in the list
956-
:param segments_to_turn_on: a list of the segments for the custom character
957-
:return: true if list is successfully
1030+
:param shift_amt: the number of digits to shift the string
1031+
:return: true if display updates successfully, false otherwise.
1032+
:rtype: bool
1033+
"""
1034+
for x in range(0, 4 * self.number_of_displays):
1035+
if x + shift_amt > (4 * self.number_of_displays):
1036+
break # Error check
1037+
self.display_content[x] = self.display_content[x + shift_amt]
1038+
1039+
# Clear the trailing characters
1040+
for x in range(0, shift_amt):
1041+
if (4 * self.number_of_displays - 1 - x) < 0:
1042+
break # Error check
1043+
1044+
self.display_content[4 * self.number_of_displays - 1 - x] = ' '
1045+
1046+
return self.display_print(self.display_content)
1047+
1048+
# ---------------------------------------------------------------------------------
1049+
# write_RAM(address, reg, buff)
1050+
#
1051+
# write LED updates to the RAM of the LED driver IC
1052+
def write_RAM(self, address, reg, buff):
1053+
"""
1054+
Write LED updates to the RAM of the LED driver IC
1055+
1056+
:param address: I2C address of the display
1057+
:param reg: the location in RAM to write to
1058+
:param buff: the bytes to be written
1059+
:return: true if RAM has been written to successfully, false otherwise.
1060+
:rtype: bool
1061+
"""
1062+
display_num = 1
1063+
if address == self._device_address_display_two:
1064+
display_num = 2
1065+
elif address == self._device_address_display_three:
1066+
display_num = 3
1067+
elif address == self._device_address_display_four:
1068+
display_num = 4
1069+
# TODO: not sure if this needs to be here or any of the lines above...
1070+
self.is_connected(display_num)
1071+
1072+
# TODO: need to convert buff into list of bytes
1073+
self._i2c.writeBlock(address, reg, buff)

0 commit comments

Comments
 (0)