Skip to content

Commit ea58756

Browse files
committed
UI Test ok
1 parent cba43a0 commit ea58756

File tree

3 files changed

+89
-45
lines changed

3 files changed

+89
-45
lines changed

m5stack/fs/system/coreink/AppList.bmp

5.53 KB
Binary file not shown.

m5stack/modules/startup/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def startup(boot_opt, timeout: int = 60) -> None:
154154
elif board_id == M5.BOARD.M5StackCoreInk:
155155
from .coreink import CoreInk_Startup
156156

157-
# coreink = CoreInk_Startup()
158-
# coreink.startup(ssid, pswd, timeout)
157+
coreink = CoreInk_Startup()
158+
coreink.startup(ssid, pswd, timeout)
159159

160160
# Only connect to network, not show any menu
161161
elif boot_opt is BOOT_OPT_NETWORK:

m5stack/modules/startup/coreink.py

Lines changed: 87 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
STARTUP_BG_IMG = '/flash/res/coreink/Startup.bmp'
2929
FLOW_BG_IMG = '/flash/res/coreink/Flow.bmp'
3030
CONFIG_BG_IMG = '/flash/res/coreink/Config.bmp'
31+
APPLIST_BG_IMG = '/flash/res/coreink/AppList.bmp'
3132

3233
WIFI_IMG = '/flash/res/coreink/wifi.bmp'
3334
WIFI_ERR_IMG = '/flash/res/coreink/wifi_err.bmp'
@@ -283,33 +284,11 @@ def _set_server(self, server):
283284
finally:
284285
pass
285286

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-
307287
def _load_data(self):
308288
self._server = self._get_server()
309-
self._cloud_status = self._get_cloud_status()
310289

311290
def _update_data(self):
312-
self._cloud_status = self._get_cloud_status()
291+
pass
313292

314293
def _load_view(self, load_bg = True):
315294
# bg img
@@ -326,7 +305,6 @@ def _load_view(self, load_bg = True):
326305
def on_launch(self):
327306
DEBUG and print("Config Launch")
328307
self._server = self._get_server()
329-
self._cloud_status = self._get_cloud_status()
330308

331309
def on_view(self):
332310
self._ssid_label = Label(
@@ -364,21 +342,11 @@ def on_view(self):
364342

365343
async def on_run(self):
366344
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)
375346

376347
def on_exit(self):
377348
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
382350
del self._bg_img
383351

384352
async def _keycode_enter_event_handler(self, fw):
@@ -400,29 +368,105 @@ async def _keycode_dpad_down_event_handler(self, fw):
400368
self._load_view(load_bg=False)
401369

402370

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+
403447
# CoreInk startup menu
404448
class CoreInk_Startup:
405449
def __init__(self) -> None:
406450
self._wifi = Startup()
407451

408452
def startup(self, ssid: str, pswd: str, timeout: int = 60) -> None:
409453
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)
411455
self._wifi.connect_network(ssid, pswd)
412456

457+
M5.Lcd.drawImage(STARTUP_BG_IMG, 0, 0)
458+
413459
# bg_img = Image(use_sprite=False)
414460
# bg_img.set_pos(0, 0)
415461
# bg_img.set_size(200, 200)
416462
# bg_img.set_src(STARTUP_BG_IMG)
417463

418-
# import time
419-
# time.sleep_ms(3000)
464+
import time
465+
time.sleep_ms(3000)
420466

421467
flow_app = FlowApp((self._wifi, ssid))
422468
config_app = ConfigApp((self._wifi, ssid))
469+
applist_app = AppListApp()
423470

424-
fw = Framework([flow_app, config_app])
471+
fw = Framework([flow_app, config_app, applist_app])
425472
asyncio.run(fw.run())
426-
427-
coreink = CoreInk_Startup()
428-
coreink.startup('Real-Internet', 'ENIAC2333')

0 commit comments

Comments
 (0)