27
27
from digitalio import DigitalInOut
28
28
from analogio import AnalogIn
29
29
30
+ try :
31
+ from typing import Optional , Tuple
32
+ from microcontroller import Pin
33
+ except ImportError :
34
+ pass
30
35
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 :
32
38
33
39
"""
34
40
Maps a number from one range to another.
@@ -89,17 +95,17 @@ class Touchscreen:
89
95
90
96
def __init__ (
91
97
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 ,
96
102
* ,
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 :
103
109
104
110
self ._xm_pin = x1_pin
105
111
self ._xp_pin = x2_pin
@@ -115,7 +121,9 @@ def __init__(
115
121
self ._zthresh = z_threshold
116
122
117
123
@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
119
127
"""A tuple that represents the x, y and z (touch pressure) coordinates
120
128
of a touch. Or, None if no touch is detected"""
121
129
z_1 = z_2 = z = None
0 commit comments