Skip to content

Commit bef548b

Browse files
authored
Merge pull request #100 from makermelissa/bigseg-colon-fix
Abstracted 7-seg displays and fixed colon on big seg
2 parents 5293f18 + c871a1e commit bef548b

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

adafruit_ht16k33/segments.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,7 @@ def _scroll_marquee(self, text: str, delay: float) -> None:
325325
self.show()
326326

327327

328-
class Seg7x4(Seg14x4):
329-
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
330-
supports displaying a limited set of characters.
331-
332-
:param I2C i2c: The I2C bus object
333-
:param int address: The I2C address for the display
334-
:param bool auto_write: True if the display should immediately change when set. If False,
335-
`show` must be called explicitly.
336-
"""
337-
328+
class _AbstractSeg7x4(Seg14x4):
338329
POSITIONS = (0, 2, 6, 8) # The positions of characters.
339330

340331
def __init__(
@@ -345,8 +336,6 @@ def __init__(
345336
char_dict: Optional[Dict[str, int]] = None,
346337
) -> None:
347338
super().__init__(i2c, address, auto_write)
348-
# Use colon for controling two-dots indicator at the center (index 0)
349-
self._colon = Colon(self)
350339
self._chardict = char_dict
351340

352341
def scroll(self, count: int = 1) -> None:
@@ -430,6 +419,28 @@ def set_digit_raw(self, index: int, bitmask: int) -> None:
430419
if self._auto_write:
431420
self.show()
432421

422+
423+
class Seg7x4(_AbstractSeg7x4):
424+
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
425+
supports displaying a limited set of characters.
426+
427+
:param I2C i2c: The I2C bus object
428+
:param int address: The I2C address for the display
429+
:param bool auto_write: True if the display should immediately change when set. If False,
430+
`show` must be called explicitly.
431+
"""
432+
433+
def __init__(
434+
self,
435+
i2c: I2C,
436+
address: int = 0x70,
437+
auto_write: bool = True,
438+
char_dict: Optional[Dict[str, int]] = None,
439+
) -> None:
440+
super().__init__(i2c, address, auto_write, char_dict)
441+
# Use colon for controling two-dots indicator at the center (index 0)
442+
self._colon = Colon(self)
443+
433444
@property
434445
def colon(self) -> bool:
435446
"""Simplified colon accessor"""
@@ -440,7 +451,7 @@ def colon(self, turn_on: bool) -> None:
440451
self._colon[0] = turn_on
441452

442453

443-
class BigSeg7x4(Seg7x4):
454+
class BigSeg7x4(_AbstractSeg7x4):
444455
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
445456
supports displaying a limited set of characters.
446457
@@ -457,11 +468,10 @@ def __init__(
457468
auto_write: bool = True,
458469
char_dict: Optional[Dict[str, int]] = None,
459470
) -> None:
460-
super().__init__(i2c, address, auto_write)
471+
super().__init__(i2c, address, auto_write, char_dict)
461472
# Use colon for controling two-dots indicator at the center (index 0)
462473
# or the two-dots indicators at the left (index 1)
463-
self.colon = Colon(self, 2)
464-
self._chardict = char_dict
474+
self.colons = Colon(self, 2)
465475

466476
def _setindicator(self, index: int, value: bool) -> None:
467477
"""Set side LEDs (dots)

0 commit comments

Comments
 (0)