@@ -62,8 +62,8 @@ class Touchscreen:
62
62
:attr:`calibration` is a tuple of two tuples, the default is
63
63
((0, 65535), (0, 65535)). The numbers are the min/max readings for the
64
64
X and Y coordinate planes, respectively. To figure these out, pass in
65
- no calibration value and read the raw values out while touching the
66
- panel.
65
+ no calibration value or size value and read the raw minimum and maximum
66
+ values out while touching the panel.
67
67
:attr:`size` is a tuple that gives the X and Y pixel size of the underlying
68
68
screen. If passed in, we will automatically scale/rotate so touches
69
69
correspond to the graphical coordinate system.
@@ -108,6 +108,7 @@ def __init__(
108
108
self ._rx_plate = x_resistance
109
109
self ._xsamples = [0 ] * samples
110
110
self ._ysamples = [0 ] * samples
111
+ self ._zsamples = [0 ] * samples
111
112
if not calibration :
112
113
calibration = ((0 , 65535 ), (0 , 65535 ))
113
114
self ._calib = calibration
@@ -118,36 +119,6 @@ def __init__(
118
119
def touch_point (self ): # pylint: disable=too-many-locals
119
120
"""A tuple that represents the x, y and z (touch pressure) coordinates
120
121
of a touch. Or, None if no touch is detected"""
121
- with DigitalInOut (self ._yp_pin ) as y_p :
122
- with DigitalInOut (self ._ym_pin ) as y_m :
123
- with AnalogIn (self ._xp_pin ) as x_p :
124
- y_p .switch_to_output (True )
125
- y_m .switch_to_output (False )
126
- for i in range ( # pylint: disable=consider-using-enumerate
127
- len (self ._xsamples )
128
- ):
129
- self ._xsamples [i ] = x_p .value
130
- x = sum (self ._xsamples ) / len (self ._xsamples )
131
- x_size = 65535
132
- if self ._size :
133
- x_size = self ._size [0 ]
134
- x = int (map_range (x , self ._calib [0 ][0 ], self ._calib [0 ][1 ], 0 , x_size ))
135
-
136
- with DigitalInOut (self ._xp_pin ) as x_p :
137
- with DigitalInOut (self ._xm_pin ) as x_m :
138
- with AnalogIn (self ._yp_pin ) as y_p :
139
- x_p .switch_to_output (True )
140
- x_m .switch_to_output (False )
141
- for i in range ( # pylint: disable=consider-using-enumerate
142
- len (self ._ysamples )
143
- ):
144
- self ._ysamples [i ] = y_p .value
145
- y = sum (self ._ysamples ) / len (self ._ysamples )
146
- y_size = 65535
147
- if self ._size :
148
- y_size = self ._size [1 ]
149
- y = int (map_range (y , self ._calib [1 ][0 ], self ._calib [1 ][1 ], 0 , y_size ))
150
-
151
122
z_1 = z_2 = z = None
152
123
with DigitalInOut (self ._xp_pin ) as x_p :
153
124
x_p .switch_to_output (False )
@@ -160,5 +131,35 @@ def touch_point(self): # pylint: disable=too-many-locals
160
131
# print(z_1, z_2)
161
132
z = 65535 - (z_2 - z_1 )
162
133
if z > self ._zthresh :
134
+ with DigitalInOut (self ._yp_pin ) as y_p :
135
+ with DigitalInOut (self ._ym_pin ) as y_m :
136
+ with AnalogIn (self ._xp_pin ) as x_p :
137
+ y_p .switch_to_output (True )
138
+ y_m .switch_to_output (False )
139
+ for i in range ( # pylint: disable=consider-using-enumerate
140
+ len (self ._xsamples )
141
+ ):
142
+ self ._xsamples [i ] = x_p .value
143
+ x = sum (self ._xsamples ) / len (self ._xsamples )
144
+ x_size = 65535
145
+ if self ._size :
146
+ x_size = self ._size [0 ]
147
+ x = int (map_range (x , self ._calib [0 ][0 ], self ._calib [0 ][1 ], 0 , x_size ))
148
+
149
+ with DigitalInOut (self ._xp_pin ) as x_p :
150
+ with DigitalInOut (self ._xm_pin ) as x_m :
151
+ with AnalogIn (self ._yp_pin ) as y_p :
152
+ x_p .switch_to_output (True )
153
+ x_m .switch_to_output (False )
154
+ for i in range ( # pylint: disable=consider-using-enumerate
155
+ len (self ._ysamples )
156
+ ):
157
+ self ._ysamples [i ] = y_p .value
158
+ y = sum (self ._ysamples ) / len (self ._ysamples )
159
+ y_size = 65535
160
+ if self ._size :
161
+ y_size = self ._size [1 ]
162
+ y = int (map_range (y , self ._calib [1 ][0 ], self ._calib [1 ][1 ], 0 , y_size ))
163
+
163
164
return (x , y , z )
164
165
return None
0 commit comments