Skip to content

Commit df0b5bc

Browse files
author
caternuson
committed
added colon control, maybe wacky?
1 parent d1e7c17 commit df0b5bc

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

adafruit_ht16k33/segments.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
0x40, # -
146146
)
147147

148-
149148
class Seg14x4(HT16K33):
150149
"""Alpha-numeric, 14-segment display."""
151150
def print(self, value):
@@ -262,10 +261,11 @@ class BigSeg7x4(Seg7x4):
262261
supports displaying a limited set of characters."""
263262
def __init__(self, i2c, address=0x70, auto_write=True):
264263
super().__init__(i2c, address, auto_write)
264+
self.colon = Colon(self, 2)
265265

266266
@property
267267
def ampm(self):
268-
return (self._get_buffer(0x04) & 0x10) >> 4
268+
return bool(self._get_buffer(0x04) & 0x10)
269269

270270
@ampm.setter
271271
def ampm(self, value):
@@ -277,8 +277,34 @@ def ampm(self, value):
277277
if self._auto_write:
278278
self.show()
279279

280-
def print(self, value):
281-
ampm = self.ampm
282-
super().print(value)
283-
if ampm:
284-
self.ampm = ampm
280+
"""need something like this to keep ampm indicator
281+
and colons from being turned off with print?"""
282+
# def print(self, value):
283+
# ampm = self.ampm
284+
# super().print(value)
285+
# if ampm:
286+
# self.ampm = ampm
287+
288+
class Colon():
289+
"""Helper class for controlling the colons. Not intended for direct use."""
290+
MASKS = (0x02, 0x0C)
291+
292+
def __init__(self, disp, num_of_colons=1):
293+
self._disp = disp
294+
self._num_of_colons = num_of_colons
295+
296+
def __setitem__(self, key, value):
297+
if key > self._num_of_colons - 1:
298+
raise ValueError("Trying to set a non-existant colon.")
299+
current = self._disp._get_buffer(0x04)
300+
if value:
301+
self._disp._set_buffer(0x04, current | self.MASKS[key])
302+
else:
303+
self._disp._set_buffer(0x04, current & ~self.MASKS[key])
304+
if self._disp.auto_write:
305+
self._disp.show()
306+
307+
def __getitem__(self, key):
308+
if key > self._num_of_colons - 1:
309+
raise ValueError("Trying to access a non-existant colon.")
310+
return bool(self._disp._get_buffer(0x04) & self.MASKS[key])

0 commit comments

Comments
 (0)