Skip to content

Commit b1ac8ff

Browse files
committed
Use separate variables for inputs and outputs, add comments
1 parent 6e69d31 commit b1ac8ff

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

api_drivers/py_api_drivers/frozen/indev/pointer_framework.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,50 @@ 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, x, y):
81-
if self.is_calibrated:
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+
91+
if self.is_calibrated:
8292
cal = self._cal
83-
xt, yt = x, y # preserve raw coords
8493

8594
xs = xt * cal.alphaX + yt * cal.betaX + cal.deltaX
8695
ys = xt * cal.alphaY + yt * cal.betaY + cal.deltaY
8796

88-
x = int(round(xs))
89-
y = int(round(ys))
90-
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.
91101
if cal.mirrorX:
92-
x = self._orig_width - x - 1
102+
xs = self._orig_width - xs - 1
93103
if cal.mirrorY:
94-
y = self._orig_height - y - 1
104+
ys = self._orig_height - ys - 1
95105
else:
106+
# Assume touch coordinates map directly to screen coordinates
107+
108+
xs, ys = xt, yt # initialise in case neither rotation is applied
109+
96110
if (
97111
self._startup_rotation == lv.DISPLAY_ROTATION._180 or # NOQA
98112
self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
99113
):
100-
x = self._orig_width - x - 1
101-
y = self._orig_height - y - 1
114+
xs = self._orig_width - xt - 1
115+
ys = self._orig_height - yt - 1
102116

103117
if (
104118
self._startup_rotation == lv.DISPLAY_ROTATION._90 or # NOQA
105119
self._startup_rotation == lv.DISPLAY_ROTATION._270 # NOQA
106120
):
107-
x, y = self._orig_height - y - 1, x
121+
xs, ys = self._orig_height - yt - 1, xt
108122

109-
return x, y
123+
return int(round(xs)), int(round(ys))
110124

111125
def _read(self, drv, data): # NOQA
112126
coords = self._get_coords()

0 commit comments

Comments
 (0)