Skip to content

Commit 4f02b44

Browse files
authored
Merge pull request #17 from tcfranks/main
Add Missing Type Annotations
2 parents afae774 + d39c6cc commit 4f02b44

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

adafruit_pcd8544.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
except ImportError:
3737
import adafruit_framebuf as framebuf
3838

39+
try:
40+
from typing import Optional
41+
from digitalio import DigitalInOut
42+
from busio import SPI
43+
except ImportError:
44+
pass
45+
3946
__version__ = "0.0.0+auto.0"
4047
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCD8544.git"
4148

@@ -64,15 +71,15 @@ class PCD8544(framebuf.FrameBuffer):
6471

6572
def __init__(
6673
self,
67-
spi,
68-
dc_pin,
69-
cs_pin,
70-
reset_pin=None,
74+
spi: SPI,
75+
dc_pin: DigitalInOut,
76+
cs_pin: DigitalInOut,
77+
reset_pin: Optional[DigitalInOut] = None,
7178
*,
72-
contrast=80,
73-
bias=4,
74-
baudrate=1000000
75-
):
79+
contrast: int = 80,
80+
bias: int = 4,
81+
baudrate: int = 1000000
82+
) -> None:
7683
self._dc_pin = dc_pin
7784
dc_pin.switch_to_output(value=False)
7885

@@ -94,7 +101,7 @@ def __init__(
94101
self.bias = bias
95102
self.contrast = contrast
96103

97-
def reset(self):
104+
def reset(self) -> None:
98105
"""Reset the display"""
99106
if self._reset_pin:
100107
# Toggle RST low to reset.
@@ -103,13 +110,13 @@ def reset(self):
103110
self._reset_pin.value = True
104111
time.sleep(0.5)
105112

106-
def write_cmd(self, cmd):
113+
def write_cmd(self, cmd: int) -> None:
107114
"""Send a command to the SPI device"""
108115
self._dc_pin.value = 0
109116
with self.spi_device as spi:
110117
spi.write(bytearray([cmd])) # pylint: disable=no-member
111118

112-
def extended_command(self, cmd):
119+
def extended_command(self, cmd: int) -> None:
113120
"""Send a command in extended mode"""
114121
# Set extended command mode
115122
self.write_cmd(_PCD8544_FUNCTIONSET | _PCD8544_EXTENDEDINSTRUCTION)
@@ -118,7 +125,7 @@ def extended_command(self, cmd):
118125
self.write_cmd(_PCD8544_FUNCTIONSET)
119126
self.write_cmd(_PCD8544_DISPLAYCONTROL | _PCD8544_DISPLAYNORMAL)
120127

121-
def show(self):
128+
def show(self) -> None:
122129
"""write out the frame buffer via SPI"""
123130
self.write_cmd(_PCD8544_SETYADDR)
124131
self.write_cmd(_PCD8544_SETXADDR)
@@ -127,12 +134,12 @@ def show(self):
127134
spi.write(self.buffer) # pylint: disable=no-member
128135

129136
@property
130-
def invert(self):
137+
def invert(self) -> bool:
131138
"""Whether the display is inverted, cached value"""
132139
return self._invert
133140

134141
@invert.setter
135-
def invert(self, val):
142+
def invert(self, val: bool) -> None:
136143
"""Set invert on or normal display on"""
137144
self._invert = val
138145
self.write_cmd(_PCD8544_FUNCTIONSET)
@@ -142,23 +149,23 @@ def invert(self, val):
142149
self.write_cmd(_PCD8544_DISPLAYCONTROL | _PCD8544_DISPLAYNORMAL)
143150

144151
@property
145-
def contrast(self):
152+
def contrast(self) -> int:
146153
"""The cached contrast value"""
147154
return self._contrast
148155

149156
@contrast.setter
150-
def contrast(self, val):
157+
def contrast(self, val: int) -> None:
151158
"""Set contrast to specified value (should be 0-127)."""
152159
self._contrast = max(0, min(val, 0x7F)) # Clamp to values 0-0x7f
153160
self.extended_command(_PCD8544_SETVOP | self._contrast)
154161

155162
@property
156-
def bias(self):
163+
def bias(self) -> int:
157164
"""The cached bias value"""
158165
return self._bias
159166

160167
@bias.setter
161-
def bias(self, val):
168+
def bias(self, val: int) -> None:
162169
"""Set display bias"""
163170
self._bias = val
164171
self.extended_command(_PCD8544_SETBIAS | self._bias)

0 commit comments

Comments
 (0)