Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally don't invert pressure readings. #23

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions adafruit_touchscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Touchscreen:
readings for the X and Y coordinate planes, respectively.
Defaults to :const:`((0, 65535), (0, 65535))`
:param int,int size: The dimensions of the screen as (x, y).
:param bool invert_pressure: Whether to invert the pressure values. Some touchscreens and
drivers may need this to be changed to `False` in order to properly register touches.

"""

Expand All @@ -104,7 +106,8 @@ def __init__(
samples: int = 4,
z_threshold: int = 10000,
calibration: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None,
size: Optional[Tuple[int, int]] = None
size: Optional[Tuple[int, int]] = None,
invert_pressure: bool = True
) -> None:

self._xm_pin = x1_pin
Expand All @@ -119,6 +122,7 @@ def __init__(
self._calib = calibration
self._size = size
self._zthresh = z_threshold
self.invert_pressure = invert_pressure

@property
def touch_point(
Expand All @@ -136,7 +140,10 @@ def touch_point(
with AnalogIn(self._yp_pin) as y_p:
z_2 = y_p.value
# print(z_1, z_2)
z = 65535 - (z_2 - z_1)
if self.invert_pressure:
z = 65535 - (z_2 - z_1)
else:
z = z_2 + z_1
if z > self._zthresh:
with DigitalInOut(self._yp_pin) as y_p:
with DigitalInOut(self._ym_pin) as y_m:
Expand Down