|
1 | 1 | print("button.py running") |
2 | 2 |
|
| 3 | +import lvgl as lv |
| 4 | + |
3 | 5 | from machine import Pin, Timer |
4 | 6 | import time |
5 | 7 | import _thread |
6 | 8 |
|
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 |
8 | 15 |
|
9 | 16 | # Configure IO0 as input with pull-up resistor |
10 | 17 | button = Pin(0, Pin.IN, Pin.PULL_UP) |
|
17 | 24 | # Timer for checking long press |
18 | 25 | timer = Timer(-1) |
19 | 26 |
|
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) |
21 | 43 |
|
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() |
33 | 47 |
|
34 | 48 | def on_long_press(t): # Callback for when long press duration is reached. |
35 | 49 | print("button.py: long press detected") |
36 | 50 | global timer |
37 | 51 | timer.deinit() # Stop the timer |
38 | 52 | global is_pressed |
39 | 53 | 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) |
42 | 59 | else: |
43 | 60 | is_pressed = False |
44 | 61 |
|
|
0 commit comments