Skip to content

Commit e9a21b9

Browse files
committed
refactor/startup/cores3: Refactor code using uasyncio
Signed-off-by: lbuque <[email protected]>
1 parent 7aeb6b8 commit e9a21b9

File tree

9 files changed

+1822
-0
lines changed

9 files changed

+1822
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from startup import Startup
2+
from .framework import Framework
3+
4+
from .apps.status_bar import StatusBarApp
5+
from .apps.settings import SettingsApp
6+
from .apps.dev import DevApp
7+
from .apps.app_run import RunApp
8+
from .apps.app_list import ListApp
9+
from .apps.ezdata import EzDataApp
10+
import M5
11+
12+
import time
13+
14+
15+
class CoreS3_Startup:
16+
def __init__(self) -> None:
17+
self._wlan = Startup()
18+
# self._status_bar = StatusBarApp(None, self._wifi)
19+
20+
def startup(self, ssid: str, pswd: str, timeout: int = 60) -> None:
21+
self._wlan.connect_network(ssid, pswd)
22+
M5.Lcd.drawImage("/system/cores3/boot.png", 0, 0)
23+
time.sleep(0.2)
24+
25+
M5.Lcd.clear(0x000000)
26+
sprite = M5.Lcd.newCanvas(320, 160, 16, True)
27+
28+
fw = Framework()
29+
settings_app = SettingsApp(sprite, data=self._wlan)
30+
dev_app = DevApp(sprite, data=self._wlan)
31+
run_app = RunApp(None)
32+
list_app = ListApp(sprite)
33+
fw.install_bar(StatusBarApp(None, self._wlan))
34+
fw.install_launcher(dev_app)
35+
fw.install(settings_app)
36+
fw.install(dev_app)
37+
fw.install(run_app)
38+
fw.install(list_app)
39+
fw.install(EzDataApp(sprite))
40+
fw.start()

m5stack/modules/startup/cores3/app.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import uasyncio as asyncio
2+
from collections import namedtuple
3+
4+
Descriptor = namedtuple("Descriptor", ["x", "y", "w", "h"])
5+
6+
7+
def generator(d):
8+
try:
9+
len(d)
10+
except TypeError:
11+
cache = []
12+
for i in d:
13+
yield i
14+
cache.append(i)
15+
d = cache
16+
while d:
17+
yield from d
18+
19+
20+
class AppSelector:
21+
def __init__(self, apps: list) -> None:
22+
self._apps = apps
23+
self._id = 0
24+
25+
def prev(self):
26+
self._id = (self._id - 1) % len(self._apps)
27+
return self._apps[self._id]
28+
29+
def next(self):
30+
self._id = (self._id + 1) % len(self._apps)
31+
return self._apps[self._id]
32+
33+
def current(self):
34+
return self._apps[self._id]
35+
36+
def select(self, app):
37+
self._id = self._apps.index(app)
38+
39+
40+
class AppBase:
41+
def __init__(self) -> None:
42+
self._task = None
43+
44+
def on_install(self):
45+
pass
46+
47+
def on_launch(self):
48+
pass
49+
50+
def on_view(self):
51+
pass
52+
53+
def on_ready(self):
54+
self._task = asyncio.create_task(self.on_run())
55+
56+
async def on_run(self):
57+
while True:
58+
await asyncio.sleep_ms(500)
59+
60+
def on_hide(self):
61+
self._task.cancel()
62+
63+
def on_exit(self):
64+
pass
65+
66+
def on_uninstall(self):
67+
pass
68+
69+
def install(self):
70+
self.on_install()
71+
72+
def start(self):
73+
self.on_launch()
74+
self.on_view()
75+
self.on_ready()
76+
77+
def pause(self):
78+
self.on_hide()
79+
80+
def resume(self):
81+
self.on_ready()
82+
83+
def stop(self):
84+
self.on_hide()
85+
self.on_exit()
86+
87+
def uninstall(self):
88+
self.on_uninstall()

0 commit comments

Comments
 (0)