|
1 | 1 | print("button.py running") |
2 | 2 |
|
| 3 | +importlvglaslv |
| 4 | + |
3 | 5 | frommachineimportPin,Timer |
4 | 6 | importtime |
5 | 7 | import_thread |
6 | 8 |
|
7 | | -importmpos.apps |
| 9 | +frommpos.appsimportActivity,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 | +classBootloader(Activity): |
| 30 | + |
| 31 | +defonCreate(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 | +defonResume(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 | | -defhandle_long_press(): |
23 | | -print(message) |
24 | | -importlvglaslv |
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 | | -importmachine |
32 | | -machine.bootloader() |
| 44 | +defstart_bootloader(self,timer): |
| 45 | +importmachine |
| 46 | +machine.bootloader() |
33 | 47 |
|
34 | 48 | defon_long_press(t):# Callback for when long press duration is reached. |
35 | 49 | print("button.py: long press detected") |
36 | 50 | globaltimer |
37 | 51 | timer.deinit()# Stop the timer |
38 | 52 | globalis_pressed |
39 | 53 | ifis_pressedandbutton.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 |
|
|