Skip to content

Abstracted 7-seg displays and fixed colon on big seg #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions adafruit_ht16k33/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,7 @@ def _scroll_marquee(self, text: str, delay: float) -> None:
self.show()


class Seg7x4(Seg14x4):
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
supports displaying a limited set of characters.

:param I2C i2c: The I2C bus object
:param int address: The I2C address for the display
:param bool auto_write: True if the display should immediately change when set. If False,
`show` must be called explicitly.
"""

class _AbstractSeg7x4(Seg14x4):
POSITIONS = (0, 2, 6, 8) # The positions of characters.

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

def scroll(self, count: int = 1) -> None:
Expand Down Expand Up @@ -430,6 +419,28 @@ def set_digit_raw(self, index: int, bitmask: int) -> None:
if self._auto_write:
self.show()


class Seg7x4(_AbstractSeg7x4):
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
supports displaying a limited set of characters.

:param I2C i2c: The I2C bus object
:param int address: The I2C address for the display
:param bool auto_write: True if the display should immediately change when set. If False,
`show` must be called explicitly.
"""

def __init__(
self,
i2c: I2C,
address: int = 0x70,
auto_write: bool = True,
char_dict: Optional[Dict[str, int]] = None,
) -> None:
super().__init__(i2c, address, auto_write, char_dict)
# Use colon for controling two-dots indicator at the center (index 0)
self._colon = Colon(self)

@property
def colon(self) -> bool:
"""Simplified colon accessor"""
Expand All @@ -440,7 +451,7 @@ def colon(self, turn_on: bool) -> None:
self._colon[0] = turn_on


class BigSeg7x4(Seg7x4):
class BigSeg7x4(_AbstractSeg7x4):
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
supports displaying a limited set of characters.

Expand All @@ -457,11 +468,10 @@ def __init__(
auto_write: bool = True,
char_dict: Optional[Dict[str, int]] = None,
) -> None:
super().__init__(i2c, address, auto_write)
super().__init__(i2c, address, auto_write, char_dict)
# 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)
self._chardict = char_dict
self.colons = Colon(self, 2)

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