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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dos
flow3r firmware
Commits
4ec0a6de
Commit
4ec0a6de
authored
Aug 21, 2023
by
Woazboat
Browse files
Options
Downloads
Patches
Plain Diff
Allow configuration of wifi credentials + hostname via settings.json
parent
bcd57529
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
python_payload/st3m/run.py
+11
-2
11 additions, 2 deletions
python_payload/st3m/run.py
python_payload/st3m/settings.py
+44
-2
44 additions, 2 deletions
python_payload/st3m/settings.py
python_payload/st3m/wifi.py
+18
-9
18 additions, 9 deletions
python_payload/st3m/wifi.py
with
73 additions
and
13 deletions
python_payload/st3m/run.py
+
11
−
2
View file @
4ec0a6de
...
...
@@ -19,6 +19,7 @@ import captouch, audio, leds, gc
import
os
import
machine
import
network
log
=
logging
.
Log
(
__name__
,
level
=
logging
.
INFO
)
...
...
@@ -36,8 +37,8 @@ def _make_reactor() -> Reactor:
settings
.
onoff_button_swap
.
subscribe
(
_onoff_button_swap_update
)
_onoff_button_swap_update
()
settings
.
onoff_
camp_
wifi
.
subscribe
(
wifi
.
_onoff_
camp_
wifi_update
)
wifi
.
_onoff_
camp_
wifi_update
()
settings
.
onoff_wifi
.
subscribe
(
wifi
.
_onoff_wifi_update
)
wifi
.
_onoff_wifi_update
()
return
reactor
...
...
@@ -142,6 +143,14 @@ def run_main() -> None:
bundles
.
update
()
settings
.
load_all
()
try
:
network
.
hostname
(
settings
.
str_hostname
.
value
if
settings
.
str_hostname
.
value
else
"
flow3r
"
)
except
Exception
as
e
:
log
.
error
(
f
"
Failed to set hostname
{
e
}
"
)
menu_settings
=
settings
.
build_menu
()
menu_system
=
SimpleMenu
(
[
...
...
This diff is collapsed.
Click to expand it.
python_payload/st3m/settings.py
+
44
−
2
View file @
4ec0a6de
...
...
@@ -242,6 +242,42 @@ class OnOffWidget(TunableWidget):
self
.
_tunable
.
set_value
(
not
self
.
_state
)
class
StringTunable
(
UnaryTunable
):
"""
StringTunable is a UnaryTunable that has a string value
"""
def
__init__
(
self
,
name
:
str
,
key
:
str
,
default
:
Optional
[
str
])
->
None
:
super
().
__init__
(
name
,
key
,
default
)
def
get_widget
(
self
)
->
TunableWidget
:
return
StringWidget
(
self
)
def
press
(
self
,
vm
:
Optional
[
ViewManager
])
->
None
:
# Text input not supported at the moment
pass
class
StringWidget
(
TunableWidget
):
"""
StringWidget is a TunableWidget for StringTunables. It renders a string.
"""
def
__init__
(
self
,
tunable
:
StringTunable
)
->
None
:
self
.
_tunable
=
tunable
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
pass
def
draw
(
self
,
ctx
:
Context
)
->
None
:
ctx
.
text_align
=
ctx
.
LEFT
ctx
.
text
(
self
.
_tunable
.
value
if
self
.
_tunable
.
value
else
""
)
def
press
(
self
,
vm
:
Optional
[
ViewManager
])
->
None
:
# Text input not supported at the moment
pass
class
SettingsMenuItem
(
MenuItem
):
"""
A MenuItem which draws its label offset to the left, and a Tunable
'
s widget
...
...
@@ -293,17 +329,23 @@ class SettingsMenu(SimpleMenu):
# Actual tunables / settings.
onoff_camp_wifi
=
OnOffTunable
(
"
Connect Camp WiFi
"
,
"
system.camp_wifi_enabled
"
,
False
)
onoff_button_swap
=
OnOffTunable
(
"
Swap Buttons
"
,
"
system.swap_buttons
"
,
False
)
onoff_debug
=
OnOffTunable
(
"
Debug Overlay
"
,
"
system.debug
"
,
False
)
onoff_debug_touch
=
OnOffTunable
(
"
Touch Overlay
"
,
"
system.debug_touch
"
,
False
)
onoff_show_tray
=
OnOffTunable
(
"
Show Icons
"
,
"
system.show_icons
"
,
True
)
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
]
=
[
onoff_camp_wifi
,
onoff_show_tray
,
onoff_button_swap
,
onoff_debug
,
onoff_debug_touch
,
onoff_wifi
,
str_wifi_ssid
,
str_wifi_psk
,
str_hostname
,
]
...
...
This diff is collapsed.
Click to expand it.
python_payload/st3m/wifi.py
+
18
−
9
View file @
4ec0a6de
import
network
from
network
import
WLAN
from
st3m
import
settings
from
st3m.goose
import
Optional
from
st3m.logging
import
Log
log
=
Log
(
__name__
)
iface
=
None
iface
:
Optional
[
WLAN
]
=
None
def
setup_
camp_
wifi
()
->
None
:
def
setup_wifi
()
->
None
:
global
iface
iface
=
network
.
WLAN
(
network
.
STA_IF
)
iface
.
active
(
True
)
enable
(
)
assert
iface
try
:
iface
.
connect
(
b
"
Camp2023-open
"
)
if
settings
.
str_wifi_ssid
.
value
:
iface
.
connect
(
settings
.
str_wifi_ssid
.
value
,
settings
.
str_wifi_psk
.
value
)
except
OSError
as
e
:
log
.
error
(
f
"
Could not connect to camp wifi:
{
e
}
"
)
log
.
error
(
f
"
Could not connect to wifi:
{
e
}
"
)
def
enable
()
->
None
:
global
iface
iface
=
network
.
WLAN
(
network
.
STA_IF
)
iface
.
active
(
True
)
def
disable
()
->
None
:
...
...
@@ -35,9 +44,9 @@ def is_connected() -> bool:
return
False
def
_onoff_
camp_
wifi_update
()
->
None
:
if
settings
.
onoff_
camp_
wifi
.
value
:
setup_
camp_
wifi
()
def
_onoff_wifi_update
()
->
None
:
if
settings
.
onoff_wifi
.
value
:
setup_wifi
()
else
:
disable
()
...
...
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