|
8 | 8 | CLOCK_UPDATE_INTERVAL = 1000 # 10 or even 1 ms doesn't seem to change the framerate but 100ms is enough |
9 | 9 | WIFI_ICON_UPDATE_INTERVAL = 1500 |
10 | 10 | TEMPERATURE_UPDATE_INTERVAL = 2000 |
11 | | -#MEMFREE_UPDATE_INTERVAL = 5000 # not too frequent because there's a forced gc.collect() to give it a reliable value |
| 11 | +MEMFREE_UPDATE_INTERVAL = 5000 # not too frequent because there's a forced gc.collect() to give it a reliable value |
12 | 12 |
|
13 | 13 | DRAWER_ANIM_DURATION=300 |
14 | 14 |
|
|
29 | 29 |
|
30 | 30 | foreground_app_name=None |
31 | 31 |
|
| 32 | + |
| 33 | +# Shutdown function to run in main thread |
| 34 | +def shutdown(): |
| 35 | + print("Shutting down...") |
| 36 | + lv.deinit() # Deinitialize LVGL (if supported) |
| 37 | + # Add driver cleanup here |
| 38 | + import sys |
| 39 | + sys.exit(0) |
| 40 | + |
| 41 | + |
32 | 42 | def set_foreground_app(appname): |
33 | 43 | global foreground_app_name |
34 | 44 | foreground_app_name = appname |
@@ -115,9 +125,9 @@ def create_notification_bar(): |
115 | 125 | temp_label = lv.label(notification_bar) |
116 | 126 | temp_label.set_text("00°C") |
117 | 127 | temp_label.align_to(time_label, lv.ALIGN.OUT_RIGHT_MID, NOTIFICATION_BAR_HEIGHT , 0) |
118 | | - #memfree_label = lv.label(notification_bar) |
119 | | - #memfree_label.set_text("") |
120 | | - #memfree_label.align_to(temp_label, lv.ALIGN.OUT_RIGHT_MID, NOTIFICATION_BAR_HEIGHT, 0) |
| 128 | + memfree_label = lv.label(notification_bar) |
| 129 | + memfree_label.set_text("") |
| 130 | + memfree_label.align_to(temp_label, lv.ALIGN.OUT_RIGHT_MID, NOTIFICATION_BAR_HEIGHT, 0) |
121 | 131 | #style = lv.style_t() |
122 | 132 | #style.init() |
123 | 133 | #style.set_text_font(lv.font_montserrat_8) # tiny font |
@@ -175,15 +185,14 @@ def update_temperature(timer): |
175 | 185 | else: |
176 | 186 | temp_label.set_text("42°C") |
177 | 187 |
|
178 | | - |
179 | | - #import gc |
180 | | - #def update_memfree(timer): |
181 | | - # gc.collect() |
182 | | - # memfree_label.set_text(f"{gc.mem_free()}") |
| 188 | + import gc |
| 189 | + def update_memfree(timer): |
| 190 | + gc.collect() |
| 191 | + memfree_label.set_text(f"{gc.mem_free()}") |
183 | 192 |
|
184 | 193 | timer1 = lv.timer_create(update_time, CLOCK_UPDATE_INTERVAL, None) |
185 | 194 | timer2 = lv.timer_create(update_temperature, TEMPERATURE_UPDATE_INTERVAL, None) |
186 | | - #timer3 = lv.timer_create(update_memfree, MEMFREE_UPDATE_INTERVAL, None) |
| 195 | + timer3 = lv.timer_create(update_memfree, MEMFREE_UPDATE_INTERVAL, None) |
187 | 196 | timer4 = lv.timer_create(update_wifi_icon, WIFI_ICON_UPDATE_INTERVAL, None) |
188 | 197 |
|
189 | 198 | # hide bar animation |
@@ -273,10 +282,32 @@ def launcher_event(e): |
273 | 282 | restart_label=lv.label(restart_btn) |
274 | 283 | restart_label.set_text(lv.SYMBOL.POWER+" Reset") |
275 | 284 | restart_label.center() |
276 | | - try: |
| 285 | + def reset_cb(e): |
277 | 286 | import machine |
278 | | - restart_btn.add_event_cb(lambda event: machine.reset(),lv.EVENT.CLICKED,None) |
| 287 | + if hasattr(machine, 'reset'): |
| 288 | + machine.reset() |
| 289 | + elif hasattr(machine, 'soft_reset'): |
| 290 | + machine.soft_reset() |
| 291 | + else: |
| 292 | + print("Warning: machine has no reset or soft_reset method available") |
| 293 | + |
| 294 | + try: |
| 295 | + restart_btn.add_event_cb(reset_cb,lv.EVENT.CLICKED,None) |
279 | 296 | except Exception as e: |
280 | | - print("Warning: not adding machine.reset() callback") |
| 297 | + print("Warning: could not import machine, not adding reset callback") |
281 | 298 |
|
| 299 | + poweroff_btn=lv.button(drawer) |
| 300 | + poweroff_btn.set_size(lv.pct(40),lv.SIZE_CONTENT) |
| 301 | + poweroff_btn.align(lv.ALIGN.BOTTOM_RIGHT,0,0) |
| 302 | + poweroff_label=lv.label(poweroff_btn) |
| 303 | + poweroff_label.set_text(lv.SYMBOL.POWER+" Power Off") |
| 304 | + poweroff_label.center() |
| 305 | + def poweroff_cb(e): |
| 306 | + lv.deinit() # Deinitialize LVGL (if supported) |
| 307 | + import sys |
| 308 | + sys.exit(0) |
282 | 309 |
|
| 310 | + poweroff_btn.add_event_cb(poweroff_cb,lv.EVENT.CLICKED,None) |
| 311 | + |
| 312 | + |
| 313 | + |
0 commit comments