Skip to content

Commit 1d6d12c

Browse files
committed
Fix: pointer coordinate mapping, wrong x value used in y calculation
1 parent ad26502 commit 1d6d12c

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

api_drivers/py_api_drivers/frozen/indev/pointer_framework.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,50 +77,34 @@ def _get_coords(self):
7777
# of (state, x, y) or None if no touch even has occured
7878
raise NotImplementedError
7979

80-
def _calc_coords(self, xt, yt):
81-
"""
82-
Convert the raw touch coordinates into screen coordinates using
83-
the calibration data if available.
84-
:param xt: The raw x coordinate from the touch device
85-
:param yt: The raw y coordinate from the touch device
86-
:return: The converted (x, y) screen coordinates
87-
"""
88-
89-
# xs, ys are the transformed screen coordinates
90-
80+
def _calc_coords(self, x, y):
9181
if self.is_calibrated:
9282
cal = self._cal
9383

94-
xs = xt * cal.alphaX + yt * cal.betaX + cal.deltaX
95-
ys = xt * cal.alphaY + yt * cal.betaY + cal.deltaY
84+
# save original x value for use in y calculation
85+
xt = x
86+
x = int(round(x * cal.alphaX + y * cal.betaX + cal.deltaX))
87+
y = int(round(xt * cal.alphaY + y * cal.betaY + cal.deltaY))
9688

97-
# The above transformation should take care of mirroring if the calibration
98-
# data has been collected using the 3 point calbration method. However,
99-
# maybe mirroring would be useful if swapping calibration data between displays
100-
# that are connected with the axes reversed.
10189
if cal.mirrorX:
10290
xs = self._orig_width - xs - 1
10391
if cal.mirrorY:
10492
ys = self._orig_height - ys - 1
10593
else:
106-
# Assume touch coordinates map directly to screen coordinates
107-
108-
xs, ys = xt, yt # initialise in case neither rotation is applied
109-
11094
if (
11195
self._startup_rotation == lv.DISPLAY_ROTATION._180 or # NOQA
11296
self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
11397
):
114-
xs = self._orig_width - xt - 1
115-
ys = self._orig_height - yt - 1
98+
x = self._orig_width - x - 1
99+
y = self._orig_height - y - 1
116100

117101
if (
118102
self._startup_rotation == lv.DISPLAY_ROTATION._90 or # NOQA
119103
self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
120104
):
121-
xs, ys = self._orig_height - yt - 1, xt
105+
x, y = self._orig_height - y - 1, x
122106

123-
return int(round(xs)), int(round(ys))
107+
return x, y
124108

125109
def _read(self, drv, data): # NOQA
126110
coords = self._get_coords()

0 commit comments

Comments
 (0)