Skip to content

Commit 23a3bc4

Browse files
main.py: tweaks for unix (desktop) target
1 parent ab43dc4 commit 23a3bc4

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

internal_filesystem/main.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131

3232
# lowering the duration from default 33 to 6 seems to increase the camera framerate from 5.5 to 9 and the UI framerate from 15 to 20fps
3333
# lowering to 1 doesn't seem to help out the camera framerate (so it's maxed out) but the UI goes to 26 FPS with it!
34-
#th = task_handler.TaskHandler()
35-
th = task_handler.TaskHandler(duration=1)
34+
# but that seems to cause a sporadic hang in the launcher on the desktop builds, so take at least 2 for now:
35+
#th = task_handler.TaskHandler()
36+
th = task_handler.TaskHandler(duration=2)
3637

3738
rootscreen = lv.screen_active()
3839
rootlabel = lv.label(rootscreen)
@@ -77,7 +78,7 @@ def close_bar():
7778
notification_bar.set_style_radius(0, 0)
7879
# Time label
7980
time_label = lv.label(notification_bar)
80-
time_label.set_text("00:00:00.000")
81+
time_label.set_text("00:00:00")
8182
time_label.align(lv.ALIGN.LEFT_MID, 0, 0)
8283
temp_label = lv.label(notification_bar)
8384
temp_label.set_text("00°C")
@@ -113,22 +114,34 @@ def update_time(timer):
113114
hours = (ticks // 3600000) % 24
114115
minutes = (ticks // 60000) % 60
115116
seconds = (ticks // 1000) % 60
116-
milliseconds = ticks % 1000
117+
#milliseconds = ticks % 1000
117118
time_label.set_text(f"{hours:02d}:{minutes:02d}:{seconds:02d}")
118119

119-
import network
120+
can_check_network = False
121+
try:
122+
import network
123+
can_check_network = True
124+
except Exception as e:
125+
print("Warning: could not check WLAN status:", str(e))
126+
120127
def update_wifi_icon(timer):
121-
try:
122-
if network.WLAN(network.STA_IF).isconnected():
123-
wifi_icon.remove_flag(lv.obj.FLAG.HIDDEN)
124-
else:
125-
wifi_icon.add_flag(lv.obj.FLAG.HIDDEN)
126-
except lv.LvReferenceError:
127-
print("update_wifi_icon caught LvReferenceError")
128-
129-
import esp32
128+
if not can_check_network or network.WLAN(network.STA_IF).isconnected():
129+
wifi_icon.remove_flag(lv.obj.FLAG.HIDDEN)
130+
else:
131+
wifi_icon.add_flag(lv.obj.FLAG.HIDDEN)
132+
133+
can_check_temperature = False
134+
try:
135+
import esp32
136+
except Exception as e:
137+
print("Warning: can't check temperature sensor:", str(e))
138+
130139
def update_temperature(timer):
131-
temp_label.set_text(f"{esp32.mcu_temperature()}°C")
140+
if can_check_temperature:
141+
temp_label.set_text(f"{esp32.mcu_temperature()}°C")
142+
else:
143+
temp_label.set_text("42°C")
144+
132145

133146
import gc
134147
def update_memfree(timer):
@@ -351,7 +364,7 @@ def execute_script(script_source, is_file, is_launcher, is_graphical):
351364
traceback.print_exception(type(e), e, tb)
352365
print(f"Thread {thread_id}: script {compile_name} finished")
353366
if False and is_graphical and prevscreen and not is_launcher: # disabled this for now
354-
print("/main.py: execute_script(): deleting timers...")
367+
print("main.py: execute_script(): deleting timers...")
355368
timer1.delete()
356369
timer2.delete()
357370
timer3.delete()
@@ -366,28 +379,29 @@ def execute_script(script_source, is_file, is_launcher, is_graphical):
366379

367380
# Run the script in a new thread:
368381
def execute_script_new_thread(scriptname, is_file, is_launcher, is_graphical):
369-
print(f"/main.py: execute_script_new_thread({scriptname},{is_file},{is_launcher})")
382+
print(f"main.py: execute_script_new_thread({scriptname},{is_file},{is_launcher})")
370383
try:
371384
# 168KB maximum at startup but 136KB after loading display, drivers, LVGL gui etc so let's go for 128KB for now, still a lot...
372385
# But then no additional threads can be created. A stacksize of 32KB allows for 4 threads, so 3 in the app itself, which might be tight.
373-
_thread.stack_size(16384) # A stack size of 16KB allows for around 10 threads in the app, which should be plenty.
386+
# 16KB allows for 10 threads in the apps, but seems too tight for urequests on unix (desktop) targets
387+
_thread.stack_size(24576)
374388
_thread.start_new_thread(execute_script, (scriptname, is_file, is_launcher, is_graphical))
375389
except Exception as e:
376-
print("/main.py: execute_script_new_thread(): error starting new thread thread: ", e)
390+
print("main.py: execute_script_new_thread(): error starting new thread thread: ", e)
377391

378392
def start_app_by_name(app_name, is_launcher=False):
379393
global foreground_app_name
380394
foreground_app_name = app_name
381-
custom_app_dir=f"/apps/{app_name}"
382-
builtin_app_dir=f"/builtin/apps/{app_name}"
395+
custom_app_dir=f"apps/{app_name}"
396+
builtin_app_dir=f"builtin/apps/{app_name}"
383397
try:
384398
stat = uos.stat(custom_app_dir)
385399
start_app(custom_app_dir, is_launcher)
386400
except OSError:
387401
start_app(builtin_app_dir, is_launcher)
388402

389403
def start_app(app_dir, is_launcher=False):
390-
print(f"/main.py start_app({app_dir},{is_launcher}")
404+
print(f"main.py start_app({app_dir},{is_launcher}")
391405
global foreground_app_name
392406
foreground_app_name = app_dir # would be better to store only the app name...
393407
manifest_path = f"{app_dir}/META-INF/MANIFEST.JSON"
@@ -409,19 +423,19 @@ def restart_launcher():
409423
# No need to stop the other launcher first, because it exits after building the screen
410424
start_app_by_name("com.example.launcher", True)
411425

412-
execute_script_new_thread("/autorun.py", True, False, False) # Generic run-at-boot script, for development
426+
execute_script_new_thread("autorun.py", True, False, False) # Generic run-at-boot script, for development
413427

414428
try:
415429
import freezefs_mount_builtin
416430
except Exception as e:
417-
print("/main.py: WARNING: could not import/run freezefs_mount_builtin: ", e)
431+
print("main.py: WARNING: could not import/run freezefs_mount_builtin: ", e)
418432

419-
execute_script_new_thread("/builtin/system/button.py", True, False, False) # Button handling through IRQ
433+
execute_script_new_thread("builtin/system/button.py", True, False, False) # Button handling through IRQ
420434

421435
# A generic "start at boot" mechanism hasn't been implemented yet, so do it like this:
422436
import uos
423-
custom_auto_connect = "/apps/com.example.wificonf/assets/auto_connect.py"
424-
builtin_auto_connect = "/builtin/apps/com.example.wificonf/assets/auto_connect.py"
437+
custom_auto_connect = "apps/com.example.wificonf/assets/auto_connect.py"
438+
builtin_auto_connect = "builtin/apps/com.example.wificonf/assets/auto_connect.py"
425439
# Maybe start_app_by_name() and start_app_by_name() could be merged so the try-except logic is not duplicated...
426440
try:
427441
stat = uos.stat(custom_auto_connect)
@@ -438,5 +452,8 @@ def restart_launcher():
438452
restart_launcher()
439453

440454
# If we got this far without crashing, then no need to rollback the update
441-
import ota.rollback
442-
ota.rollback.cancel()
455+
try:
456+
import ota.rollback
457+
ota.rollback.cancel()
458+
except Exception as e:
459+
print("main.py: warning: could not mark this update as valid:", e)

0 commit comments

Comments
 (0)