Skip to content

Commit ea1f0de

Browse files
authored
Merge pull request #95 from tekktrik/doc/update-documentation
Updates to Documentation
2 parents e8566ae + 43f06a8 commit ea1f0de

File tree

5 files changed

+172
-78
lines changed

5 files changed

+172
-78
lines changed

adafruit_ht16k33/bargraph.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __getitem__(self, key: int) -> Optional[bool]:
3636
# construct the color value and return it
3737
return self._pixel(x, y) | self._pixel(x + 8, y) << 1
3838

39-
def __setitem__(self, key: int, value: bool):
39+
def __setitem__(self, key: int, value: bool) -> None:
4040
# map to HT16K33 row (x) and column (y), see schematic
4141
x = key % 4 + 4 * (key // 12)
4242
y = key // 4 - 3 * (key // 12)
@@ -45,8 +45,12 @@ def __setitem__(self, key: int, value: bool):
4545
# conditionally turn on green LED
4646
self._pixel(x + 8, y, value >> 1)
4747

48-
def fill(self, color: bool):
49-
"""Fill the whole display with the given color."""
48+
def fill(self, color: bool) -> None:
49+
"""Fill the whole display with the given color.
50+
51+
:param bool color: Whether to fill the display
52+
"""
53+
5054
what_it_was = self.auto_write
5155
self.auto_write = False
5256
for i in range(24):

adafruit_ht16k33/ht16k33.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class HT16K33:
3333
"""
3434
The base class for all displays. Contains common methods.
3535
36+
:param I2C i2c: The I2C bus object
3637
:param int address: The I2C addess of the HT16K33.
3738
:param bool auto_write: True if the display should immediately change when
3839
set. If False, `show` must be called explicitly.
@@ -45,7 +46,7 @@ def __init__(
4546
address: int = 0x70,
4647
auto_write: bool = True,
4748
brightness: float = 1.0,
48-
):
49+
) -> None:
4950
self.i2c_device = i2c_device.I2CDevice(i2c, address)
5051
self._temp = bytearray(1)
5152
self._buffer = bytearray(17)
@@ -57,31 +58,31 @@ def __init__(
5758
self.blink_rate = 0
5859
self.brightness = brightness
5960

60-
def _write_cmd(self, byte: bytearray):
61+
def _write_cmd(self, byte: bytearray) -> None:
6162
self._temp[0] = byte
6263
with self.i2c_device:
6364
self.i2c_device.write(self._temp)
6465

6566
@property
66-
def blink_rate(self):
67+
def blink_rate(self) -> int:
6768
"""The blink rate. Range 0-3."""
6869
return self._blink_rate
6970

7071
@blink_rate.setter
71-
def blink_rate(self, rate: int = None):
72+
def blink_rate(self, rate: Optional[int] = None) -> None:
7273
if not 0 <= rate <= 3:
7374
raise ValueError("Blink rate must be an integer in the range: 0-3")
7475
rate = rate & 0x03
7576
self._blink_rate = rate
7677
self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1)
7778

7879
@property
79-
def brightness(self):
80+
def brightness(self) -> float:
8081
"""The brightness. Range 0.0-1.0"""
8182
return self._brightness
8283

8384
@brightness.setter
84-
def brightness(self, brightness: float):
85+
def brightness(self, brightness: float) -> None:
8586
if not 0.0 <= brightness <= 1.0:
8687
raise ValueError(
8788
"Brightness must be a decimal number in the range: 0.0-1.0"
@@ -93,26 +94,30 @@ def brightness(self, brightness: float):
9394
self._write_cmd(_HT16K33_CMD_BRIGHTNESS | xbright)
9495

9596
@property
96-
def auto_write(self):
97+
def auto_write(self) -> bool:
9798
"""Auto write updates to the display."""
9899
return self._auto_write
99100

100101
@auto_write.setter
101-
def auto_write(self, auto_write: bool):
102+
def auto_write(self, auto_write: bool) -> None:
102103
if isinstance(auto_write, bool):
103104
self._auto_write = auto_write
104105
else:
105106
raise ValueError("Must set to either True or False.")
106107

107-
def show(self):
108+
def show(self) -> None:
108109
"""Refresh the display and show the changes."""
109110
with self.i2c_device:
110111
# Byte 0 is 0x00, address of LED data register. The remaining 16
111112
# bytes are the display register data to set.
112113
self.i2c_device.write(self._buffer)
113114

114-
def fill(self, color: bool):
115-
"""Fill the whole display with the given color."""
115+
def fill(self, color: bool) -> None:
116+
"""Fill the whole display with the given color.
117+
118+
:param bool color: Whether to fill the display
119+
"""
120+
116121
fill = 0xFF if color else 0x00
117122
for i in range(16):
118123
self._buffer[i + 1] = fill
@@ -134,7 +139,7 @@ def _pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]
134139
self.show()
135140
return None
136141

137-
def _set_buffer(self, i: int, value: bool):
142+
def _set_buffer(self, i: int, value: bool) -> None:
138143
self._buffer[i + 1] = value # Offset by 1 to move past register address.
139144

140145
def _get_buffer(self, i: int) -> bool:

adafruit_ht16k33/matrix.py

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# SPDX-License-Identifier: MIT
55

66
"""
7-
Matrix Displays
8-
================
7+
adafruit_ht16k33.matrix
8+
=======================
99
1010
"""
1111
from adafruit_ht16k33.ht16k33 import HT16K33
@@ -27,7 +27,14 @@ class Matrix8x8(HT16K33):
2727
_rows = 8
2828

2929
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
30-
"""Get or set the color of a given pixel."""
30+
"""Get or set the color of a given pixel.
31+
32+
:param int x: The x coordinate of the pixel
33+
:param int y: The y coordinate of the pixel
34+
:param bool color: (Optional) The state to set the pixel
35+
:return: If ``color`` was not set, this returns the state of the pixel
36+
:rtype: bool
37+
"""
3138
if not 0 <= x <= 7:
3239
return None
3340
if not 0 <= y <= 7:
@@ -39,16 +46,18 @@ def __getitem__(self, key: int) -> Optional[bool]:
3946
x, y = key
4047
return self.pixel(x, y)
4148

42-
def __setitem__(self, key: int, value: bool):
49+
def __setitem__(self, key: int, value: bool) -> None:
4350
x, y = key
4451
self.pixel(x, y, value)
4552

4653
# pylint: disable=too-many-branches
47-
def shift(self, x: int, y: int, rotate: bool = False):
54+
def shift(self, x: int, y: int, rotate: bool = False) -> None:
4855
"""
4956
Shift pixels by x and y
5057
51-
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
58+
:param int x: The x coordinate of the pixel
59+
:param int y: The y coordinate of the pixel
60+
:param bool rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
5261
"""
5362
auto_write = self.auto_write
5463
self._auto_write = False
@@ -86,41 +95,45 @@ def shift(self, x: int, y: int, rotate: bool = False):
8695

8796
# pylint: enable=too-many-branches
8897

89-
def shift_right(self, rotate: bool = False):
98+
def shift_right(self, rotate: bool = False) -> None:
9099
"""
91100
Shift all pixels right
92101
93102
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
94103
"""
95104
self.shift(1, 0, rotate)
96105

97-
def shift_left(self, rotate: bool = False):
106+
def shift_left(self, rotate: bool = False) -> None:
98107
"""
99108
Shift all pixels left
100109
101110
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
102111
"""
103112
self.shift(-1, 0, rotate)
104113

105-
def shift_up(self, rotate: bool = False):
114+
def shift_up(self, rotate: bool = False) -> None:
106115
"""
107116
Shift all pixels up
108117
109118
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
110119
"""
111120
self.shift(0, 1, rotate)
112121

113-
def shift_down(self, rotate: bool = False):
122+
def shift_down(self, rotate: bool = False) -> None:
114123
"""
115124
Shift all pixels down
116125
117126
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
118127
"""
119128
self.shift(0, -1, rotate)
120129

121-
def image(self, img):
130+
def image(self, img: Image) -> None:
122131
"""Set buffer to value of Python Imaging Library image. The image should
123-
be in 1 bit mode and a size equal to the display size."""
132+
be in 1 bit mode and a size equal to the display size.
133+
134+
:param Image img: The image to show
135+
"""
136+
124137
imwidth, imheight = img.size
125138
if imwidth != self.columns or imheight != self.rows:
126139
raise ValueError(
@@ -141,12 +154,12 @@ def image(self, img):
141154
self.show()
142155

143156
@property
144-
def columns(self):
157+
def columns(self) -> int:
145158
"""Read-only property for number of columns"""
146159
return self._columns
147160

148161
@property
149-
def rows(self):
162+
def rows(self) -> int:
150163
"""Read-only property for number of rows"""
151164
return self._rows
152165

@@ -156,8 +169,16 @@ class Matrix16x8(Matrix8x8):
156169

157170
_columns = 16
158171

159-
def pixel(self, x, y, color=None):
160-
"""Get or set the color of a given pixel."""
172+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
173+
"""Get or set the color of a given pixel.
174+
175+
:param int x: The x coordinate of the pixel
176+
:param int y: The y coordinate of the pixel
177+
:param bool color: (Optional) The state to set the pixel
178+
:return: If ``color`` was not set, this returns the state of the pixel
179+
:rtype: bool
180+
"""
181+
161182
if not 0 <= x <= 15:
162183
return None
163184
if not 0 <= y <= 7:
@@ -171,8 +192,16 @@ def pixel(self, x, y, color=None):
171192
class MatrixBackpack16x8(Matrix16x8):
172193
"""A double matrix backpack."""
173194

174-
def pixel(self, x, y, color=None):
175-
"""Get or set the color of a given pixel."""
195+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
196+
"""Get or set the color of a given pixel.
197+
198+
:param int x: The x coordinate of the pixel
199+
:param int y: The y coordinate of the pixel
200+
:param bool color: (Optional) The state to set the pixel
201+
:return: If ``color`` was not set, this returns the state of the pixel
202+
:rtype: bool
203+
"""
204+
176205
if not 0 <= x <= 15:
177206
return None
178207
if not 0 <= y <= 7:
@@ -188,8 +217,15 @@ class Matrix8x8x2(Matrix8x8):
188217
LED_GREEN = 2
189218
LED_YELLOW = 3
190219

191-
def pixel(self, x, y, color=None):
192-
"""Get or set the color of a given pixel."""
220+
def pixel(self, x: int, y: int, color: Optional[bool] = None) -> Optional[bool]:
221+
"""Get or set the color of a given pixel.
222+
223+
:param int x: The x coordinate of the pixel
224+
:param int y: The y coordinate of the pixel
225+
:param bool color: (Optional) The state to set the pixel
226+
:return: If ``color`` was not set, this returns the state of the pixel
227+
:rtype: bool
228+
"""
193229
if not 0 <= x <= 7:
194230
return None
195231
if not 0 <= y <= 7:
@@ -201,8 +237,12 @@ def pixel(self, x, y, color=None):
201237
return super()._pixel(y, x) | super()._pixel(y + 8, x) << 1
202238
return None
203239

204-
def fill(self, color):
205-
"""Fill the whole display with the given color."""
240+
def fill(self, color: bool) -> None:
241+
"""Fill the whole display with the given color.
242+
243+
:param bool color: Whether to fill the display
244+
"""
245+
206246
fill1 = 0xFF if color & 0x01 else 0x00
207247
fill2 = 0xFF if color & 0x02 else 0x00
208248
for i in range(8):
@@ -211,9 +251,13 @@ def fill(self, color):
211251
if self._auto_write:
212252
self.show()
213253

214-
def image(self, img: Image):
254+
def image(self, img: Image) -> None:
215255
"""Set buffer to value of Python Imaging Library image. The image should
216-
be a size equal to the display size."""
256+
be a size equal to the display size.
257+
258+
:param Image img: The image to show
259+
"""
260+
217261
imwidth, imheight = img.size
218262
if imwidth != self.columns or imheight != self.rows:
219263
raise ValueError(

0 commit comments

Comments
 (0)