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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ferdinand Bachmann
flow3r firmware
Commits
c76af6cb
Commit
c76af6cb
authored
1 year ago
by
ave
Browse files
Options
Downloads
Patches
Plain Diff
w1f1: add more improvements
parent
8a80feae
No related branches found
No related tags found
No related merge requests found
Pipeline
#7694
passed
1 year ago
Stage: check
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
python_payload/apps/w1f1/__init__.py
+47
-31
47 additions, 31 deletions
python_payload/apps/w1f1/__init__.py
python_payload/apps/w1f1/flow3r.toml
+1
-1
1 addition, 1 deletion
python_payload/apps/w1f1/flow3r.toml
python_payload/apps/w1f1/helpers.py
+8
-0
8 additions, 0 deletions
python_payload/apps/w1f1/helpers.py
with
56 additions
and
32 deletions
python_payload/apps/w1f1/__init__.py
+
47
−
31
View file @
c76af6cb
...
@@ -9,7 +9,12 @@ import os
...
@@ -9,7 +9,12 @@ import os
import
json
import
json
import
math
import
math
from
.k3yboard
import
TextInputModel
,
KeyboardView
from
.k3yboard
import
TextInputModel
,
KeyboardView
from
.helpers
import
sd_card_plugged
,
set_direction_leds
,
copy_across_devices
from
.helpers
import
(
sd_card_plugged
,
set_direction_leds
,
copy_across_devices
,
mark_unknown_characters
,
)
class
WifiApp
(
Application
):
class
WifiApp
(
Application
):
...
@@ -30,21 +35,13 @@ class WifiApp(Application):
...
@@ -30,21 +35,13 @@ class WifiApp(Application):
self
.
_waiting_for_password
=
False
self
.
_waiting_for_password
=
False
self
.
_password_model
=
TextInputModel
(
""
)
self
.
_password_model
=
TextInputModel
(
""
)
# Use config on SD card whenever possible
# Copy config to flash from SD card if we don't have one on flash
if
sd_card_plugged
():
if
(
# Move config to SD card from flash if we don't have one on SD card
sd_card_plugged
()
if
not
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE_SD
)
and
os
.
path
.
exists
(
and
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE_SD
)
self
.
WIFI_CONFIG_FILE
and
not
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE
)
):
copy_across_devices
(
self
.
WIFI_CONFIG_FILE
,
self
.
WIFI_CONFIG_FILE_SD
)
# if we have both sd and flash config, remove flash config
if
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE_SD
)
and
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE
):
):
os
.
remove
(
self
.
WIFI_CONFIG_FILE
)
copy_across_devices
(
self
.
WIFI_CONFIG_FILE_SD
,
self
.
WIFI_CONFIG_FILE
)
self
.
WIFI_CONFIG_FILE
=
self
.
WIFI_CONFIG_FILE_SD
if
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE
):
if
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE
):
with
open
(
self
.
WIFI_CONFIG_FILE
)
as
f
:
with
open
(
self
.
WIFI_CONFIG_FILE
)
as
f
:
...
@@ -57,8 +54,7 @@ class WifiApp(Application):
...
@@ -57,8 +54,7 @@ class WifiApp(Application):
"
Camp2023-open
"
:
{
"
psk
"
:
None
},
"
Camp2023-open
"
:
{
"
psk
"
:
None
},
},
},
}
}
with
open
(
self
.
WIFI_CONFIG_FILE
,
"
w
"
)
as
f
:
self
.
save_config_json
()
json
.
dump
(
self
.
_wifi_config
,
f
)
def
on_enter
(
self
,
vm
:
Optional
[
ViewManager
])
->
None
:
def
on_enter
(
self
,
vm
:
Optional
[
ViewManager
])
->
None
:
super
().
on_enter
(
vm
)
super
().
on_enter
(
vm
)
...
@@ -72,7 +68,6 @@ class WifiApp(Application):
...
@@ -72,7 +68,6 @@ class WifiApp(Application):
def
draw
(
self
,
ctx
:
Context
)
->
None
:
def
draw
(
self
,
ctx
:
Context
)
->
None
:
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
font
=
ctx
.
get_font_name
(
8
)
ctx
.
rgb
(
0
,
0
,
0
).
rectangle
(
-
120
,
-
90
,
240
,
180
).
fill
()
ctx
.
rgb
(
0
,
0
,
0
).
rectangle
(
-
120
,
-
90
,
240
,
180
).
fill
()
ctx
.
rgb
(
0.2
,
0.2
,
0.2
).
rectangle
(
-
120
,
-
120
,
240
,
30
).
fill
()
ctx
.
rgb
(
0.2
,
0.2
,
0.2
).
rectangle
(
-
120
,
-
120
,
240
,
30
).
fill
()
...
@@ -83,11 +78,12 @@ class WifiApp(Application):
...
@@ -83,11 +78,12 @@ class WifiApp(Application):
ctx
.
save
()
ctx
.
save
()
ctx
.
rgb
(
1
,
1
,
1
)
ctx
.
rgb
(
1
,
1
,
1
)
ctx
.
font
=
"
Arimo Bold
"
if
self
.
_iface
.
active
():
if
self
.
_iface
.
active
():
ctx
.
rgb
(
0
,
1
,
0
)
ctx
.
rgb
(
0
,
1
,
0
)
else
:
else
:
ctx
.
rgb
(
1
,
0
,
0
)
ctx
.
rgb
(
1
,
0
,
0
)
ctx
.
move_to
(
0
,
-
10
5
)
ctx
.
move_to
(
0
,
-
1
1
0
)
ctx
.
text
(
"
^
"
)
ctx
.
text
(
"
^
"
)
ctx
.
move_to
(
0
,
-
100
)
ctx
.
move_to
(
0
,
-
100
)
ctx
.
text
(
"
toggle wlan
"
)
ctx
.
text
(
"
toggle wlan
"
)
...
@@ -100,16 +96,17 @@ class WifiApp(Application):
...
@@ -100,16 +96,17 @@ class WifiApp(Application):
wlan_draw_offset
=
self
.
_wlan_offset
*
-
20
wlan_draw_offset
=
self
.
_wlan_offset
*
-
20
for
wlan
in
self
.
_nearby_wlans
:
for
wlan
in
self
.
_nearby_wlans
:
ssid
=
wlan
[
0
].
decode
()
base_ssid
=
wlan
[
0
].
decode
()
ssid
=
wlan
[
-
1
]
if
(
if
(
ssid
==
current_ssid
base_
ssid
==
current_ssid
and
self
.
_iface
.
active
()
and
self
.
_iface
.
active
()
and
self
.
_iface
.
isconnected
()
and
self
.
_iface
.
isconnected
()
):
):
ctx
.
rgb
(
0
,
1
,
0
)
ctx
.
rgb
(
0
,
1
,
0
)
elif
ssid
==
self
.
_is_connecting
:
elif
base_
ssid
==
self
.
_is_connecting
:
ctx
.
rgb
(
0
,
0
,
1
)
ctx
.
rgb
(
0
,
0
,
1
)
elif
ssid
in
self
.
_wifi_config
[
"
networks
"
]:
elif
base_
ssid
in
self
.
_wifi_config
[
"
networks
"
]:
ctx
.
rgb
(
1
,
1
,
0
)
ctx
.
rgb
(
1
,
1
,
0
)
else
:
else
:
ctx
.
rgb
(
1
,
1
,
1
)
ctx
.
rgb
(
1
,
1
,
1
)
...
@@ -120,6 +117,7 @@ class WifiApp(Application):
...
@@ -120,6 +117,7 @@ class WifiApp(Application):
selected
=
self
.
_nearby_wlans
[
self
.
_wlan_offset
]
==
wlan
selected
=
self
.
_nearby_wlans
[
self
.
_wlan_offset
]
==
wlan
open_network
=
wlan
[
4
]
==
0
open_network
=
wlan
[
4
]
==
0
ctx
.
font
=
"
Arimo Bold
"
if
selected
else
"
Arimo Regular
"
ctx
.
font_size
=
25
if
selected
else
15
ctx
.
font_size
=
25
if
selected
else
15
ssid_width
=
ctx
.
text_width
(
ssid
)
ssid_width
=
ctx
.
text_width
(
ssid
)
...
@@ -129,7 +127,7 @@ class WifiApp(Application):
...
@@ -129,7 +127,7 @@ class WifiApp(Application):
if
ssid_width
>
max_width
:
if
ssid_width
>
max_width
:
xpos
=
math
.
sin
(
self
.
_scroll_pos
)
*
(
ssid_width
-
max_width
)
/
2
xpos
=
math
.
sin
(
self
.
_scroll_pos
)
*
(
ssid_width
-
max_width
)
/
2
if
not
open_network
:
if
not
open_network
:
xpos
-=
10
xpos
-=
7
ctx
.
move_to
(
xpos
,
wlan_draw_offset
)
ctx
.
move_to
(
xpos
,
wlan_draw_offset
)
ctx
.
text
(
ssid
)
ctx
.
text
(
ssid
)
...
@@ -142,7 +140,7 @@ class WifiApp(Application):
...
@@ -142,7 +140,7 @@ class WifiApp(Application):
ctx
.
save
()
ctx
.
save
()
ctx
.
font
=
"
Material Icons
"
ctx
.
font
=
"
Material Icons
"
ctx
.
text_align
=
ctx
.
LEFT
ctx
.
text_align
=
ctx
.
LEFT
ctx
.
move_to
(
xpos
+
(
ssid_width
/
2
)
+
5
,
wlan_draw_offset
+
2
)
ctx
.
move_to
(
xpos
+
(
ssid_width
/
2
)
+
2
,
wlan_draw_offset
+
2
)
ctx
.
text
(
"
\ue897
"
)
ctx
.
text
(
"
\ue897
"
)
ctx
.
restore
()
ctx
.
restore
()
...
@@ -168,10 +166,15 @@ class WifiApp(Application):
...
@@ -168,10 +166,15 @@ class WifiApp(Application):
if
wlan
[
5
]
or
not
wlan
[
0
].
strip
():
if
wlan
[
5
]
or
not
wlan
[
0
].
strip
():
continue
continue
if
wlan
[
0
].
decode
()
in
self
.
_wifi_config
[
"
networks
"
]:
wlan_list
=
list
(
wlan
)
known_wlans
.
append
(
wlan
)
base_ssid
=
wlan
[
0
].
decode
()
clean_ssid
=
mark_unknown_characters
(
base_ssid
).
strip
()
wlan_list
.
append
(
clean_ssid
)
if
base_ssid
in
self
.
_wifi_config
[
"
networks
"
]:
known_wlans
.
append
(
wlan_list
)
else
:
else
:
unknown_wlans
.
append
(
wlan
)
unknown_wlans
.
append
(
wlan
_list
)
# sort by signal strength
# sort by signal strength
known_wlans
.
sort
(
key
=
lambda
wlan
:
wlan
[
3
],
reverse
=
True
)
known_wlans
.
sort
(
key
=
lambda
wlan
:
wlan
[
3
],
reverse
=
True
)
...
@@ -203,12 +206,23 @@ class WifiApp(Application):
...
@@ -203,12 +206,23 @@ class WifiApp(Application):
with
open
(
self
.
SETTINGS_JSON_FILE
,
"
w
"
)
as
f
:
with
open
(
self
.
SETTINGS_JSON_FILE
,
"
w
"
)
as
f
:
json
.
dump
(
settings_json
,
f
)
json
.
dump
(
settings_json
,
f
)
def
add_to_config_json
(
self
,
ssid
:
str
,
psk
:
str
)
->
None
:
def
add_
wlan_
to_config_json
(
self
,
ssid
:
str
,
psk
:
str
)
->
None
:
self
.
_wifi_config
[
"
networks
"
][
ssid
]
=
{
"
psk
"
:
psk
}
self
.
_wifi_config
[
"
networks
"
][
ssid
]
=
{
"
psk
"
:
psk
}
self
.
save_config_json
()
def
save_config_json
(
self
)
->
None
:
with
open
(
self
.
WIFI_CONFIG_FILE
,
"
w
"
)
as
f
:
with
open
(
self
.
WIFI_CONFIG_FILE
,
"
w
"
)
as
f
:
json
.
dump
(
self
.
_wifi_config
,
f
)
json
.
dump
(
self
.
_wifi_config
,
f
)
if
sd_card_plugged
():
try
:
if
os
.
path
.
exists
(
self
.
WIFI_CONFIG_FILE_SD
):
os
.
remove
(
self
.
WIFI_CONFIG_FILE_SD
)
copy_across_devices
(
self
.
WIFI_CONFIG_FILE
,
self
.
WIFI_CONFIG_FILE_SD
)
except
OSError
as
e
:
print
(
"
SD issue:
"
,
str
(
e
),
"
:(
"
)
def
connect_wifi
(
self
,
ssid
:
str
,
psk
:
str
=
None
)
->
None
:
def
connect_wifi
(
self
,
ssid
:
str
,
psk
:
str
=
None
)
->
None
:
if
ssid
in
self
.
_wifi_config
[
"
networks
"
]:
if
ssid
in
self
.
_wifi_config
[
"
networks
"
]:
psk
=
self
.
_wifi_config
[
"
networks
"
][
ssid
][
"
psk
"
]
psk
=
self
.
_wifi_config
[
"
networks
"
][
ssid
][
"
psk
"
]
...
@@ -307,7 +321,9 @@ class WifiApp(Application):
...
@@ -307,7 +321,9 @@ class WifiApp(Application):
if
self
.
_current_ssid
:
if
self
.
_current_ssid
:
self
.
update_settings_json
(
self
.
_current_ssid
,
self
.
_current_psk
)
self
.
update_settings_json
(
self
.
_current_ssid
,
self
.
_current_psk
)
if
self
.
_current_ssid
not
in
self
.
_wifi_config
[
"
networks
"
]:
if
self
.
_current_ssid
not
in
self
.
_wifi_config
[
"
networks
"
]:
self
.
add_to_config_json
(
self
.
_current_ssid
,
self
.
_current_psk
)
self
.
add_wlan_to_config_json
(
self
.
_current_ssid
,
self
.
_current_psk
)
elif
self
.
_connection_timer
<=
0
:
elif
self
.
_connection_timer
<=
0
:
self
.
_iface
.
disconnect
()
self
.
_iface
.
disconnect
()
self
.
_status_text
=
"
conn timed out
"
self
.
_status_text
=
"
conn timed out
"
...
...
This diff is collapsed.
Click to expand it.
python_payload/apps/w1f1/flow3r.toml
+
1
−
1
View file @
c76af6cb
...
@@ -10,4 +10,4 @@ author = "ave"
...
@@ -10,4 +10,4 @@ author = "ave"
license
=
"LGPL-3.0-only"
license
=
"LGPL-3.0-only"
url
=
"https://git.flow3r.garden/flow3r/flow3r-firmware"
url
=
"https://git.flow3r.garden/flow3r/flow3r-firmware"
description
=
"Lets you use multiple wireless networks."
description
=
"Lets you use multiple wireless networks."
version
=
6
version
=
7
This diff is collapsed.
Click to expand it.
python_payload/apps/w1f1/helpers.py
+
8
−
0
View file @
c76af6cb
...
@@ -28,3 +28,11 @@ def set_direction_leds(direction, r, g, b):
...
@@ -28,3 +28,11 @@ def set_direction_leds(direction, r, g, b):
leds
.
set_rgb
((
direction
*
4
)
-
1
,
r
,
g
,
b
)
leds
.
set_rgb
((
direction
*
4
)
-
1
,
r
,
g
,
b
)
leds
.
set_rgb
(
direction
*
4
,
r
,
g
,
b
)
leds
.
set_rgb
(
direction
*
4
,
r
,
g
,
b
)
leds
.
set_rgb
((
direction
*
4
)
+
1
,
r
,
g
,
b
)
leds
.
set_rgb
((
direction
*
4
)
+
1
,
r
,
g
,
b
)
def
mark_unknown_characters
(
text
:
str
)
->
str
:
glyph_index
=
"
!
\"
#$%&
'
()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[
\\
]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿŁπ“”•…€™←↑→↓−≈▼♠♣♥♦fiflffiffl
"
result_text
=
""
for
char
in
text
:
result_text
+=
char
if
char
in
glyph_index
else
"
?
"
return
result_text
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