From 6e69d31c0b44acfb05dafb437721ccb7ebd166c8 Mon Sep 17 00:00:00 2001 From: Glenn Ramsey Date: Sun, 14 Sep 2025 08:01:53 +1200 Subject: [PATCH 1/4] Fix pointer coordinate mapping Previously was using the already mapped x coord to compute the new y coord --- .../py_api_drivers/frozen/indev/pointer_framework.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py index 079c8359..22849ae3 100644 --- a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py +++ b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py @@ -80,8 +80,13 @@ def _get_coords(self): def _calc_coords(self, x, y): if self.is_calibrated: cal = self._cal - x = int(round(x * cal.alphaX + y * cal.betaX + cal.deltaX)) - y = int(round(x * cal.alphaY + y * cal.betaY + cal.deltaY)) + xt, yt = x, y # preserve raw coords + + xs = xt * cal.alphaX + yt * cal.betaX + cal.deltaX + ys = xt * cal.alphaY + yt * cal.betaY + cal.deltaY + + x = int(round(xs)) + y = int(round(ys)) if cal.mirrorX: x = self._orig_width - x - 1 From b1ac8ff2d2ef0d23e0277f374007a7c8f027d88d Mon Sep 17 00:00:00 2001 From: Glenn Ramsey Date: Mon, 15 Sep 2025 08:12:05 +1200 Subject: [PATCH 2/4] Use separate variables for inputs and outputs, add comments --- .../frozen/indev/pointer_framework.py | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py index 22849ae3..6f1c477d 100644 --- a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py +++ b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py @@ -77,36 +77,50 @@ def _get_coords(self): # of (state, x, y) or None if no touch even has occured raise NotImplementedError - def _calc_coords(self, x, y): - if self.is_calibrated: + def _calc_coords(self, xt, yt): + """ + Convert the raw touch coordinates into screen coordinates using + the calibration data if available. + :param xt: The raw x coordinate from the touch device + :param yt: The raw y coordinate from the touch device + :return: The converted (x, y) screen coordinates + """ + + # xs, ys are the transformed screen coordinates + + if self.is_calibrated: cal = self._cal - xt, yt = x, y # preserve raw coords xs = xt * cal.alphaX + yt * cal.betaX + cal.deltaX ys = xt * cal.alphaY + yt * cal.betaY + cal.deltaY - x = int(round(xs)) - y = int(round(ys)) - + # The above transformation should take care of mirroring if the calibration + # data has been collected using the 3 point calbration method. However, + # maybe mirroring would be useful if swapping calibration data between displays + # that are connected with the axes reversed. if cal.mirrorX: - x = self._orig_width - x - 1 + xs = self._orig_width - xs - 1 if cal.mirrorY: - y = self._orig_height - y - 1 + ys = self._orig_height - ys - 1 else: + # Assume touch coordinates map directly to screen coordinates + + xs, ys = xt, yt # initialise in case neither rotation is applied + if ( self._startup_rotation == lv.DISPLAY_ROTATION._180 or # NOQA self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA ): - x = self._orig_width - x - 1 - y = self._orig_height - y - 1 + xs = self._orig_width - xt - 1 + ys = self._orig_height - yt - 1 if ( self._startup_rotation == lv.DISPLAY_ROTATION._90 or # NOQA self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA ): - x, y = self._orig_height - y - 1, x + xs, ys = self._orig_height - yt - 1, xt - return x, y + return int(round(xs)), int(round(ys)) def _read(self, drv, data): # NOQA coords = self._get_coords() From ad26502ebed339135cb8ee63e1760d9fe18c45ea Mon Sep 17 00:00:00 2001 From: Glenn Ramsey Date: Mon, 15 Sep 2025 08:28:45 +1200 Subject: [PATCH 3/4] Update instruction text to match the square target shape drawn on the display --- .../frozen/indev/touch_calibration/touch_calibrate.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api_drivers/py_api_drivers/frozen/indev/touch_calibration/touch_calibrate.py b/api_drivers/py_api_drivers/frozen/indev/touch_calibration/touch_calibrate.py index 28aae3ec..6508b0b6 100644 --- a/api_drivers/py_api_drivers/frozen/indev/touch_calibration/touch_calibrate.py +++ b/api_drivers/py_api_drivers/frozen/indev/touch_calibration/touch_calibrate.py @@ -109,6 +109,7 @@ def calibrate(indev, cal_data): target.remove_flag(lv.obj.FLAG.CHECKABLE) # NOQA target.remove_flag(lv.obj.FLAG.SCROLLABLE) # NOQA + instruction_text = 'Press and hold\n red square' for i in range(3): print('point', i + 1, 'of 3') @@ -119,7 +120,7 @@ def calibrate(indev, cal_data): lcd_bus._pump_main_thread() # NOQA time.sleep_ms(2000) # NOQA - label.set_text('Press and hold\n red circle') + label.set_text(instruction_text) label.center() lcd_bus._pump_main_thread() # NOQA @@ -142,7 +143,7 @@ def calibrate(indev, cal_data): if text_on: label.set_text('') else: - label.set_text('Press and hold\n red circle') + label.set_text(instruction_text) label.center() text_on = not text_on @@ -209,6 +210,7 @@ def calibrate(indev, cal_data): # else: # mirror_y = False + # The 3 point method uses an affine transformation so mirroring should not be needed. mirror_x = False mirror_y = False From 2cfd9678812fb425f29355b6d0aec8db57f5fc05 Mon Sep 17 00:00:00 2001 From: Glenn Ramsey Date: Mon, 15 Sep 2025 17:18:22 +1200 Subject: [PATCH 4/4] Fix: pointer coordinate mapping, wrong x value used in y calculation --- .../frozen/indev/pointer_framework.py | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py index 6f1c477d..f26e66f4 100644 --- a/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py +++ b/api_drivers/py_api_drivers/frozen/indev/pointer_framework.py @@ -77,50 +77,34 @@ def _get_coords(self): # of (state, x, y) or None if no touch even has occured raise NotImplementedError - def _calc_coords(self, xt, yt): - """ - Convert the raw touch coordinates into screen coordinates using - the calibration data if available. - :param xt: The raw x coordinate from the touch device - :param yt: The raw y coordinate from the touch device - :return: The converted (x, y) screen coordinates - """ - - # xs, ys are the transformed screen coordinates - + def _calc_coords(self, x, y): if self.is_calibrated: cal = self._cal - xs = xt * cal.alphaX + yt * cal.betaX + cal.deltaX - ys = xt * cal.alphaY + yt * cal.betaY + cal.deltaY + # save original x value for use in y calculation + xt = x + x = int(round(x * cal.alphaX + y * cal.betaX + cal.deltaX)) + y = int(round(xt * cal.alphaY + y * cal.betaY + cal.deltaY)) - # The above transformation should take care of mirroring if the calibration - # data has been collected using the 3 point calbration method. However, - # maybe mirroring would be useful if swapping calibration data between displays - # that are connected with the axes reversed. if cal.mirrorX: - xs = self._orig_width - xs - 1 + x = self._orig_width - x - 1 if cal.mirrorY: - ys = self._orig_height - ys - 1 + y = self._orig_height - y - 1 else: - # Assume touch coordinates map directly to screen coordinates - - xs, ys = xt, yt # initialise in case neither rotation is applied - if ( self._startup_rotation == lv.DISPLAY_ROTATION._180 or # NOQA self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA ): - xs = self._orig_width - xt - 1 - ys = self._orig_height - yt - 1 + x = self._orig_width - x - 1 + y = self._orig_height - y - 1 if ( self._startup_rotation == lv.DISPLAY_ROTATION._90 or # NOQA self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA ): - xs, ys = self._orig_height - yt - 1, xt + x, y = self._orig_height - y - 1, x - return int(round(xs)), int(round(ys)) + return x, y def _read(self, drv, data): # NOQA coords = self._get_coords()