From 6aacd0b0cde519719950bbaf9fb4e59bd5340c56 Mon Sep 17 00:00:00 2001 From: Vincent Dehors Date: Mon, 21 Oct 2019 12:10:17 +0200 Subject: [PATCH 1/3] segments: Add missing API for "dot" control on big 7-segments There are 4 side LEDs around the 4 7-segments on 1.2" packages of HT16k33 (https://www.adafruit.com/product/1270). This commit adds an API to control them (set and get). There already was setter and getter to control "ampm" dot (the one at the top-right). This API is still working but now use the new added functions. --- adafruit_ht16k33/segments.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index b08c27a..5ef985a 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -308,20 +308,39 @@ def __init__(self, i2c, address=0x70, auto_write=True): super().__init__(i2c, address, auto_write) self.colon = Colon(self, 2) + def setindicator(self, index, value): + """ Set side LEDs (dots) + Index is as follow : + * 0 : two dots at the center + * 1 : top-left dot + * 2 : bottom-left dot + * 3 : right dot (also ampm indicator) + """ + bitmask = 1 << (index + 1) + current = self._get_buffer(0x04) + if value: + self._set_buffer(0x04, current | bitmask) + else: + self._set_buffer(0x04, current & ~bitmask) + if self._auto_write: + self.show() + + def getindicator(self, index): + """ Get side LEDs (dots) + See setindicator() for indexes + """ + bitmask = 1 << (index + 1) + return self._get_buffer(0x04) & bitmask + @property def ampm(self): """The AM/PM indicator.""" - return bool(self._get_buffer(0x04) & 0x10) + return bool(self.getindicator(3)) @ampm.setter def ampm(self, value): - current = self._get_buffer(0x04) - if value: - self._set_buffer(0x04, current | 0x10) - else: - self._set_buffer(0x04, current & ~0x10) - if self._auto_write: - self.show() + self.setindicator(3, value) + class Colon(): """Helper class for controlling the colons. Not intended for direct use.""" From 63247a862dd2acf38d012bfaa5a9bb04ee974e5d Mon Sep 17 00:00:00 2001 From: Vincent Dehors Date: Tue, 22 Oct 2019 16:17:46 +0200 Subject: [PATCH 2/3] segments: Add properties for LED indicators of BigSeg7x4 --- adafruit_ht16k33/segments.py | 38 +++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 5ef985a..a4e863b 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -306,9 +306,11 @@ class BigSeg7x4(Seg7x4): supports displaying a limited set of characters.""" def __init__(self, i2c, address=0x70, auto_write=True): super().__init__(i2c, address, auto_write) + # Use colon for controling two-dots indicator at the center (index 0) + # or the two-dots indicators at the left (index 1) self.colon = Colon(self, 2) - def setindicator(self, index, value): + def _setindicator(self, index, value): """ Set side LEDs (dots) Index is as follow : * 0 : two dots at the center @@ -325,22 +327,48 @@ def setindicator(self, index, value): if self._auto_write: self.show() - def getindicator(self, index): + def _getindicator(self, index): """ Get side LEDs (dots) See setindicator() for indexes """ bitmask = 1 << (index + 1) return self._get_buffer(0x04) & bitmask + @property + def two_dots_center(self): + """The two dots at the center indicator.""" + return bool(self._getindicator(0)) + + @two_dots_center.setter + def two_dots_center(self, value): + self._setindicator(0, value) + + @property + def top_left_dot(self): + """The top-left dot indicator.""" + return bool(self._getindicator(1)) + + @top_left_dot.setter + def top_left_dot(self, value): + self._setindicator(1, value) + + @property + def bottom_left_dot(self): + """The bottom-left dot indicator.""" + return bool(self._getindicator(2)) + + @bottom_left_dot.setter + def bottom_left_dot(self, value): + self._setindicator(2, value) + @property def ampm(self): """The AM/PM indicator.""" - return bool(self.getindicator(3)) + return bool(self._getindicator(3)) @ampm.setter def ampm(self, value): - self.setindicator(3, value) - + self._setindicator(3, value) class Colon(): """Helper class for controlling the colons. Not intended for direct use.""" From 1332d2c07a6da79b4e5d59e300352fcb9bbdd23d Mon Sep 17 00:00:00 2001 From: Vincent Dehors Date: Thu, 9 Jan 2020 16:14:10 +0100 Subject: [PATCH 3/3] segments: Removing property two_dots_center The "colon" property already allow to control these LEDs so remove two_dots_center because of the redundancy. --- adafruit_ht16k33/segments.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index a4e863b..ab89f57 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -334,15 +334,6 @@ def _getindicator(self, index): bitmask = 1 << (index + 1) return self._get_buffer(0x04) & bitmask - @property - def two_dots_center(self): - """The two dots at the center indicator.""" - return bool(self._getindicator(0)) - - @two_dots_center.setter - def two_dots_center(self, value): - self._setindicator(0, value) - @property def top_left_dot(self): """The top-left dot indicator."""