Skip to content

Commit 3926459

Browse files
committed
Optionally don't invert pressure readings.
This is required e.g. on ILI9341. Default to the old behavior to not break any existing projects.
1 parent 0056da9 commit 3926459

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

adafruit_touchscreen.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ def __init__(
104104
samples: int = 4,
105105
z_threshold: int = 10000,
106106
calibration: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None,
107-
size: Optional[Tuple[int, int]] = None
107+
size: Optional[Tuple[int, int]] = None,
108+
invert_pressure: bool = True
108109
) -> None:
109110

110111
self._xm_pin = x1_pin
@@ -119,6 +120,7 @@ def __init__(
119120
self._calib = calibration
120121
self._size = size
121122
self._zthresh = z_threshold
123+
self.invert_pressure = invert_pressure
122124

123125
@property
124126
def touch_point(
@@ -136,7 +138,10 @@ def touch_point(
136138
with AnalogIn(self._yp_pin) as y_p:
137139
z_2 = y_p.value
138140
# print(z_1, z_2)
139-
z = 65535 - (z_2 - z_1)
141+
if self.invert_pressure:
142+
z = 65535 - (z_2 - z_1)
143+
else:
144+
z = z_2 + z_1
140145
if z > self._zthresh:
141146
with DigitalInOut(self._yp_pin) as y_p:
142147
with DigitalInOut(self._ym_pin) as y_m:

0 commit comments

Comments
 (0)