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
ar
flow3r firmware
Commits
5e302d65
Commit
5e302d65
authored
1 year ago
by
ar
Browse files
Options
Downloads
Patches
Plain Diff
py/nick: allow adjusting colors using petals
parent
dd6ad21c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/badge/usage.rst
+4
-1
4 additions, 1 deletion
docs/badge/usage.rst
python_payload/apps/nick/__init__.py
+116
-9
116 additions, 9 deletions
python_payload/apps/nick/__init__.py
with
120 additions
and
10 deletions
docs/badge/usage.rst
+
4
−
1
View file @
5e302d65
...
...
@@ -55,11 +55,14 @@ pendrive). Open the file ```nick.json`` in a text editor and change your nick,
pronouns, font sizes for nick and pronouns, and whatever else you wish. Please
note that ``pronouns`` is a list, and should be formatted as such. for example:
``"pronouns": ["aa/bb", "cc/dd"],``
If you provide a string value there, the code will also handle that, but it
will be converted to a list.
For the ``nick.json`` file to appear, you must have started the Nick app at
least once.
Use ``"color": "0xffffff",`` to color your name and pronouns.
Use ``"color": "0xffffff",`` to color your name and pronouns, and you can also
use the bottom three petals to change the color on the fly.
When you're done editing, unmount/eject the badge from your computer
(``umount`` on Linux is enough) and press the left shoulder button to exit Disk
...
...
This diff is collapsed.
Click to expand it.
python_payload/apps/nick/__init__.py
+
116
−
9
View file @
5e302d65
...
...
@@ -35,13 +35,14 @@ class Configuration:
res
.
size
=
data
[
"
size
"
]
if
"
font
"
in
data
and
type
(
data
[
"
font
"
])
==
int
:
res
.
font
=
data
[
"
font
"
]
if
"
pronouns
"
in
data
:
# type checks don't look inside collections
if
(
"
pronouns
"
in
data
and
type
(
data
[
"
pronouns
"
])
==
list
and
set
([
type
(
x
)
for
x
in
data
[
"
pronouns
"
]])
==
{
str
}
):
if
type
(
data
[
"
pronouns
"
])
==
list
and
set
(
[
type
(
x
)
for
x
in
data
[
"
pronouns
"
]]
)
==
{
str
}:
res
.
pronouns
=
data
[
"
pronouns
"
]
if
type
(
data
[
"
pronouns
"
])
==
str
:
res
.
pronouns
=
data
[
"
pronouns
"
].
split
()
if
"
pronouns_size
"
in
data
:
if
type
(
data
[
"
pronouns_size
"
])
==
float
:
res
.
pronouns_size
=
int
(
data
[
"
pronouns_size
"
])
...
...
@@ -88,6 +89,13 @@ class NickApp(Application):
self
.
_filename
=
"
/flash/nick.json
"
self
.
_config
=
Configuration
.
load
(
self
.
_filename
)
self
.
_pronouns_serialized
=
"
"
.
join
(
self
.
_config
.
pronouns
)
self
.
_normalized_colors
=
self
.
_config
.
to_normalized_tuple
()
self
.
PETAL_R
=
6
self
.
PETAL_G
=
5
self
.
PETAL_B
=
4
def
to_denormalized_string
(
self
)
->
str
:
return
f
"
0x
{
int
(
self
.
_normalized_colors
[
0
]
*
255
)
:
x
}{
int
(
self
.
_normalized_colors
[
1
]
*
255
)
:
x
}{
int
(
self
.
_normalized_colors
[
2
]
*
255
)
:
x
}
"
def
draw
(
self
,
ctx
:
Context
)
->
None
:
ctx
.
text_align
=
ctx
.
CENTER
...
...
@@ -96,7 +104,7 @@ class NickApp(Application):
ctx
.
font
=
ctx
.
get_font_name
(
self
.
_config
.
font
)
ctx
.
rgb
(
0
,
0
,
0
).
rectangle
(
-
120
,
-
120
,
240
,
240
).
fill
()
ctx
.
rgb
(
*
self
.
_
config
.
to_
normalized_
tuple
()
)
ctx
.
rgb
(
*
self
.
_normalized_
colors
)
ctx
.
move_to
(
0
,
0
)
ctx
.
save
()
...
...
@@ -115,7 +123,6 @@ class NickApp(Application):
leds
.
set_hsv
(
int
(
self
.
_led
),
abs
(
self
.
_scale_name
)
*
360
,
1
,
0.2
)
leds
.
update
()
# ctx.fill()
def
on_exit
(
self
)
->
None
:
self
.
_config
.
save
(
self
.
_filename
)
...
...
@@ -130,6 +137,106 @@ class NickApp(Application):
if
self
.
_led
>=
40
:
self
.
_led
=
0
pos_r
=
ins
.
captouch
.
petals
[
self
.
PETAL_R
].
position
pos_g
=
ins
.
captouch
.
petals
[
self
.
PETAL_G
].
position
pos_b
=
ins
.
captouch
.
petals
[
self
.
PETAL_B
].
position
if
pos_r
[
0
]
>
10000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
]
+
1.0
/
32
,
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
],
)
if
self
.
_normalized_colors
[
0
]
>
1.0
:
self
.
_normalized_colors
=
(
1.0
,
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
],
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
if
pos_r
[
0
]
<
-
10000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
]
-
1.0
/
32
,
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
],
)
if
self
.
_normalized_colors
[
0
]
<
0.0
:
self
.
_normalized_colors
=
(
0.0
,
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
],
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
if
pos_g
[
0
]
>
20000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
]
+
1.0
/
32
,
self
.
_normalized_colors
[
2
],
)
if
self
.
_normalized_colors
[
1
]
>
1.0
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
1.0
,
self
.
_normalized_colors
[
2
],
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
if
pos_g
[
0
]
>
1000
and
pos_g
[
0
]
<
15000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
]
-
1.0
/
32
,
self
.
_normalized_colors
[
2
],
)
if
self
.
_normalized_colors
[
1
]
<
0.0
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
0.0
,
self
.
_normalized_colors
[
2
],
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
if
pos_b
[
0
]
>
10000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
]
+
1.0
/
32
,
)
if
self
.
_normalized_colors
[
2
]
>
1.0
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
],
1.0
,
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
if
pos_b
[
0
]
<
-
10000
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
],
self
.
_normalized_colors
[
2
]
-
1.0
/
32
,
)
if
self
.
_normalized_colors
[
2
]
<
0.0
:
self
.
_normalized_colors
=
(
self
.
_normalized_colors
[
0
],
self
.
_normalized_colors
[
1
],
0.0
,
)
self
.
_config
.
color
=
self
.
to_denormalized_string
()
# For running with `mpremote run`:
if
__name__
==
"
__main__
"
:
...
...
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