From 100912266754e7bc8089c9fbb0830715f80d608d Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 11 Jul 2018 18:47:08 -0700 Subject: [PATCH 1/9] added AM/PM indicator control --- adafruit_ht16k33/segments.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 97f1c28..c0a607f 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -256,3 +256,29 @@ def _put(self, char, index=0): else: return self._set_buffer(index, NUMBERS[character]) + +class BigSeg7x4(Seg7x4): + """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only + supports displaying a limited set of characters.""" + def __init__(self, i2c, address=0x70, auto_write=True): + super().__init__(i2c, address, auto_write) + + @property + def ampm(self): + return (self._get_buffer(0x04) & 0x10) >> 4 + + @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() + + def print(self, value): + ampm = self.ampm + super().print(value) + if ampm: + self.ampm = ampm From 8fe0f4ce831b35939dec5e3a9dd4ab7bd905dcbc Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 11 Jul 2018 21:28:39 -0700 Subject: [PATCH 2/9] added colon control, maybe wacky? --- adafruit_ht16k33/segments.py | 40 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index c0a607f..f8a6f10 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -145,7 +145,6 @@ 0x40, # - ) - class Seg14x4(HT16K33): """Alpha-numeric, 14-segment display.""" def print(self, value): @@ -262,10 +261,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) + self.colon = Colon(self, 2) @property def ampm(self): - return (self._get_buffer(0x04) & 0x10) >> 4 + return bool(self._get_buffer(0x04) & 0x10) @ampm.setter def ampm(self, value): @@ -277,8 +277,34 @@ def ampm(self, value): if self._auto_write: self.show() - def print(self, value): - ampm = self.ampm - super().print(value) - if ampm: - self.ampm = ampm + """need something like this to keep ampm indicator + and colons from being turned off with print?""" + # def print(self, value): + # ampm = self.ampm + # super().print(value) + # if ampm: + # self.ampm = ampm + +class Colon(): + """Helper class for controlling the colons. Not intended for direct use.""" + MASKS = (0x02, 0x0C) + + def __init__(self, disp, num_of_colons=1): + self._disp = disp + self._num_of_colons = num_of_colons + + def __setitem__(self, key, value): + if key > self._num_of_colons - 1: + raise ValueError("Trying to set a non-existant colon.") + current = self._disp._get_buffer(0x04) + if value: + self._disp._set_buffer(0x04, current | self.MASKS[key]) + else: + self._disp._set_buffer(0x04, current & ~self.MASKS[key]) + if self._disp.auto_write: + self._disp.show() + + def __getitem__(self, key): + if key > self._num_of_colons - 1: + raise ValueError("Trying to access a non-existant colon.") + return bool(self._disp._get_buffer(0x04) & self.MASKS[key]) From d1e7c17c80ac3591bf6e4f291c73e525ea62e8c6 Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 11 Jul 2018 18:47:08 -0700 Subject: [PATCH 3/9] added AM/PM indicator control --- adafruit_ht16k33/segments.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 97f1c28..c0a607f 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -256,3 +256,29 @@ def _put(self, char, index=0): else: return self._set_buffer(index, NUMBERS[character]) + +class BigSeg7x4(Seg7x4): + """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only + supports displaying a limited set of characters.""" + def __init__(self, i2c, address=0x70, auto_write=True): + super().__init__(i2c, address, auto_write) + + @property + def ampm(self): + return (self._get_buffer(0x04) & 0x10) >> 4 + + @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() + + def print(self, value): + ampm = self.ampm + super().print(value) + if ampm: + self.ampm = ampm From df0b5bcd39faa649d62079731a983faa4071f614 Mon Sep 17 00:00:00 2001 From: caternuson Date: Wed, 11 Jul 2018 21:28:39 -0700 Subject: [PATCH 4/9] added colon control, maybe wacky? --- adafruit_ht16k33/segments.py | 40 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index c0a607f..f8a6f10 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -145,7 +145,6 @@ 0x40, # - ) - class Seg14x4(HT16K33): """Alpha-numeric, 14-segment display.""" def print(self, value): @@ -262,10 +261,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) + self.colon = Colon(self, 2) @property def ampm(self): - return (self._get_buffer(0x04) & 0x10) >> 4 + return bool(self._get_buffer(0x04) & 0x10) @ampm.setter def ampm(self, value): @@ -277,8 +277,34 @@ def ampm(self, value): if self._auto_write: self.show() - def print(self, value): - ampm = self.ampm - super().print(value) - if ampm: - self.ampm = ampm + """need something like this to keep ampm indicator + and colons from being turned off with print?""" + # def print(self, value): + # ampm = self.ampm + # super().print(value) + # if ampm: + # self.ampm = ampm + +class Colon(): + """Helper class for controlling the colons. Not intended for direct use.""" + MASKS = (0x02, 0x0C) + + def __init__(self, disp, num_of_colons=1): + self._disp = disp + self._num_of_colons = num_of_colons + + def __setitem__(self, key, value): + if key > self._num_of_colons - 1: + raise ValueError("Trying to set a non-existant colon.") + current = self._disp._get_buffer(0x04) + if value: + self._disp._set_buffer(0x04, current | self.MASKS[key]) + else: + self._disp._set_buffer(0x04, current & ~self.MASKS[key]) + if self._disp.auto_write: + self._disp.show() + + def __getitem__(self, key): + if key > self._num_of_colons - 1: + raise ValueError("Trying to access a non-existant colon.") + return bool(self._disp._get_buffer(0x04) & self.MASKS[key]) From e7e452d7b6e86d20846a6aef3eaf83d608604ba0 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 13 Jul 2018 12:23:10 -0700 Subject: [PATCH 5/9] refined --- adafruit_ht16k33/segments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index f8a6f10..7373bfa 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -261,7 +261,7 @@ 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) - self.colon = Colon(self, 2) + self.colon = Colon(self, 2) @property def ampm(self): From debd029e232db7c32c82d2d68edb3f19e5b5d32b Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 13 Jul 2018 12:45:18 -0700 Subject: [PATCH 6/9] remove stubbed out func, typos --- adafruit_ht16k33/segments.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 7373bfa..a76337d 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -277,14 +277,6 @@ def ampm(self, value): if self._auto_write: self.show() - """need something like this to keep ampm indicator - and colons from being turned off with print?""" - # def print(self, value): - # ampm = self.ampm - # super().print(value) - # if ampm: - # self.ampm = ampm - class Colon(): """Helper class for controlling the colons. Not intended for direct use.""" MASKS = (0x02, 0x0C) @@ -295,7 +287,7 @@ def __init__(self, disp, num_of_colons=1): def __setitem__(self, key, value): if key > self._num_of_colons - 1: - raise ValueError("Trying to set a non-existant colon.") + raise ValueError("Trying to set a non-existent colon.") current = self._disp._get_buffer(0x04) if value: self._disp._set_buffer(0x04, current | self.MASKS[key]) @@ -306,5 +298,5 @@ def __setitem__(self, key, value): def __getitem__(self, key): if key > self._num_of_colons - 1: - raise ValueError("Trying to access a non-existant colon.") + raise ValueError("Trying to access a non-existent colon.") return bool(self._disp._get_buffer(0x04) & self.MASKS[key]) From 30ba1db8b5be1c045de07a04e7be1ac1299bd377 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 13 Jul 2018 12:54:43 -0700 Subject: [PATCH 7/9] sir lint-a-lot --- adafruit_ht16k33/segments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index a76337d..ea836da 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -261,10 +261,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) - self.colon = Colon(self, 2) + self.colon = Colon(self, 2) @property def ampm(self): + """The AM/PM indicator.""" return bool(self._get_buffer(0x04) & 0x10) @ampm.setter From 5d25dc3b1ccff5cac63b339f6219f54c97ea77f0 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 13 Jul 2018 13:01:54 -0700 Subject: [PATCH 8/9] it's ok linty, it's a friendly class --- adafruit_ht16k33/segments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index ea836da..399d6ad 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -278,6 +278,7 @@ def ampm(self, value): if self._auto_write: self.show() +#pylint: disable=W0212 class Colon(): """Helper class for controlling the colons. Not intended for direct use.""" MASKS = (0x02, 0x0C) From aff4185733ab24cab2d7f6aae8c1b225c0d6fdb4 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 13 Jul 2018 14:22:57 -0700 Subject: [PATCH 9/9] change and move pylint disable --- adafruit_ht16k33/segments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 399d6ad..95424b3 100644 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -278,9 +278,10 @@ def ampm(self, value): if self._auto_write: self.show() -#pylint: disable=W0212 class Colon(): """Helper class for controlling the colons. Not intended for direct use.""" + #pylint: disable=protected-access + MASKS = (0x02, 0x0C) def __init__(self, disp, num_of_colons=1):