Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3r firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flow3r
flow3r firmware
Commits
cf318ef4
Commit
cf318ef4
authored
1 year ago
by
Woazboat
Browse files
Options
Downloads
Patches
Plain Diff
Declaratively define settings (sub-)menu structure
Add wifi settings submenu
parent
bbee3451
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!205
Allow configuration of wifi credentials + hostname via settings.json
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python_payload/st3m/goose.py
+11
-1
11 additions, 1 deletion
python_payload/st3m/goose.py
python_payload/st3m/settings.py
+55
-8
55 additions, 8 deletions
python_payload/st3m/settings.py
with
66 additions
and
9 deletions
python_payload/st3m/goose.py
+
11
−
1
View file @
cf318ef4
...
...
@@ -17,7 +17,17 @@ if TYPE_CHECKING:
class
ABCBase
(
metaclass
=
ABCMeta
):
pass
from
typing
import
List
,
Optional
,
Tuple
,
Dict
,
Any
,
Callable
,
Iterator
,
Generator
,
Union
from
typing
import
(
List
,
Optional
,
Tuple
,
Dict
,
Any
,
Callable
,
Iterator
,
Generator
,
Union
,
)
from
enum
import
Enum
else
:
# We're in CPython or Micropython.
...
...
This diff is collapsed.
Click to expand it.
python_payload/st3m/settings.py
+
55
−
8
View file @
cf318ef4
...
...
@@ -11,8 +11,19 @@ request.
import
json
from
st3m
import
InputState
,
Responder
,
logging
from
st3m.goose
import
ABCBase
,
abstractmethod
,
Any
,
Dict
,
List
,
Optional
,
Callable
from
st3m.ui.menu
import
MenuController
,
MenuItem
,
MenuItemBack
from
st3m.goose
import
(
ABCBase
,
abstractmethod
,
Any
,
Dict
,
List
,
Tuple
,
Optional
,
Callable
,
Union
,
TYPE_CHECKING
,
)
from
st3m.ui.menu
import
MenuController
,
MenuItem
,
MenuItemBack
,
MenuItemForeground
from
st3m.ui.elements.menus
import
SimpleMenu
from
st3m.ui.view
import
ViewManager
from
st3m.utils
import
lerp
,
ease_out_cubic
,
reduce
...
...
@@ -337,7 +348,9 @@ onoff_wifi = OnOffTunable("Enable WiFi", "system.wifi.enabled", False)
str_wifi_ssid
=
StringTunable
(
"
WiFi SSID
"
,
"
system.wifi.ssid
"
,
"
Camp2023-open
"
)
str_wifi_psk
=
StringTunable
(
"
WiFi Password
"
,
"
system.wifi.psk
"
,
None
)
str_hostname
=
StringTunable
(
"
Hostname
"
,
"
system.hostname
"
,
"
flow3r
"
)
all_settings
:
List
[
UnaryTunable
]
=
[
# List of all settings to be loaded/saved
load_save_settings
:
List
[
UnaryTunable
]
=
[
onoff_show_tray
,
onoff_button_swap
,
onoff_debug
,
...
...
@@ -348,6 +361,27 @@ all_settings: List[UnaryTunable] = [
str_hostname
,
]
if
TYPE_CHECKING
:
MenuStructureEntry
=
Union
[
UnaryTunable
,
Tuple
[
str
,
List
[
"
MenuStructureEntry
"
]]]
MenuStructure
=
List
[
MenuStructureEntry
]
# WiFi submenu
wifi_settings
:
"
MenuStructure
"
=
[
onoff_wifi
,
str_wifi_ssid
,
str_wifi_psk
,
str_hostname
,
]
# Main settings menu
settings_menu_structure
:
"
MenuStructure
"
=
[
onoff_show_tray
,
onoff_button_swap
,
onoff_debug
,
onoff_debug_touch
,
(
"
Wifi
"
,
wifi_settings
),
]
def
load_all
()
->
None
:
"""
...
...
@@ -362,7 +396,7 @@ def load_all() -> None:
return
log
.
info
(
"
Loaded settings from flash
"
)
for
setting
in
all
_settings
:
for
setting
in
load_save
_settings
:
setting
.
load
(
data
)
...
...
@@ -383,7 +417,7 @@ def save_all() -> None:
Save all settings to flash.
"""
res
:
Dict
[
str
,
Any
]
=
{}
for
setting
in
all
_settings
:
for
setting
in
load_save
_settings
:
res
=
_update
(
res
,
setting
.
save
())
try
:
with
open
(
"
/flash/settings.json
"
,
"
w
"
)
as
f
:
...
...
@@ -395,12 +429,25 @@ def save_all() -> None:
log
.
info
(
"
Saved settings to flash
"
)
def
build_menu
(
)
->
SimpleMenu
:
def
build_menu
_recursive
(
items
:
"
MenuStructure
"
)
->
SimpleMenu
:
"""
Re
t
ur
n a SimpleMenu for all settings
.
Re
c
ur
sively build a menu for the given setting structure
.
"""
mib
:
MenuItem
=
SettingsMenuItemBack
()
positions
:
List
[
MenuItem
]
=
[
mib
,
]
+
[
SettingsMenuItem
(
t
)
for
t
in
all_settings
]
]
+
[
SettingsMenuItem
(
t
)
if
isinstance
(
t
,
UnaryTunable
)
else
MenuItemForeground
(
t
[
0
],
build_menu_recursive
(
t
[
1
]))
for
t
in
items
]
return
SettingsMenu
(
positions
)
def
build_menu
()
->
SimpleMenu
:
"""
Return a SettingsMenu for all settings.
"""
return
build_menu_recursive
(
settings_menu_structure
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment