Skip to content

Commit 560a97b

Browse files
committed
prefect/startup/fire: Unified management of image resources
Signed-off-by: lbuque <[email protected]>
1 parent 37f4365 commit 560a97b

File tree

7 files changed

+155
-58
lines changed

7 files changed

+155
-58
lines changed

m5stack/modules/startup/fire/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from .apps.app_list import ListApp
88
from .apps.ezdata import EzDataApp
99
import time
10-
11-
BK_IMG = "/system/stack/logo.png"
10+
from .res import LOGO_IMG
1211

1312

1413
class Sprite:
@@ -30,7 +29,7 @@ def startup(self, ssid: str, pswd: str, timeout: int = 60) -> None:
3029
M5.Speaker.setVolume(80)
3130
M5.Speaker.tone(4000, 50)
3231

33-
M5.Lcd.drawImage(BK_IMG)
32+
M5.Lcd.drawImage(LOGO_IMG)
3433
time.sleep_ms(200)
3534

3635
sprite = M5.Lcd.newCanvas(320, 184, 16, True)

m5stack/modules/startup/fire/apps/app_list.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
import M5
66
import os
77
import sys
8+
from ..res import (
9+
APPLIST_UNSELECTED_IMG,
10+
APPLIST_SELECTED_IMG,
11+
APPLIST_IMG,
12+
BAR5_IMG,
13+
APPLIST_LEFT_IMG,
14+
APPLIST_RIGHT_IMG,
15+
)
816

917

1018
class Rectangle:
@@ -60,7 +68,7 @@ def __init__(self, icos: dict, data=None) -> None:
6068
pass
6169

6270
def on_install(self):
63-
M5.Lcd.drawImage("/system/fire/appList_unselected.png", 5 + 62 * 3, 0)
71+
M5.Lcd.drawImage(APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
6472

6573
def on_launch(self):
6674
self._files = FileList("apps")
@@ -69,14 +77,14 @@ def on_launch(self):
6977
self._file_pos = 0
7078

7179
def on_view(self):
72-
M5.Lcd.drawImage("/system/fire/appList_selected.png", 5 + 62 * 3, 0)
80+
M5.Lcd.drawImage(APPLIST_SELECTED_IMG, 5 + 62 * 3, 0)
7381

7482
self._bg_img = Image(use_sprite=False)
7583
self._bg_img.set_pos(4, 56 + 4)
7684
self._bg_img.set_size(312, 156)
77-
self._bg_img.set_src("/system/fire/applist.png")
85+
self._bg_img.set_src(APPLIST_IMG)
7886

79-
M5.Lcd.drawImage("/system/fire/bar5.png", 0, 220)
87+
M5.Lcd.drawImage(BAR5_IMG, 0, 220)
8088

8189
self._line_spacing = 36 + 2 + 2
8290
self._left_cursor_x = 4
@@ -90,7 +98,7 @@ def on_view(self):
9098
self._left_img = Image(use_sprite=False)
9199
self._left_img.set_pos(self._left_cursor_x, self._left_cursor_y)
92100
self._left_img.set_size(10, 36)
93-
self._left_img.set_src("/system/fire/applistLeft.png")
101+
self._left_img.set_src(APPLIST_LEFT_IMG)
94102

95103
self._right_cursor_x = 320 - 4 - 60 - 10
96104
self._right_cursor_y = (56 + 4) + 2
@@ -103,7 +111,7 @@ def on_view(self):
103111
self._right_img = Image(use_sprite=False)
104112
self._right_img.set_pos(self._right_cursor_x, self._right_cursor_y)
105113
self._right_img.set_size(10, 36)
106-
self._right_img.set_src("/system/fire/applistRight.png")
114+
self._right_img.set_src(APPLIST_RIGHT_IMG)
107115

108116
self._label0 = Label(
109117
"",
@@ -158,7 +166,7 @@ def on_view(self):
158166
file and label and label.setText(file)
159167

160168
def on_exit(self):
161-
M5.Lcd.drawImage("/system/fire/appList_unselected.png", 5 + 62 * 3, 0)
169+
M5.Lcd.drawImage(APPLIST_UNSELECTED_IMG, 5 + 62 * 3, 0)
162170
del self._bg_img, self._left_img, self._right_img
163171
del self._label0, self._label1, self._label2, self._label3, self._labels
164172
del self._files

m5stack/modules/startup/fire/apps/app_run.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import machine
99
import os
1010
import time
11+
from ..res import (
12+
APPRUN_UNSELECTED_IMG,
13+
APPRUN_SELECTED_IMG,
14+
RUN_IMG,
15+
BAR4_IMG,
16+
)
1117

1218
try:
1319
import M5Things
@@ -22,21 +28,16 @@ def __init__(self, icos: dict, data=None) -> None:
2228
super().__init__()
2329

2430
def on_install(self):
25-
M5.Lcd.drawImage("/system/fire/appRun_unselected.png", 5 + 62 * 2, 0)
31+
M5.Lcd.drawImage(APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
2632

2733
def on_launch(self):
2834
self._mtime_text, self._account_text, self._ver_text = self._get_file_info("main.py")
2935

3036
def on_view(self):
31-
# M5.Lcd.clear()
32-
# M5.Lcd.drawImage("/system/fire/setting_unselected.png", 5 + 62 * 0, 0)
33-
# M5.Lcd.drawImage("/system/fire/develop_unselected.png", 5 + 62 * 1, 0)
34-
M5.Lcd.drawImage("/system/fire/appRun_selected.png", 5 + 62 * 2, 0)
35-
# M5.Lcd.drawImage("/system/fire/appList_unselected.png", 5 + 62 * 3, 0)
36-
# M5.Lcd.drawImage("/system/fire/ezdata_unselected.png", 5 + 62 * 4, 0)
37+
M5.Lcd.drawImage(APPRUN_SELECTED_IMG, 5 + 62 * 2, 0)
3738

38-
M5.Lcd.drawImage("/system/fire/run.png", 4, 56 + 4)
39-
M5.Lcd.drawImage("/system/fire/bar4.png", 0, 220)
39+
M5.Lcd.drawImage(RUN_IMG, 4, 56 + 4)
40+
M5.Lcd.drawImage(BAR4_IMG, 0, 220)
4041

4142
self._name_label = Label(
4243
"name",
@@ -89,20 +90,17 @@ def on_hide(self):
8990
pass
9091

9192
def on_exit(self):
92-
M5.Lcd.drawImage("/system/fire/appRun_unselected.png", 5 + 62 * 2, 0)
93+
M5.Lcd.drawImage(APPRUN_UNSELECTED_IMG, 5 + 62 * 2, 0)
9394
del self._name_label, self._mtime_label, self._account_label, self._ver_label
9495

9596
async def _btna_event_handler(self, fw):
96-
# print("_btna_event_handler")
9797
pass
9898

9999
async def _btnb_event_handler(self, fw):
100-
# print("_btnb_event_handler")
101100
execfile("main.py")
102101
sys.exit(0)
103102

104103
async def _btnc_event_handler(self, fw):
105-
# print("_btnc_event_handler")
106104
nvs = esp32.NVS("uiflow")
107105
nvs.set_u8("boot_option", 2)
108106
nvs.commit()

m5stack/modules/startup/fire/apps/dev.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,28 @@
1515

1616
from common.font import MontserratMedium10
1717
from common.font import MontserratMedium18
18-
18+
from ..res import (
19+
WIFI_EMPTY_IMG,
20+
WIFI_GOOD_IMG,
21+
WIFI_MID_IMG,
22+
WIFI_WORSE_IMG,
23+
WIFI_DISCONNECTED_IMG,
24+
SERVER_EMPTY_IMG,
25+
SERVER_GREEN_IMG,
26+
SERVER_ERROR_IMG,
27+
DEVELOP_UNSELECTED_IMG,
28+
DEVELOP_SELECTED_IMG,
29+
DEVELOP_PRIVATE_IMG,
30+
DEVELOP_PUBLIC_IMG,
31+
BAR2_IMG,
32+
BAR3_IMG,
33+
BATTERY_RED_CHARGE_IMG,
34+
BATTERY_RED_IMG,
35+
BATTERY_GREEN_CHARGE_IMG,
36+
BATTERY_GREEN_IMG,
37+
BATTERY_BLACK_CHARGE_IMG,
38+
BATTERY_BLACK_IMG,
39+
)
1940
import os
2041
import binascii
2142
import machine
@@ -44,17 +65,17 @@ class CloudStatus:
4465

4566

4667
_NETWORK_STATUS_ICOS = {
47-
NetworkStatus.INIT: "/system/fire/WiFi/wifi_empty.png",
48-
NetworkStatus.RSSI_GOOD: "/system/fire/WiFi/wifi_good.png",
49-
NetworkStatus.RSSI_MID: "/system/fire/WiFi/wifi_mid.png",
50-
NetworkStatus.RSSI_WORSE: "/system/fire/WiFi/wifi_worse.png",
51-
NetworkStatus.DISCONNECTED: "/system/fire/WiFi/wifi_disconnected.png",
68+
NetworkStatus.INIT: WIFI_EMPTY_IMG,
69+
NetworkStatus.RSSI_GOOD: WIFI_GOOD_IMG,
70+
NetworkStatus.RSSI_MID: WIFI_MID_IMG,
71+
NetworkStatus.RSSI_WORSE: WIFI_WORSE_IMG,
72+
NetworkStatus.DISCONNECTED: WIFI_DISCONNECTED_IMG,
5273
}
5374

5475
_CLOUD_STATUS_ICOS = {
55-
CloudStatus.INIT: "/system/fire/Server/server_empty.png",
56-
CloudStatus.CONNECTED: "/system/fire/Server/Server_Green.png",
57-
CloudStatus.DISCONNECTED: "/system/fire/Server/server_error.png",
76+
CloudStatus.INIT: SERVER_EMPTY_IMG,
77+
CloudStatus.CONNECTED: SERVER_GREEN_IMG,
78+
CloudStatus.DISCONNECTED: SERVER_ERROR_IMG,
5879
}
5980

6081

@@ -65,7 +86,7 @@ def __init__(self, icos: dict, data=None) -> None:
6586
super().__init__()
6687

6788
def on_install(self):
68-
M5.Lcd.drawImage("/system/fire/develop_unselected.png", 5 + 62 * 1, 0)
89+
M5.Lcd.drawImage(DEVELOP_UNSELECTED_IMG, 5 + 62 * 1, 0)
6990

7091
def on_launch(self):
7192
self._mac_text = self._get_mac()
@@ -83,7 +104,7 @@ def on_launch(self):
83104
self._avatar_src = self._get_avatar()
84105

85106
def on_view(self):
86-
M5.Lcd.drawImage("/system/fire/develop_selected.png", 5 + 62 * 1, 0)
107+
M5.Lcd.drawImage(DEVELOP_SELECTED_IMG, 5 + 62 * 1, 0)
87108
self._origin_x = 0
88109
self._origin_y = 56
89110
self._lcd.clear()
@@ -230,21 +251,18 @@ async def on_run(self):
230251
await asyncio.sleep_ms(1500)
231252

232253
def on_exit(self):
233-
M5.Lcd.drawImage("/system/fire/develop_unselected.png", 5 + 62 * 1, 0)
254+
M5.Lcd.drawImage(DEVELOP_UNSELECTED_IMG, 5 + 62 * 1, 0)
234255
del self._bg_img, self._mac_label, self._account_label, self._avatar_img
235256
del self._bar_img, self._network_img, self._cloud_img, self._battery_img
236257
del self._battery_label
237258

238259
async def _btna_event_handler(self, fw):
239-
# print("_btna_event_handler")
240260
pass
241261

242262
async def _btnb_event_handler(self, fw):
243-
# print("_btnb_event_handler")
244263
pass
245264

246265
async def _btnc_event_handler(self, fw):
247-
# print("_btnc_event_handler")
248266
pass
249267

250268
async def _dl_avatar(self, dst):

m5stack/modules/startup/fire/apps/ezdata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from ..app import AppBase
22
import M5
3+
from ..res import EZDATA_UNSELECTED_IMG, EZDATA_SELECTED_IMG
34

45

56
class EzDataApp(AppBase):
@@ -8,10 +9,10 @@ def __init__(self, icos) -> None:
89
super().__init__()
910

1011
def on_install(self):
11-
M5.Lcd.drawImage("/system/fire/ezdata_unselected.png", 5 + 62 * 4, 0)
12+
M5.Lcd.drawImage(EZDATA_UNSELECTED_IMG, 5 + 62 * 4, 0)
1213

1314
def on_view(self):
14-
M5.Lcd.drawImage("/system/fire/ezdata_selected.png", 5 + 62 * 4, 0)
15+
M5.Lcd.drawImage(EZDATA_SELECTED_IMG, 5 + 62 * 4, 0)
1516

1617
self._origin_x = 0
1718
self._origin_y = 56
@@ -25,7 +26,7 @@ def on_hide(self):
2526
pass
2627

2728
def on_exit(self):
28-
M5.Lcd.drawImage("/system/fire/ezdata_unselected.png", 5 + 62 * 4, 0)
29+
M5.Lcd.drawImage(EZDATA_UNSELECTED_IMG, 5 + 62 * 4, 0)
2930
self._lcd.clear()
3031
self._lcd.push(self._origin_x, self._origin_y)
3132

0 commit comments

Comments
 (0)