fix more apps

This commit is contained in:
Thomas Farstrike
2025-05-25 12:58:57 +02:00
parent 9350d38d61
commit 976be2326b
8 changed files with 35 additions and 26 deletions
@@ -36,6 +36,9 @@ import hashlib
import os
import _thread
import mpos.apps
import mpos.ui
keeprunning = True
summary = "Running 3 CPU tests...\n\n"
@@ -96,19 +99,20 @@ def stress_test_thread():
def janitor_cb(timer):
global keeprunning
if lv.screen_active() != appscreen:
if lv.screen_active() != main_screen:
print("cputest.py backgrounded, cleaning up...")
janitor.delete()
keeprunning = False
update_status_timer.delete()
appscreen = lv.screen_active()
main_screen = lv.obj()
janitor = lv.timer_create(janitor_cb, 1000, None)
update_status_timer = lv.timer_create(lambda timer: status.set_text(summary), 750, None)
status = lv.label(appscreen)
status = lv.label(main_screen)
status.align(lv.ALIGN.TOP_LEFT, 5, 10)
status.set_text(summary)
mpos.ui.load_screen(main_screen)
_thread.stack_size(12*1024)
_thread.stack_size(mpos.apps.good_stack_size())
_thread.start_new_thread(stress_test_thread, ())
@@ -32,6 +32,9 @@ import gc
import time
import _thread
import mpos.apps
import mpos.ui
# Configuration
ALLOCATION_TIMEOUT_MS = 100 # Timeout for a single allocation (in milliseconds)
keep_running = True
@@ -110,18 +113,19 @@ def stress_test_thread():
def janitor_cb(timer):
global keep_running
if lv.screen_active() != appscreen:
if lv.screen_active() != main_screen:
print("memtest.py backgrounded, cleaning up...")
janitor.delete()
keep_running = False
appscreen = lv.screen_active()
status = lv.label(appscreen)
main_screen = lv.obj()
status = lv.label(main_screen)
status.align(lv.ALIGN.TOP_LEFT, 5, 10)
status.set_style_text_color(lv.color_hex(0xFFFFFF), 0)
status.set_style_text_font(lv.font_unscii_8, 0)
mpos.ui.load_screen(main_screen)
_thread.stack_size(12*1024)
_thread.stack_size(mpos.apps.good_stack_size())
_thread.start_new_thread(stress_test_thread, ())
janitor = lv.timer_create(janitor_cb, 400, None)
@@ -4,6 +4,7 @@ import ujson
import time
import _thread
import mpos.apps
import mpos.info
import mpos.ui
@@ -91,7 +92,7 @@ def update_with_lvgl(url):
def install_button_click(download_url):
print(f"install_button_click for url {download_url}")
try:
_thread.stack_size(12*1024)
_thread.stack_size(mpos.apps.good_stack_size())
_thread.start_new_thread(update_with_lvgl, (download_url,))
except Exception as e:
print("Could not start update_with_lvgl thread: ", e)
@@ -4,6 +4,7 @@ import time
import lvgl as lv
import _thread
import mpos.apps
import mpos.ui
# Screens:
@@ -99,7 +100,7 @@ def start_scan_networks():
busy_scanning = True
scan_button.remove_flag(lv.obj.FLAG.CLICKABLE)
scan_button_label.set_text(scan_button_scanning_text)
_thread.stack_size(12*1024)
_thread.stack_size(get_good_stacksize())
_thread.start_new_thread(scan_networks_thread, ())
@@ -144,7 +145,7 @@ def start_attempt_connecting(ssid,password):
print("Not attempting connect because busy_connecting.")
else:
busy_connecting = True
_thread.stack_size(12*1024)
_thread.stack_size(get_good_stacksize())
_thread.start_new_thread(attempt_connecting_thread, (ssid,password))
def show_error(message):
@@ -295,7 +296,6 @@ def cancel_cb(event):
print("Deleting password screen...")
password_page.delete()
print("cancel_cb: Restoring main_screen")
#mpos.ui.load_screen(main_screen)
mpos.ui.back_screen()
def create_ui():
+3 -1
View File
@@ -4,6 +4,8 @@ from machine import Pin, Timer
import time
import _thread
import mpos.apps
# Configure IO0 as input with pull-up resistor
button = Pin(0, Pin.IN, Pin.PULL_UP)
@@ -35,7 +37,7 @@ def on_long_press(t): # Callback for when long press duration is reached.
timer.deinit() # Stop the timer
global is_pressed
if is_pressed and button.value() == 0: # Ensure button is still pressed
_thread.stack_size(12*1024)
_thread.stack_size(mpos.apps.good_stack_size())
_thread.start_new_thread(handle_long_press, ())
else:
is_pressed = False
+8
View File
@@ -11,6 +11,13 @@ import mpos.apps
import mpos.info
import mpos.ui
def good_stack_size():
stacksize = 24*1024
import sys
if sys.platform == "esp32":
stacksize = 16*1024
return stacksize
# Run the script in the current thread:
def execute_script(script_source, is_file, cwd=None):
thread_id = _thread.get_ident()
@@ -64,6 +71,7 @@ def execute_script_new_thread(scriptname, is_file):
stack=24*1024 # this doesn't do anything because it's all started in the same thread
else:
stack=16*1024 # 16KB doesn't seem to be enough for the AppStore app on desktop
stack = mpos.apps.good_stack_size()
print(f"app.py: setting stack size for script to {stack}")
_thread.stack_size(stack)
_thread.start_new_thread(execute_script, (scriptname, is_file))
+2 -1
View File
@@ -18,7 +18,8 @@ class Thread:
#stacksize = 12*1024
# small stack sizes 8KB gives segfault directly
# 22KB or less is too tight on desktop, 23KB and more is fine
stacksize = 24*1024
#stacksize = 24*1024
stacksize = mpos.apps.good_stack_size()
#stacksize = 20*1024
print(f"starting thread with stacksize {stacksize}")
_thread.stack_size(stacksize)
+1 -12
View File
@@ -17,18 +17,7 @@ except Exception as e:
from mpos import apps
apps.execute_script("builtin/system/button.py", True) # Install button handler through IRQ
def dummy():
pass
import sys
if sys.platform == "esp32":
apps.auto_connect()
else:
# On unix/desktop, at least 24KB of stack size is needed in the REPL to make nostr work there
#import _thread
#_thread.stack_size(24*1024) # on unix/desktop, at least 24KB is needed for doing nostr connections from the REPL
#_thread.start_new_thread(dummy, ()) # not just setting the stack_size but actually starting a thread to apply this globally
pass
apps.auto_connect()
apps.restart_launcher()