Skip to content

Commit

Permalink
Fixes touch calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
kdschlosser committed Dec 1, 2024
1 parent 374f6e5 commit dec93ee
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 551 deletions.
59 changes: 19 additions & 40 deletions api_drivers/py_api_drivers/frozen/indev/pointer_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self, touch_cal=None, startup_rotation=lv.DISPLAY_ROTATION._0, debu
self._orig_width = self._width
self._orig_height = self._height
self._set_type(lv.INDEV_TYPE.POINTER) # NOQA
self._cal_running = None
self._startup_rotation = startup_rotation

self._indev_drv.enable(True)
Expand All @@ -45,37 +44,17 @@ def __ip_callback(self, _):
if last_state == self.PRESSED:
lv.refr_now(self._disp_drv)

def __cal_callback(self, alphaX, betaX, deltaX, alphaY, betaY, deltaY):
self._cal.alphaX = alphaX
self._cal.betaX = betaX
self._cal.deltaX = deltaX
self._cal.alphaY = alphaY
self._cal.betaY = betaY
self._cal.deltaY = deltaY
self._cal.save()
self._cal_running = None

def calibrate(self, update_handler=None):
if self._cal_running:
return

import time
def calibrate(self):
import touch_calibrate
self._cal_running = touch_calibrate.TPCal(self, self.__cal_callback)
while self._cal_running:
if update_handler is not None:
delay = update_handler()
time.sleep_ms(delay)
else:
time.sleep_ms(33)

self._indev_drv.set_read_cb(self._read)
if touch_calibrate.calibrate(self, self._cal):
self._cal.save()
return True

return False

@property
def is_calibrated(self):
if self._cal_running:
return False

cal = self._cal

return None not in (
Expand All @@ -98,19 +77,19 @@ def _calc_coords(self, x, y):
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))

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

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
else:
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

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

return x, y

Expand Down
Loading

0 comments on commit dec93ee

Please sign in to comment.