@@ -90,6 +90,8 @@ class Touchscreen:
90
90
readings for the X and Y coordinate planes, respectively.
91
91
Defaults to :const:`((0, 65535), (0, 65535))`
92
92
:param int,int size: The dimensions of the screen as (x, y).
93
+ :param bool invert_pressure: Whether to invert the pressure values. Some touchscreens and
94
+ drivers may need this to be changed to `False` in order to properly register touches.
93
95
94
96
"""
95
97
@@ -104,7 +106,8 @@ def __init__(
104
106
samples : int = 4 ,
105
107
z_threshold : int = 10000 ,
106
108
calibration : Optional [Tuple [Tuple [int , int ], Tuple [int , int ]]] = None ,
107
- size : Optional [Tuple [int , int ]] = None
109
+ size : Optional [Tuple [int , int ]] = None ,
110
+ invert_pressure : bool = True
108
111
) -> None :
109
112
110
113
self ._xm_pin = x1_pin
@@ -119,6 +122,7 @@ def __init__(
119
122
self ._calib = calibration
120
123
self ._size = size
121
124
self ._zthresh = z_threshold
125
+ self .invert_pressure = invert_pressure
122
126
123
127
@property
124
128
def touch_point (
@@ -136,7 +140,10 @@ def touch_point(
136
140
with AnalogIn (self ._yp_pin ) as y_p :
137
141
z_2 = y_p .value
138
142
# print(z_1, z_2)
139
- z = 65535 - (z_2 - z_1 )
143
+ if self .invert_pressure :
144
+ z = 65535 - (z_2 - z_1 )
145
+ else :
146
+ z = z_2 + z_1
140
147
if z > self ._zthresh :
141
148
with DigitalInOut (self ._yp_pin ) as y_p :
142
149
with DigitalInOut (self ._ym_pin ) as y_m :
0 commit comments