You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Add Restart to Bootloader setting
This commit is contained in:
+2
-1
@@ -2,7 +2,8 @@
|
||||
=====
|
||||
- Tweak button size in drawer and add "Settings" button
|
||||
- Show "Brightness" text in drawer
|
||||
- Add builtin "Settings" app with settings for dark/light theme, theme color
|
||||
- Save and restore "Brightness" setting
|
||||
- Add builtin "Settings" app with settings for Light/Dark Theme, Theme Color, Restart to Bootloader
|
||||
|
||||
0.0.5
|
||||
=====
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
from mpos.apps import Activity, Intent
|
||||
from mpos.apps import Activity, ActivityNavigator, Intent
|
||||
|
||||
import mpos.config
|
||||
import mpos.ui
|
||||
|
||||
class Hello(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
screen = lv.obj()
|
||||
label = lv.label(screen)
|
||||
label.set_text('Hello World!')
|
||||
label.center()
|
||||
self.setContentView(screen)
|
||||
|
||||
|
||||
# Used to list and edit all settings:
|
||||
class SettingsActivity(Activity):
|
||||
@@ -20,9 +12,10 @@ class SettingsActivity(Activity):
|
||||
self.settings = [
|
||||
{"title": "Light/Dark Theme", "key": "theme_light_dark", "value_label": None, "cont": None},
|
||||
{"title": "Theme Color", "key": "theme_primary_color", "value_label": None, "cont": None, "placeholder": "HTML hex color, like: EC048C"},
|
||||
{"title": "Restart to Bootloader", "key": "boot_mode", "value_label": None, "cont": None}, # special that doesn't get saved
|
||||
# This is currently only in the drawer but would make sense to have it here for completeness:
|
||||
#{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
|
||||
# Maybe also add font size (but ideally then all fonts should scale up/down)
|
||||
#{"title": "Reboot into Bootloader", "key": "boot_mode", "value_label": None, "cont": None}, # special that doesn't get saved
|
||||
#{"title": "Timezone", "key": "timezone", "value_label": None, "cont": None, "placeholder": "Example: Europe/Prague"},
|
||||
]
|
||||
|
||||
@@ -238,6 +231,13 @@ class SettingActivity(Activity):
|
||||
self.startActivityForResult(Intent(activity_class=CameraApp).putExtra("scanqr_mode", True), self.gotqr_result_callback)
|
||||
|
||||
def save_setting(self, setting):
|
||||
if setting["key"] == "boot_mode" and self.radio_container:
|
||||
if self.active_radio_index == 1:
|
||||
from mpos.bootloader import ResetIntoBootloader
|
||||
intent = Intent(activity_class=ResetIntoBootloader)
|
||||
ActivityNavigator.startActivity(intent)
|
||||
return
|
||||
|
||||
if ( setting["key"] =="theme_light_dark" or setting["key"] == "boot_mode" ) and self.radio_container:
|
||||
if setting["key"] == "boot_mode":
|
||||
options = [("Normal", "normal"), ("Bootloader", "bootloader")]
|
||||
|
||||
@@ -8,6 +8,8 @@ import _thread
|
||||
|
||||
from mpos.apps import Activity, ActivityNavigator, Intent
|
||||
|
||||
from mpos.bootloader import ResetIntoBootloader
|
||||
|
||||
#import mpos.config
|
||||
#import mpos.ui
|
||||
|
||||
@@ -24,26 +26,7 @@ is_pressed = False
|
||||
# Timer for checking long press
|
||||
timer = Timer(-1)
|
||||
|
||||
message = "Bootloader mode activated.\nYou can now install firmware over USB.\n\nReset the device to cancel."
|
||||
|
||||
class Bootloader(Activity):
|
||||
|
||||
def onCreate(self):
|
||||
print(message)
|
||||
screen = lv.obj()
|
||||
label = lv.label(screen)
|
||||
label.set_text(message)
|
||||
label.center()
|
||||
self.setContentView(screen)
|
||||
|
||||
def onResume(self, screen):
|
||||
# Use a timer, otherwise the UI won't have time to update:
|
||||
timer = lv.timer_create(self.start_bootloader, 1000, None) # give it some time (at least 500ms) for the new screen animation
|
||||
timer.set_repeat_count(1)
|
||||
|
||||
def start_bootloader(self, timer):
|
||||
import machine
|
||||
machine.bootloader()
|
||||
|
||||
def on_long_press(t): # Callback for when long press duration is reached.
|
||||
print("button.py: long press detected")
|
||||
@@ -54,7 +37,7 @@ def on_long_press(t): # Callback for when long press duration is reached.
|
||||
#_thread.stack_size(mpos.apps.good_stack_size())
|
||||
#_thread.start_new_thread(handle_long_press, ())
|
||||
#lv.async_call(lambda l: handle_long_press(), None)
|
||||
intent = Intent(activity_class=Bootloader)
|
||||
intent = Intent(activity_class=ResetIntoBootloader)
|
||||
ActivityNavigator.startActivity(intent)
|
||||
else:
|
||||
is_pressed = False
|
||||
|
||||
Reference in New Issue
Block a user