@@ -77,36 +77,50 @@ def _get_coords(self):
77
77
# of (state, x, y) or None if no touch even has occured
78
78
raise NotImplementedError
79
79
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 :
82
92
cal = self ._cal
83
- xt , yt = x , y # preserve raw coords
84
93
85
94
xs = xt * cal .alphaX + yt * cal .betaX + cal .deltaX
86
95
ys = xt * cal .alphaY + yt * cal .betaY + cal .deltaY
87
96
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.
91
101
if cal .mirrorX :
92
- x = self ._orig_width - x - 1
102
+ xs = self ._orig_width - xs - 1
93
103
if cal .mirrorY :
94
- y = self ._orig_height - y - 1
104
+ ys = self ._orig_height - ys - 1
95
105
else :
106
+ # Assume touch coordinates map directly to screen coordinates
107
+
108
+ xs , ys = xt , yt # initialise in case neither rotation is applied
109
+
96
110
if (
97
111
self ._startup_rotation == lv .DISPLAY_ROTATION ._180 or # NOQA
98
112
self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
99
113
):
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
102
116
103
117
if (
104
118
self ._startup_rotation == lv .DISPLAY_ROTATION ._90 or # NOQA
105
119
self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
106
120
):
107
- x , y = self ._orig_height - y - 1 , x
121
+ xs , ys = self ._orig_height - yt - 1 , xt
108
122
109
- return x , y
123
+ return int ( round ( xs )), int ( round ( ys ))
110
124
111
125
def _read (self , drv , data ): # NOQA
112
126
coords = self ._get_coords ()
0 commit comments