|
145 | 145 | 0x40, # -
|
146 | 146 | )
|
147 | 147 |
|
148 |
| - |
149 | 148 | class Seg14x4(HT16K33):
|
150 | 149 | """Alpha-numeric, 14-segment display."""
|
151 | 150 | def print(self, value):
|
@@ -256,3 +255,51 @@ def _put(self, char, index=0):
|
256 | 255 | else:
|
257 | 256 | return
|
258 | 257 | self._set_buffer(index, NUMBERS[character])
|
| 258 | + |
| 259 | +class BigSeg7x4(Seg7x4): |
| 260 | + """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only |
| 261 | + supports displaying a limited set of characters.""" |
| 262 | + def __init__(self, i2c, address=0x70, auto_write=True): |
| 263 | + super().__init__(i2c, address, auto_write) |
| 264 | + self.colon = Colon(self, 2) |
| 265 | + |
| 266 | + @property |
| 267 | + def ampm(self): |
| 268 | + """The AM/PM indicator.""" |
| 269 | + return bool(self._get_buffer(0x04) & 0x10) |
| 270 | + |
| 271 | + @ampm.setter |
| 272 | + def ampm(self, value): |
| 273 | + current = self._get_buffer(0x04) |
| 274 | + if value: |
| 275 | + self._set_buffer(0x04, current | 0x10) |
| 276 | + else: |
| 277 | + self._set_buffer(0x04, current & ~0x10) |
| 278 | + if self._auto_write: |
| 279 | + self.show() |
| 280 | + |
| 281 | +class Colon(): |
| 282 | + """Helper class for controlling the colons. Not intended for direct use.""" |
| 283 | + #pylint: disable=protected-access |
| 284 | + |
| 285 | + MASKS = (0x02, 0x0C) |
| 286 | + |
| 287 | + def __init__(self, disp, num_of_colons=1): |
| 288 | + self._disp = disp |
| 289 | + self._num_of_colons = num_of_colons |
| 290 | + |
| 291 | + def __setitem__(self, key, value): |
| 292 | + if key > self._num_of_colons - 1: |
| 293 | + raise ValueError("Trying to set a non-existent colon.") |
| 294 | + current = self._disp._get_buffer(0x04) |
| 295 | + if value: |
| 296 | + self._disp._set_buffer(0x04, current | self.MASKS[key]) |
| 297 | + else: |
| 298 | + self._disp._set_buffer(0x04, current & ~self.MASKS[key]) |
| 299 | + if self._disp.auto_write: |
| 300 | + self._disp.show() |
| 301 | + |
| 302 | + def __getitem__(self, key): |
| 303 | + if key > self._num_of_colons - 1: |
| 304 | + raise ValueError("Trying to access a non-existent colon.") |
| 305 | + return bool(self._disp._get_buffer(0x04) & self.MASKS[key]) |
0 commit comments