Skip to content

Commit 7db8002

Browse files
authored
Merge pull request #21 from tcfranks/main
Add Missing Type Annotations
2 parents 827e1ca + a511cec commit 7db8002

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

adafruit_touchscreen.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
from digitalio import DigitalInOut
2828
from analogio import AnalogIn
2929

30+
try:
31+
from typing import Optional, Tuple
32+
from microcontroller import Pin
33+
except ImportError:
34+
pass
3035

31-
def map_range(x, in_min, in_max, out_min, out_max):
36+
37+
def map_range(x: float, in_min: int, in_max: int, out_min: int, out_max: int) -> float:
3238

3339
"""
3440
Maps a number from one range to another.
@@ -89,17 +95,17 @@ class Touchscreen:
8995

9096
def __init__(
9197
self,
92-
x1_pin,
93-
x2_pin,
94-
y1_pin,
95-
y2_pin,
98+
x1_pin: Pin,
99+
x2_pin: Pin,
100+
y1_pin: Pin,
101+
y2_pin: Pin,
96102
*,
97-
x_resistance=None,
98-
samples=4,
99-
z_threshold=10000,
100-
calibration=None,
101-
size=None
102-
):
103+
x_resistance: Optional[int] = None,
104+
samples: int = 4,
105+
z_threshold: int = 10000,
106+
calibration: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None,
107+
size: Optional[Tuple[int, int]] = None
108+
) -> None:
103109

104110
self._xm_pin = x1_pin
105111
self._xp_pin = x2_pin
@@ -115,7 +121,9 @@ def __init__(
115121
self._zthresh = z_threshold
116122

117123
@property
118-
def touch_point(self): # pylint: disable=too-many-locals
124+
def touch_point(
125+
self,
126+
) -> Optional[Tuple[int, int, int]]: # pylint: disable=too-many-locals
119127
"""A tuple that represents the x, y and z (touch pressure) coordinates
120128
of a touch. Or, None if no touch is detected"""
121129
z_1 = z_2 = z = None

0 commit comments

Comments
 (0)