Skip to content

Commit 7374df5

Browse files
Settings app: add "format internal data partition" option
1 parent e00201a commit 7374df5

File tree

1 file changed

+28
-3
lines changed
  • internal_filesystem/builtin/apps/com.micropythonos.settings/assets

1 file changed

+28
-3
lines changed

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self):
4545
# Advanced settings, alphabetically:
4646
{"title": "Auto Start App", "key": "auto_start_app", "value_label": None, "cont": None, "ui": "radiobuttons", "ui_options": [(app.name, app.fullname) for app in PackageManager.get_app_list()]},
4747
{"title": "Restart to Bootloader", "key": "boot_mode", "value_label": None, "cont": None, "ui": "radiobuttons", "ui_options": [("Normal", "normal"), ("Bootloader", "bootloader")]}, # special that doesn't get saved
48+
{"title": "Format internal data partition", "key": "format_internal_data_partition", "value_label": None, "cont": None, "ui": "radiobuttons", "ui_options": [("No, do not format", "no"), ("Yes, erase all settings, files and non-builtin apps", "yes")]}, # special that doesn't get saved
4849
# This is currently only in the drawer but would make sense to have it here for completeness:
4950
#{"title": "Display Brightness", "key": "display_brightness", "value_label": None, "cont": None, "placeholder": "A value from 0 to 100."},
5051
# Maybe also add font size (but ideally then all fonts should scale up/down)
@@ -151,11 +152,12 @@ def onCreate(self):
151152
top_cont.set_style_pad_all(mpos.ui.pct_of_display_width(1), 0)
152153
top_cont.set_flex_flow(lv.FLEX_FLOW.ROW)
153154
top_cont.set_style_flex_main_place(lv.FLEX_ALIGN.SPACE_BETWEEN, 0)
155+
top_cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
154156

155157
setting_label = lv.label(top_cont)
156158
setting_label.set_text(setting["title"])
157159
setting_label.align(lv.ALIGN.TOP_LEFT,0,0)
158-
setting_label.set_style_text_font(lv.font_montserrat_24, 0)
160+
setting_label.set_style_text_font(lv.font_montserrat_20, 0)
159161

160162
ui = setting.get("ui")
161163
ui_options = setting.get("ui_options")
@@ -295,12 +297,35 @@ def cambutton_cb_unused(self, event):
295297
self.startActivityForResult(Intent(activity_class=CameraApp).putExtra("scanqr_mode", True), self.gotqr_result_callback)
296298

297299
def save_setting(self, setting):
298-
if setting["key"] == "boot_mode" and self.radio_container: # special case that isn't saved
299-
if self.active_radio_index == 1:
300+
# Check special cases that aren't saved
301+
if self.radio_container and self.active_radio_index == 1:
302+
if setting["key"] == "boot_mode":
300303
from mpos.bootloader import ResetIntoBootloader
301304
intent = Intent(activity_class=ResetIntoBootloader)
302305
self.startActivity(intent)
303306
return
307+
elif setting["key"] == "format_internal_data_partition":
308+
# Inspired by lvgl_micropython/lib/micropython/ports/esp32/modules/inisetup.py
309+
try:
310+
import vfs
311+
from flashbdev import bdev
312+
except Exception as e:
313+
print(f"Could not format internal data partition because: {e}")
314+
self.finish() # would be nice to show the error instead of silently returning
315+
return
316+
if bdev.info()[4] == "vfs":
317+
print(f"Formatting {bdev} as LittleFS2")
318+
vfs.VfsLfs2.mkfs(bdev)
319+
fs = vfs.VfsLfs2(bdev)
320+
elif bdev.info()[4] == "ffat":
321+
print(f"Formatting {bdev} as FAT")
322+
vfs.VfsFat.mkfs(bdev)
323+
fs = vfs.VfsFat(bdev)
324+
print(f"Mounting {fs} at /")
325+
vfs.mount(fs, "/")
326+
print("Done formatting, returning...")
327+
self.finish() # would be nice to show a "FormatInternalDataPartition" activity
328+
return
304329

305330
ui = setting.get("ui")
306331
ui_options = setting.get("ui_options")

0 commit comments

Comments
 (0)