Skip to content

Commit 32b4204

Browse files
Use as activity
1 parent 3eb2908 commit 32b4204

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

internal_filesystem/builtin/system/button.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
print("button.py running")
22

3+
import lvgl as lv
4+
35
from machine import Pin, Timer
46
import time
57
import _thread
68

7-
import mpos.apps
9+
from mpos.apps import Activity, ActivityNavigator, Intent
10+
11+
#import mpos.config
12+
#import mpos.ui
13+
14+
#import mpos.apps
815

916
# Configure IO0 as input with pull-up resistor
1017
button = Pin(0, Pin.IN, Pin.PULL_UP)
@@ -17,28 +24,38 @@
1724
# Timer for checking long press
1825
timer = Timer(-1)
1926

20-
message = "Bootloader mode activated.\nYou can now install firmware over USB.\n\n"
27+
message = "Bootloader mode activated.\nYou can now install firmware over USB.\n\nReset the device to cancel."
28+
29+
class Bootloader(Activity):
30+
31+
def onCreate(self):
32+
print(message)
33+
screen = lv.obj()
34+
label = lv.label(screen)
35+
label.set_text(message)
36+
label.center()
37+
self.setContentView(screen)
38+
39+
def onResume(self, screen):
40+
# Use a timer, otherwise the UI won't have time to update:
41+
timer = lv.timer_create(self.start_bootloader, 1000, None) # give it some time (at least 500ms) for the new screen animation
42+
timer.set_repeat_count(1)
2143

22-
def handle_long_press():
23-
print(message)
24-
import lvgl as lv
25-
screen = lv.obj()
26-
label = lv.label(screen)
27-
label.set_text(message)
28-
label.center()
29-
lv.screen_load(screen)
30-
time.sleep(1)
31-
import machine
32-
machine.bootloader()
44+
def start_bootloader(self, timer):
45+
import machine
46+
machine.bootloader()
3347

3448
def on_long_press(t): # Callback for when long press duration is reached.
3549
print("button.py: long press detected")
3650
global timer
3751
timer.deinit() # Stop the timer
3852
global is_pressed
3953
if is_pressed and button.value() == 0: # Ensure button is still pressed
40-
_thread.stack_size(mpos.apps.good_stack_size())
41-
_thread.start_new_thread(handle_long_press, ())
54+
#_thread.stack_size(mpos.apps.good_stack_size())
55+
#_thread.start_new_thread(handle_long_press, ())
56+
#lv.async_call(lambda l: handle_long_press(), None)
57+
intent = Intent(activity_class=Bootloader)
58+
ActivityNavigator.startActivity(intent)
4259
else:
4360
is_pressed = False
4461

0 commit comments

Comments
 (0)