@@ -24,7 +24,6 @@ def __init__(self, touch_cal=None, startup_rotation=lv.DISPLAY_ROTATION._0, debu
2424 self ._orig_width = self ._width
2525 self ._orig_height = self ._height
2626 self ._set_type (lv .INDEV_TYPE .POINTER ) # NOQA
27- self ._cal_running = None
2827 self ._startup_rotation = startup_rotation
2928
3029 self ._indev_drv .enable (True )
@@ -45,37 +44,17 @@ def __ip_callback(self, _):
4544 if last_state == self .PRESSED :
4645 lv .refr_now (self ._disp_drv )
4746
48- def __cal_callback (self , alphaX , betaX , deltaX , alphaY , betaY , deltaY ):
49- self ._cal .alphaX = alphaX
50- self ._cal .betaX = betaX
51- self ._cal .deltaX = deltaX
52- self ._cal .alphaY = alphaY
53- self ._cal .betaY = betaY
54- self ._cal .deltaY = deltaY
55- self ._cal .save ()
56- self ._cal_running = None
57-
58- def calibrate (self , update_handler = None ):
59- if self ._cal_running :
60- return
61-
62- import time
47+ def calibrate (self ):
6348 import touch_calibrate
64- self ._cal_running = touch_calibrate .TPCal (self , self .__cal_callback )
65- while self ._cal_running :
66- if update_handler is not None :
67- delay = update_handler ()
68- time .sleep_ms (delay )
69- else :
70- time .sleep_ms (33 )
7149
72- self ._indev_drv .set_read_cb (self ._read )
50+ if touch_calibrate .calibrate (self , self ._cal ):
51+ self ._cal .save ()
52+ return True
53+
54+ return False
7355
7456 @property
7557 def is_calibrated (self ):
76- if self ._cal_running :
77- return False
78-
7958 cal = self ._cal
8059
8160 return None not in (
@@ -98,19 +77,19 @@ def _calc_coords(self, x, y):
9877 cal = self ._cal
9978 x = int (round (x * cal .alphaX + y * cal .betaX + cal .deltaX ))
10079 y = int (round (x * cal .alphaY + y * cal .betaY + cal .deltaY ))
101-
102- if (
103- self ._startup_rotation == lv .DISPLAY_ROTATION ._180 or # NOQA
104- self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
105- ):
106- x = self ._orig_width - x - 1
107- y = self ._orig_height - y - 1
108-
109- if (
110- self ._startup_rotation == lv .DISPLAY_ROTATION ._90 or # NOQA
111- self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
112- ):
113- x , y = self ._orig_height - y - 1 , x
80+ else :
81+ if (
82+ self ._startup_rotation == lv .DISPLAY_ROTATION ._180 or # NOQA
83+ self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
84+ ):
85+ x = self ._orig_width - x - 1
86+ y = self ._orig_height - y - 1
87+
88+ if (
89+ self ._startup_rotation == lv .DISPLAY_ROTATION ._90 or # NOQA
90+ self ._startup_rotation == lv .DISPLAY_ROTATION ._270 # NOQA
91+ ):
92+ x , y = self ._orig_height - y - 1 , x
11493
11594 return x , y
11695
0 commit comments