28
28
STARTUP_BG_IMG = '/flash/res/coreink/Startup.bmp'
29
29
FLOW_BG_IMG = '/flash/res/coreink/Flow.bmp'
30
30
CONFIG_BG_IMG = '/flash/res/coreink/Config.bmp'
31
+ APPLIST_BG_IMG = '/flash/res/coreink/AppList.bmp'
31
32
32
33
WIFI_IMG = '/flash/res/coreink/wifi.bmp'
33
34
WIFI_ERR_IMG = '/flash/res/coreink/wifi_err.bmp'
@@ -283,33 +284,11 @@ def _set_server(self, server):
283
284
finally :
284
285
pass
285
286
286
- def _get_cloud_status (self ):
287
- _cloud_status = {
288
- network .STAT_IDLE : 0 ,
289
- network .STAT_CONNECTING : 0 ,
290
- network .STAT_GOT_IP : 1 ,
291
- network .STAT_NO_AP_FOUND : 2 ,
292
- network .STAT_WRONG_PASSWORD : 2 ,
293
- network .STAT_BEACON_TIMEOUT : 2 ,
294
- network .STAT_ASSOC_FAIL : 2 ,
295
- network .STAT_HANDSHAKE_TIMEOUT : 2 ,
296
- }[self ._wifi .connect_status ()]
297
-
298
- if _cloud_status is not 1 or _HAS_SERVER is not True :
299
- return _cloud_status
300
-
301
- if M5Things .status () == 2 :
302
- _cloud_status = 4
303
- else :
304
- _cloud_status = 3
305
- return _cloud_status
306
-
307
287
def _load_data (self ):
308
288
self ._server = self ._get_server ()
309
- self ._cloud_status = self ._get_cloud_status ()
310
289
311
290
def _update_data (self ):
312
- self . _cloud_status = self . _get_cloud_status ()
291
+ pass
313
292
314
293
def _load_view (self , load_bg = True ):
315
294
# bg img
@@ -326,7 +305,6 @@ def _load_view(self, load_bg = True):
326
305
def on_launch (self ):
327
306
DEBUG and print ("Config Launch" )
328
307
self ._server = self ._get_server ()
329
- self ._cloud_status = self ._get_cloud_status ()
330
308
331
309
def on_view (self ):
332
310
self ._ssid_label = Label (
@@ -364,21 +342,11 @@ def on_view(self):
364
342
365
343
async def on_run (self ):
366
344
while True :
367
- t = self ._get_cloud_status ()
368
- if t is not self ._cloud_status :
369
- self ._cloud_status = t
370
- self ._update_data ()
371
- self ._load_view ()
372
- await asyncio .sleep_ms (1000 )
373
- else :
374
- await asyncio .sleep_ms (1000 )
345
+ await asyncio .sleep_ms (1000 )
375
346
376
347
def on_exit (self ):
377
348
DEBUG and print ("Config Exit" )
378
- try :
379
- del self ._ssid_label , self ._server_label
380
- except :
381
- pass
349
+ del self ._ssid_label , self ._server_label
382
350
del self ._bg_img
383
351
384
352
async def _keycode_enter_event_handler (self , fw ):
@@ -400,29 +368,105 @@ async def _keycode_dpad_down_event_handler(self, fw):
400
368
self ._load_view (load_bg = False )
401
369
402
370
371
+ class AppListApp (AppBase ):
372
+ def __init__ (self ) -> None :
373
+ super ().__init__ ()
374
+
375
+ def on_launch (self ):
376
+ self ._bg_img = Image (use_sprite = False )
377
+ self ._bg_img .set_x (0 )
378
+ self ._bg_img .set_y (0 )
379
+ self ._bg_img .set_size (200 , 200 )
380
+
381
+ self ._labels = []
382
+
383
+ self ._files = []
384
+ for file in os .listdir ("apps" ):
385
+ if file .endswith (".py" ):
386
+ self ._files .append (file )
387
+ self ._files_number = len (self ._files )
388
+ self ._cursor_pos = 0
389
+ self ._file_pos = 0
390
+
391
+ def on_view (self ):
392
+ self ._bg_img .set_src (APPLIST_BG_IMG )
393
+
394
+ if len (self ._labels ) is not 5 :
395
+ for i in range (5 ):
396
+ self ._labels .append (Label (
397
+ "" ,
398
+ 14 ,
399
+ 37 + 27 * i ,
400
+ w = 138 ,
401
+ h = 24 ,
402
+ fg_color = 0x000000 ,
403
+ bg_color = 0xFFFFFF ,
404
+ font = M5 .Lcd .FONTS .DejaVu18 ,
405
+ ))
406
+ self ._labels [- 1 ].setLongMode (Label .LONG_DOT )
407
+
408
+ for label , file in zip (self ._labels , self ._files ):
409
+ # print("file:", file)
410
+ file and label and label .setText (file )
411
+
412
+ async def on_run (self ):
413
+ while True :
414
+ await asyncio .sleep_ms (1000 )
415
+
416
+ def on_exit (self ):
417
+ del self ._bg_img , self ._labels , self ._files
418
+
419
+ async def _keycode_enter_event_handler (self , fw ):
420
+ # print("_keycode_enter_event_handler")
421
+ M5 .Lcd .clear ()
422
+ execfile ("apps/" + self ._files [self ._file_pos ])
423
+ sys .exit (0 )
424
+
425
+ async def _keycode_back_event_handler (self , fw ):
426
+ # print("_keycode_back_event_handler")
427
+ pass
428
+
429
+ async def _keycode_dpad_down_event_handler (self , fw ):
430
+ # print("_keycode_dpad_down_event_handler")
431
+ self ._file_pos += 1
432
+
433
+ if self ._file_pos >= len (self ._files ):
434
+ self ._file_pos = 0
435
+
436
+ if self ._file_pos >= len (self ._labels ):
437
+ self ._file_pos = 0
438
+
439
+ for i in range (len (self ._labels )):
440
+ file = self ._files [i ]
441
+ if self ._file_pos == i :
442
+ self ._labels [i ].setText ('>' + file )
443
+ else :
444
+ self ._labels [i ].setText (file )
445
+
446
+
403
447
# CoreInk startup menu
404
448
class CoreInk_Startup :
405
449
def __init__ (self ) -> None :
406
450
self ._wifi = Startup ()
407
451
408
452
def startup (self , ssid : str , pswd : str , timeout : int = 60 ) -> None :
409
453
DEBUG and print ('Corink startup' )
410
- DEBUG and M5 .Lcd .drawCenterString ("Corink startup2" , 100 , 100 )
454
+ # DEBUG and M5.Lcd.drawCenterString("Corink startup2", 100, 100)
411
455
self ._wifi .connect_network (ssid , pswd )
412
456
457
+ M5 .Lcd .drawImage (STARTUP_BG_IMG , 0 , 0 )
458
+
413
459
# bg_img = Image(use_sprite=False)
414
460
# bg_img.set_pos(0, 0)
415
461
# bg_img.set_size(200, 200)
416
462
# bg_img.set_src(STARTUP_BG_IMG)
417
463
418
- # import time
419
- # time.sleep_ms(3000)
464
+ import time
465
+ time .sleep_ms (3000 )
420
466
421
467
flow_app = FlowApp ((self ._wifi , ssid ))
422
468
config_app = ConfigApp ((self ._wifi , ssid ))
469
+ applist_app = AppListApp ()
423
470
424
- fw = Framework ([flow_app , config_app ])
471
+ fw = Framework ([flow_app , config_app , applist_app ])
425
472
asyncio .run (fw .run ())
426
-
427
- coreink = CoreInk_Startup ()
428
- coreink .startup ('Real-Internet' , 'ENIAC2333' )
0 commit comments