2828style .set_shadow_width (0 )
2929
3030
31- def build_crosshair (scrn ):
31+ def build_crosshair (scrn , img , scale , color_step ):
3232canvas = lv .canvas (scrn )
3333canvas .add_style (style ,0 )
3434canvas .set_size (89 ,89 )
@@ -54,17 +54,23 @@ def build_crosshair(scrn):
5454
5555lv .draw_arc (layer ,desc )
5656
57- for radius ,color , opa in (
58- (39 ,0xFFFFFF ,255 ),
59- (34 ,0xFFFFFF ,255 ),
60- (19 ,0xFFFFFF ,255 ),
61- (9 ,0x727171 ,207 ),
62- (8 ,0xDD1919 ,190 ),
63- (4 ,0xBABABA ,192 )
64- ):
57+ for i , ( radius ,na_color , a_color , opa ) in enumerate ( (
58+ (39 ,0xFF0000 , 0x00FF00 ,255 ),
59+ (34 ,0xFF0000 , 0x00FF00 ,255 ),
60+ (19 ,0xFF0000 , 0x00FF00 ,255 ),
61+ (9 ,0x6D0000 , 0x006D00 ,207 ),
62+ (8 ,0xDD1919 ,0x19DD19 , 190 ),
63+ (4 ,0xB20000 , 0x00B200 ,192 )
64+ )) :
6565desc = lv .draw_arc_dsc_t ()
6666desc .init ()
6767
68+
69+ if i <= color_step :
70+ color = a_color
71+ else :
72+ color = na_color
73+
6874desc .color = lv .color_hex (color )
6975desc .width = 1
7076desc .start_angle = 0
@@ -112,6 +118,7 @@ def build_crosshair(scrn):
112118 ):
113119canvas .set_px (x ,y ,lv .color_hex (0xD82424 ),186 )
114120
121+ # tested
115122for (x1 ,y1 ), (x2 ,y2 )in (
116123 ((34 ,34 ), (37 ,37 )),
117124 ((54 ,34 ), (51 ,37 )),
@@ -135,34 +142,57 @@ def build_crosshair(scrn):
135142
136143lv .draw_line (layer ,desc )
137144
138- for a ,b in (
139- (24 ,18 ),
140- (27 ,23 ),
141- (32 ,26 ),
145+ for item in (
142146 (35 ,31 ),
143- (64 ,18 ),
144- (61 ,23 ),
145- (56 ,26 ),
146- (53 ,31 ),
147+ (32 ,26 ),
148+ (27 ,23 ),
149+ (24 ,18 ),
147150 (64 ,70 ),
148151 (61 ,65 ),
149152 (56 ,62 ),
150- (53 ,57 )
153+ (53 ,57 ),
154+ (53 ,31 ,56 ,34 ),
155+ (56 ,26 ,61 ,31 ),
156+ (61 ,23 ,64 ,26 ),
157+ (64 ,18 ,69 ,23 ),
151158 ):
152159
153160desc = lv .draw_line_dsc_t ()
154161desc .init ()
155- desc .p1 .x = a
156- desc .p1 .y = b
157- desc .p2 .x = b
158- desc .p2 .y = a
159162desc .color = lv .color_hex (0xFFFFFF )
160163desc .width = 1
161164desc .opa = 255
162165desc .blend_mode = lv .BLEND_MODE .NORMAL
163166desc .round_start = 0
164167desc .round_end = 0
165168
169+ if len (item )== 2 :
170+ a ,b = item
171+ desc .p1 .x = a
172+ desc .p1 .y = b
173+ desc .p2 .x = b
174+ desc .p2 .y = a
175+ else :
176+ a ,b ,c ,d = item
177+ desc .p1 .x = a
178+ desc .p1 .y = b
179+ desc .p2 .x = c
180+ desc .p2 .y = d
181+
182+ desc2 = lv .draw_line_dsc_t ()
183+ desc2 .init ()
184+ desc2 .color = lv .color_hex (0xFFFFFF )
185+ desc2 .width = 1
186+ desc2 .opa = 255
187+ desc2 .blend_mode = lv .BLEND_MODE .NORMAL
188+ desc2 .round_start = 0
189+ desc2 .round_end = 0
190+ desc2 .p1 .x = b
191+ desc2 .p1 .y = a
192+ desc2 .p2 .x = d
193+ desc2 .p2 .y = c
194+ lv .draw_line (layer ,desc2 )
195+
166196lv .draw_line (layer ,desc )
167197
168198for (x1 ,y1 ), (x2 ,y2 )in (
@@ -193,12 +223,10 @@ def build_crosshair(scrn):
193223
194224canvas .finish_layer (layer )
195225
196- image = lv .image (scrn )
197- image .add_style (style ,0 )
198- image .set_style_bg_opa (0 ,0 )
199- image .set_size (89 ,89 )
200- image .set_src (canvas .get_image ())
201- return image
226+ img .set_src (canvas .get_image ())
227+ img .set_scale (scale )
228+
229+ canvas .delete ()
202230
203231
204232class Tpcal_point (object ):
@@ -245,20 +273,9 @@ def __init__(self, indev, callback):
245273disp = indev .get_disp ()
246274disp .set_default ()
247275
248- width = self .width = disp .get_physical_horizontal_resolution ()
249- height = self .height = disp .get_physical_vertical_resolution ()
276+ width = self .width = disp ._physical_width
277+ height = self .height = disp ._physical_height
250278
251- hor_margin = width * 0.15
252- ver_margin = height * 0.15
253- margin = hor_margin if hor_margin < ver_margin else ver_margin
254-
255- self .points = [
256- Tpcal_point (x = int (margin ),y = int (height * 0.3 )),
257- Tpcal_point (x = int (width * 0.4 ),y = int (height - margin )),
258- Tpcal_point (x = int (width - margin ),y = int (margin ))
259- ]
260-
261- self .curr_point = self .points [0 ]
262279self .curr_scrn = disp .get_screen_active ()
263280
264281self .scr = lv .obj (None )
@@ -272,34 +289,47 @@ def __init__(self, indev, callback):
272289
273290self .run_again_timer = None
274291
275- self .crosshair = build_crosshair (self .scr )
292+ self .crosshair = lv .image (self .scr )
293+ self .crosshair .add_style (style ,0 )
294+ self .crosshair .set_style_bg_opa (0 ,0 )
295+ self .crosshair .set_size (89 ,89 )
276296
277- crosshair_size = int (math .sqrt ((width * height )>> 5 ))
278- crosshair_scale = int (crosshair_size / 89.0 * 256.0 )
279- self .crosshair .set_scale (crosshair_scale )
280- self .crosshair .set_size (crosshair_size ,crosshair_size )
281- self .cross_offset = int (crosshair_size / 2 )
297+ self .crosshair_size = int (math .sqrt ((width * height )>> 5 ))
298+ self .crosshair_scale = int (self .crosshair_size / 89.0 * 256.0 )
299+ self .crosshair .set_size (self .crosshair_size ,self .crosshair_size )
300+ self .cross_offset = int (self .crosshair_size / 2 )
282301
283- self .crosshair .set_pos (
284- self .curr_point .x - self .cross_offset ,
285- self .curr_point .y - self .cross_offset
286- )
302+ build_crosshair (self .scr ,self .crosshair ,self .crosshair_scale ,- 1 )
303+
304+ self .crosshair .set_pos (0 ,0 )
305+
306+ self .points = [
307+ Tpcal_point (x = self .cross_offset ,y = self .cross_offset ),
308+ Tpcal_point (x = self .cross_offset ,y = int (height - self .cross_offset )),
309+ Tpcal_point (x = int (width - self .cross_offset ),y = self .cross_offset )
310+ ]
311+
312+ self .curr_point = self .points [0 ]
287313
288314self .run_again_button = lv .button (self .scr )
289315self .run_again_button .add_flag (lv .obj .FLAG .HIDDEN )
290316self .run_again_button .remove_flag (lv .obj .FLAG .CLICKABLE )
317+
318+ self .run_again_button .add_event_cb (self .on_recalibrate ,lv .EVENT .CLICKED ,None )
291319
292320self .ok_button = lv .button (self .scr )
293321self .ok_button .add_flag (lv .obj .FLAG .HIDDEN )
294322self .ok_button .remove_flag (lv .obj .FLAG .CLICKABLE )
295-
323+
324+ self .ok_button .add_event_cb (self .on_ok ,lv .EVENT .CLICKED ,None )
325+
296326run_again_label = self .run_again_label = lv .label (self .run_again_button )
297327run_again_label .set_text ("Run Again (30)" )
298328ok_label = lv .label (self .ok_button )
299329ok_label .set_text ("OK" )
300330
301- self .ok_button .set_size (50 ,lv .SIZE_CONTENT )
302- self .run_again_button .set_size (50 ,lv .SIZE_CONTENT )
331+ self .ok_button .set_size (lv . SIZE_CONTENT ,lv .SIZE_CONTENT )
332+ self .run_again_button .set_size (lv . SIZE_CONTENT ,lv .SIZE_CONTENT )
303333
304334run_again_label .center ()
305335ok_label .center ()
@@ -334,6 +364,9 @@ def __init__(self, indev, callback):
334364self .betaY = None
335365self .deltaY = None
336366
367+ self .run_count = 30
368+
369+ self .scr .add_event_cb (self .on_press ,lv .EVENT .PRESSED ,None )
337370indev ._indev_drv .set_read_cb (self .on_touch )# NOQA
338371
339372def on_ok (self ,_ ):
@@ -366,12 +399,6 @@ def on_touch(self, _, data):
366399
367400if None not in (x ,y ):
368401self .indev ._last_x ,self .indev ._last_y = x ,y
369- if coords is None :
370- data .continue_reading = False
371- else :
372- data .continue_reading = True
373- else :
374- data .continue_reading = False
375402
376403data .point .x ,data .point .y = (
377404self .indev ._last_x ,self .indev ._last_y
@@ -411,34 +438,37 @@ def on_recalibrate(self, _):
411438self .ok_button .remove_flag (lv .obj .FLAG .CLICKABLE )
412439
413440for point in self .points :
414- point .x = 0
415- point .y = 0
441+ point .touched_point . x = 0
442+ point .touched_point . y = 0
416443
417444self .curr_point = self .points [0 ]
418- self .crosshair .set_pos (
419- self .curr_point .x - self .cross_offset ,
420- self .curr_point .y - self .cross_offset
421- )
422- self .crosshair .add_flag (lv .obj .FLAG .CLICKABLE )
445+ self .crosshair .set_pos (0 ,0 )
423446
447+ self .scr .add_event_cb (self .on_press ,lv .EVENT .PRESSED ,None )
424448self .scr .remove_event_cb (self .on_scr_click )
425449
426450def on_run_again_timer (self ,_ ):
427- remaining_runs = 30 - self .run_again_timer .run_cnt
451+ self .run_count -= 1
452+
453+ label = str (self .run_count )
454+ if len (label )!= 2 :
455+ label = '0' + label
428456
429457self .run_again_label .set_text (
430- f"Run Again ({ str ( remaining_runs ). zfill ( 2 ) } )"
458+ f"Run Again ({ label } )"
431459 )
432460
433- if remaining_runs == 0 :
461+ if self .run_count == 0 :
462+ self .run_count = 30
434463self .on_recalibrate (None )
435464
436- def on_click (self ):
465+ def on_press (self , _ ):
437466self .indev .get_point (self .curr_point .touched_point )
438467index = self .points .index (self .curr_point )+ 1
468+
439469if index == len (self .points ):
440470self .crosshair .remove_flag (lv .obj .FLAG .CLICKABLE )
441-
471+ self . run_count = 30
442472self .run_again_label .set_text ("Run Again (30)" )
443473
444474self .run_again_button .add_flag (lv .obj .FLAG .CLICKABLE )
@@ -490,7 +520,8 @@ def on_click(self):
490520tp1 .y * (sp3 .y * tp2 .x - sp2 .y * tp3 .x )
491521 )/ divisor
492522
493- self .scr .add_event_cb (self .on_scr_click ,lv .EVENT .CLICK ,None )
523+ self .scr .remove_event_cb (self .on_press )
524+ self .scr .add_event_cb (self .on_scr_click ,lv .EVENT .PRESSED ,None )
494525
495526else :
496527self .curr_point = self .points [index ]