Skip to content

Commit f836604

Browse files
authored
Merge pull request #41 from vdehors/master
segments: Add missing API for "dot" control on big 7-segments
2 parents 1f60840 + 1332d2c commit f836604

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

adafruit_ht16k33/segments.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,60 @@ class BigSeg7x4(Seg7x4):
306306
supports displaying a limited set of characters."""
307307
def __init__(self, i2c, address=0x70, auto_write=True):
308308
super().__init__(i2c, address, auto_write)
309+
# Use colon for controling two-dots indicator at the center (index 0)
310+
# or the two-dots indicators at the left (index 1)
309311
self.colon = Colon(self, 2)
310312

313+
def _setindicator(self, index, value):
314+
""" Set side LEDs (dots)
315+
Index is as follow :
316+
* 0 : two dots at the center
317+
* 1 : top-left dot
318+
* 2 : bottom-left dot
319+
* 3 : right dot (also ampm indicator)
320+
"""
321+
bitmask = 1 << (index + 1)
322+
current = self._get_buffer(0x04)
323+
if value:
324+
self._set_buffer(0x04, current | bitmask)
325+
else:
326+
self._set_buffer(0x04, current & ~bitmask)
327+
if self._auto_write:
328+
self.show()
329+
330+
def _getindicator(self, index):
331+
""" Get side LEDs (dots)
332+
See setindicator() for indexes
333+
"""
334+
bitmask = 1 << (index + 1)
335+
return self._get_buffer(0x04) & bitmask
336+
337+
@property
338+
def top_left_dot(self):
339+
"""The top-left dot indicator."""
340+
return bool(self._getindicator(1))
341+
342+
@top_left_dot.setter
343+
def top_left_dot(self, value):
344+
self._setindicator(1, value)
345+
346+
@property
347+
def bottom_left_dot(self):
348+
"""The bottom-left dot indicator."""
349+
return bool(self._getindicator(2))
350+
351+
@bottom_left_dot.setter
352+
def bottom_left_dot(self, value):
353+
self._setindicator(2, value)
354+
311355
@property
312356
def ampm(self):
313357
"""The AM/PM indicator."""
314-
return bool(self._get_buffer(0x04) & 0x10)
358+
return bool(self._getindicator(3))
315359

316360
@ampm.setter
317361
def ampm(self, value):
318-
current = self._get_buffer(0x04)
319-
if value:
320-
self._set_buffer(0x04, current | 0x10)
321-
else:
322-
self._set_buffer(0x04, current & ~0x10)
323-
if self._auto_write:
324-
self.show()
362+
self._setindicator(3, value)
325363

326364
class Colon():
327365
"""Helper class for controlling the colons. Not intended for direct use."""

0 commit comments

Comments
 (0)