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
148aa1db
Commit
148aa1db
authored
1 year ago
by
iggy
Committed by
q3k
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
py: nick.py read and store nickname and config in a json file
parent
1d6ad2d9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python_payload/apps/nick.py
+37
-6
37 additions, 6 deletions
python_payload/apps/nick.py
python_payload/st4m/application.py
+4
-0
4 additions, 0 deletions
python_payload/st4m/application.py
with
41 additions
and
6 deletions
python_payload/apps/nick.py
+
37
−
6
View file @
148aa1db
...
@@ -2,20 +2,29 @@ from st4m.application import Application
...
@@ -2,20 +2,29 @@ from st4m.application import Application
from
st4m.property
import
PUSH_RED
,
GO_GREEN
,
BLACK
from
st4m.property
import
PUSH_RED
,
GO_GREEN
,
BLACK
import
leds
import
leds
import
json
class
NickApp
(
Application
):
class
NickApp
(
Application
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
super
().
__init__
(
name
)
super
().
__init__
(
name
)
self
.
_nick
=
self
.
_read_nick_from_file
()
self
.
_scale
=
1
self
.
_scale
=
1
self
.
_dir
=
1
self
.
_dir
=
1
self
.
_led
=
0.0
self
.
_led
=
0.0
self
.
_filename
=
"
nick.json
"
self
.
_defaults
=
{
"
name
"
:
"
flow3r
"
,
"
size
"
:
75
,
"
font
"
:
5
,
}
self
.
_data
=
{}
self
.
_load
()
def
draw
(
self
,
ctx
):
def
draw
(
self
,
ctx
):
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
font_size
=
75
ctx
.
font_size
=
self
.
_data
[
"
size
"
]
ctx
.
font
=
ctx
.
get_font_name
(
5
)
ctx
.
font
=
ctx
.
get_font_name
(
self
.
_data
[
"
font
"
]
)
# TODO (q3k) bug: we have to do this, otherwise we have horrible blinking
# TODO (q3k) bug: we have to do this, otherwise we have horrible blinking
ctx
.
rgb
(
1
,
1
,
1
)
ctx
.
rgb
(
1
,
1
,
1
)
...
@@ -27,7 +36,7 @@ class NickApp(Application):
...
@@ -27,7 +36,7 @@ class NickApp(Application):
ctx
.
move_to
(
0
,
0
)
ctx
.
move_to
(
0
,
0
)
ctx
.
save
()
ctx
.
save
()
ctx
.
scale
(
self
.
_scale
,
1
)
ctx
.
scale
(
self
.
_scale
,
1
)
ctx
.
text
(
self
.
_
nick
)
ctx
.
text
(
self
.
_
data
[
"
name
"
]
)
ctx
.
restore
()
ctx
.
restore
()
leds
.
set_hsv
(
int
(
self
.
_led
),
abs
(
self
.
_scale
)
*
360
,
1
,
0.2
)
leds
.
set_hsv
(
int
(
self
.
_led
),
abs
(
self
.
_scale
)
*
360
,
1
,
0.2
)
...
@@ -38,6 +47,9 @@ class NickApp(Application):
...
@@ -38,6 +47,9 @@ class NickApp(Application):
def
on_enter
(
self
):
def
on_enter
(
self
):
super
().
on_enter
()
super
().
on_enter
()
def
on_exit
(
self
):
self
.
_save_to_json
(
self
.
_data
)
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
super
().
think
(
ins
,
delta_ms
)
super
().
think
(
ins
,
delta_ms
)
...
@@ -50,8 +62,27 @@ class NickApp(Application):
...
@@ -50,8 +62,27 @@ class NickApp(Application):
if
self
.
_led
>=
40
:
if
self
.
_led
>=
40
:
self
.
_led
=
0
self
.
_led
=
0
def
_read_nick_from_file
(
self
):
def
_load
(
self
):
return
"
iggy
"
self
.
_data
=
self
.
_defaults
.
copy
()
self
.
_data
.
update
(
self
.
_load_from_json
())
def
_load_from_json
(
self
):
jsondata
=
""
data
=
{}
try
:
with
open
(
self
.
_filename
)
as
f
:
jsondata
=
f
.
read
()
data
=
json
.
loads
(
jsondata
)
except
OSError
:
pass
return
data
def
_save_to_json
(
self
,
data
):
jsondata
=
json
.
dumps
(
data
)
with
open
(
self
.
_filename
,
"
w
"
)
as
f
:
f
.
write
(
jsondata
)
f
.
close
()
app
=
NickApp
(
"
nick
"
)
app
=
NickApp
(
"
nick
"
)
This diff is collapsed.
Click to expand it.
python_payload/st4m/application.py
+
4
−
0
View file @
148aa1db
...
@@ -8,9 +8,13 @@ class Application(ViewWithInputState):
...
@@ -8,9 +8,13 @@ class Application(ViewWithInputState):
self
.
_view_manager
=
None
self
.
_view_manager
=
None
super
().
__init__
()
super
().
__init__
()
def
on_exit
(
self
):
pass
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
def
think
(
self
,
ins
:
InputState
,
delta_ms
:
int
)
->
None
:
super
().
think
(
ins
,
delta_ms
)
super
().
think
(
ins
,
delta_ms
)
if
self
.
input
.
left_shoulder
.
middle
.
pressed
:
if
self
.
input
.
left_shoulder
.
middle
.
pressed
:
if
self
.
_view_manager
is
not
None
:
if
self
.
_view_manager
is
not
None
:
self
.
on_exit
()
self
.
_view_manager
.
pop
(
ViewTransitionSwipeRight
())
self
.
_view_manager
.
pop
(
ViewTransitionSwipeRight
())
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