From 74fedf4ed2e1926287629d891a389be67a55472e Mon Sep 17 00:00:00 2001 From: Cedar Grove Maker Studios Date: Sat, 29 Apr 2023 10:51:44 -0700 Subject: [PATCH] Limit x and y values to pixel address maximum Limit x and y values to the maximum pixel address rather than screen size. Prevents the touchscreen from generating a pixel address greater than the displayable area. --- adafruit_touchscreen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_touchscreen.py b/adafruit_touchscreen.py index 8ec3a4e..5b2ccca 100644 --- a/adafruit_touchscreen.py +++ b/adafruit_touchscreen.py @@ -158,7 +158,7 @@ def touch_point( x_size = 65535 if self._size: x_size = self._size[0] - x = int(map_range(x, self._calib[0][0], self._calib[0][1], 0, x_size)) + x = int(map_range(x, self._calib[0][0], self._calib[0][1], 0, x_size - 1)) with DigitalInOut(self._xp_pin) as x_p: with DigitalInOut(self._xm_pin) as x_m: @@ -173,7 +173,7 @@ def touch_point( y_size = 65535 if self._size: y_size = self._size[1] - y = int(map_range(y, self._calib[1][0], self._calib[1][1], 0, y_size)) + y = int(map_range(y, self._calib[1][0], self._calib[1][1], 0, y_size - 1)) return (x, y, z) return None