Skip to content

Commit ee09a17

Browse files
lv.async_call from threads
1 parent 3b558c2 commit ee09a17

File tree

1 file changed

+10
-12
lines changed
  • internal_filesystem/builtin/apps/com.example.wificonf/assets

1 file changed

+10
-12
lines changed

internal_filesystem/builtin/apps/com.example.wificonf/assets/wificonf.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,8 @@ def start_scan_networks():
105105
_thread.start_new_thread(scan_networks, ())
106106

107107

108-
def attempt_connecting_done(ssid, result):
109-
print(f"Connecting to {ssid} got result: {result}")
108+
def attempt_connecting_thread(ssid,password):
110109
global busy_connecting, scan_button_label, scan_button, last_tried_ssid, last_tried_result
111-
last_tried_ssid = ssid
112-
last_tried_result = result
113-
busy_connecting=False
114-
scan_button_label.set_text(scan_button_scan_text)
115-
scan_button.add_flag(lv.obj.FLAG.CLICKABLE)
116-
117-
118-
def attempt_connecting(ssid,password):
119110
print(f"attempt_connecting: Attempting to connect to SSID: {ssid}")
120111
result="connected"
121112
try:
@@ -136,7 +127,14 @@ def attempt_connecting(ssid,password):
136127
print(f"attempt_connecting: Connection error: {e}")
137128
result=f"{e}"
138129
show_error("Connecting to {ssid} failed!")
139-
attempt_connecting_done(ssid, result)
130+
print(f"Connecting to {ssid} got result: {result}")
131+
last_tried_ssid = ssid
132+
last_tried_result = result
133+
busy_connecting=False
134+
# Schedule UI updates because different thread
135+
lv.async_call(lambda l: scan_button_label.set_text(scan_button_scan_text), None)
136+
lv.async_call(lambda l: scan_button.add_flag(lv.obj.FLAG.CLICKABLE), None)
137+
140138

141139
def start_attempt_connecting(ssid,password):
142140
print(f"start_attempt_connecting: Attempting to connect to SSID: {ssid}")
@@ -148,7 +146,7 @@ def start_attempt_connecting(ssid,password):
148146
else:
149147
busy_connecting = True
150148
_thread.stack_size(12*1024)
151-
_thread.start_new_thread(attempt_connecting, (ssid,password))
149+
_thread.start_new_thread(attempt_connecting_thread, (ssid,password))
152150

153151
def show_error(message):
154152
print(f"show_error: Displaying error: {message}")

0 commit comments

Comments
 (0)