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
66ff1002
Commit
66ff1002
authored
1 year ago
by
Timon
Browse files
Options
Downloads
Patches
Plain Diff
format
parent
70594160
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#6507
passed
1 year ago
Stage: check
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python_payload/apps/led_painter/__init__.py
+60
-33
60 additions, 33 deletions
python_payload/apps/led_painter/__init__.py
with
60 additions
and
33 deletions
python_payload/apps/led_painter/__init__.py
+
60
−
33
View file @
66ff1002
...
@@ -13,14 +13,16 @@ from ctx import Context
...
@@ -13,14 +13,16 @@ from ctx import Context
from
st3m.input
import
InputController
,
InputState
from
st3m.input
import
InputController
,
InputState
from
st3m.utils
import
tau
from
st3m.utils
import
tau
from
st3m
import
logging
from
st3m
import
logging
# from st3m.ui.interactions import CapScrollController
# from st3m.ui.interactions import CapScrollController
import
leds
import
leds
# import st3m.run
# import st3m.run
log
=
logging
.
Log
(
__name__
,
level
=
logging
.
INFO
)
log
=
logging
.
Log
(
__name__
,
level
=
logging
.
INFO
)
log
.
info
(
"
hello led painter
"
)
log
.
info
(
"
hello led painter
"
)
class
LEDPainter
(
Application
):
class
LEDPainter
(
Application
):
def
__init__
(
self
,
app_ctx
:
ApplicationContext
)
->
None
:
def
__init__
(
self
,
app_ctx
:
ApplicationContext
)
->
None
:
super
().
__init__
(
app_ctx
)
super
().
__init__
(
app_ctx
)
...
@@ -42,20 +44,30 @@ class LEDPainter(Application):
...
@@ -42,20 +44,30 @@ class LEDPainter(Application):
self
.
PETAL_B_MINUS
=
5
self
.
PETAL_B_MINUS
=
5
self
.
PETAL_BLACK
=
4
self
.
PETAL_BLACK
=
4
self
.
PETAL_WHITE
=
3
self
.
PETAL_WHITE
=
3
self
.
LEDS
=
[[
0
,
0
,
0
]
for
i
in
range
(
40
)]
self
.
LEDS
=
[[
0
,
0
,
0
]
for
i
in
range
(
40
)]
# https://www.sr-research.com/circular-coordinate-calculator/
# https://www.sr-research.com/circular-coordinate-calculator/
self
.
PETAL_POS
=
[(
120
,
35
),
(
170
,
51
),
(
201
,
94
),
(
201
,
146
),
(
170
,
189
),
(
120
,
205
),
(
70
,
189
),
(
39
,
146
),
(
39
,
94
),
(
70
,
51
)]
self
.
PETAL_POS
=
[
(
120
,
35
),
(
170
,
51
),
(
201
,
94
),
(
201
,
146
),
(
170
,
189
),
(
120
,
205
),
(
70
,
189
),
(
39
,
146
),
(
39
,
94
),
(
70
,
51
),
]
# self.PETAL_POS.reverse()
# self.PETAL_POS.reverse()
def
draw
(
self
,
ctx
:
Context
)
->
None
:
def
draw
(
self
,
ctx
:
Context
)
->
None
:
ctx
.
font
=
ctx
.
get_font_name
(
1
)
ctx
.
font
=
ctx
.
get_font_name
(
1
)
ctx
.
rgb
(
0
,
0
,
0
).
rectangle
(
-
120
,
-
120
,
240
,
240
).
fill
()
ctx
.
rgb
(
0
,
0
,
0
).
rectangle
(
-
120
,
-
120
,
240
,
240
).
fill
()
ctx
.
rgb
(
self
.
r
/
255
,
self
.
g
/
255
,
self
.
b
/
255
).
rectangle
(
-
30
,
-
30
,
60
,
60
).
fill
()
ctx
.
rgb
(
self
.
r
/
255
,
self
.
g
/
255
,
self
.
b
/
255
).
rectangle
(
-
30
,
-
30
,
60
,
60
).
fill
()
if
(
self
.
r
==
0
)
and
(
self
.
g
==
0
)
and
(
self
.
b
==
0
):
if
(
self
.
r
==
0
)
and
(
self
.
g
==
0
)
and
(
self
.
b
==
0
):
ctx
.
font_size
=
20
ctx
.
font_size
=
20
...
@@ -64,31 +76,47 @@ class LEDPainter(Application):
...
@@ -64,31 +76,47 @@ class LEDPainter(Application):
if
self
.
_draw
:
if
self
.
_draw
:
self
.
LEDS
[
self
.
_cursor
]
=
[
self
.
r
,
self
.
g
,
self
.
b
]
self
.
LEDS
[
self
.
_cursor
]
=
[
self
.
r
,
self
.
g
,
self
.
b
]
ctx
.
font_size
=
14
ctx
.
font_size
=
14
ctx
.
move_to
(
-
80
,
-
40
).
rgb
(
255
,
255
,
255
).
text
(
"
(Center L) Brush Down
"
)
ctx
.
move_to
(
-
80
,
-
40
).
rgb
(
255
,
255
,
255
).
text
(
"
(Center L) Brush Down
"
)
for
i
in
range
(
len
(
self
.
LEDS
)):
for
i
in
range
(
len
(
self
.
LEDS
)):
leds
.
set_rgb
(
i
,
self
.
LEDS
[
i
][
0
],
self
.
LEDS
[
i
][
1
],
self
.
LEDS
[
i
][
2
])
leds
.
set_rgb
(
i
,
self
.
LEDS
[
i
][
0
],
self
.
LEDS
[
i
][
1
],
self
.
LEDS
[
i
][
2
])
else
:
else
:
ctx
.
font_size
=
14
ctx
.
font_size
=
14
ctx
.
move_to
(
-
80
,
-
40
).
rgb
(
255
,
255
,
255
).
text
(
"
(Center L) Brush Up
"
)
ctx
.
move_to
(
-
80
,
-
40
).
rgb
(
255
,
255
,
255
).
text
(
"
(Center L) Brush Up
"
)
for
i
in
range
(
len
(
self
.
LEDS
)):
for
i
in
range
(
len
(
self
.
LEDS
)):
leds
.
set_rgb
(
i
,
self
.
LEDS
[
i
][
0
],
self
.
LEDS
[
i
][
1
],
self
.
LEDS
[
i
][
2
])
leds
.
set_rgb
(
i
,
self
.
LEDS
[
i
][
0
],
self
.
LEDS
[
i
][
1
],
self
.
LEDS
[
i
][
2
])
leds
.
set_rgb
(
self
.
_cursor
,
255
,
255
,
255
)
leds
.
set_rgb
(
self
.
_cursor
,
255
,
255
,
255
)
if
(
self
.
r
==
255
)
and
(
self
.
g
==
255
)
and
(
self
.
b
==
255
):
if
(
self
.
r
==
255
)
and
(
self
.
g
==
255
)
and
(
self
.
b
==
255
):
leds
.
set_rgb
(
self
.
_cursor
,
0
,
0
,
255
)
leds
.
set_rgb
(
self
.
_cursor
,
0
,
0
,
255
)
leds
.
update
()
leds
.
update
()
off_x
=
130
off_x
=
130
off_y
=
110
off_y
=
110
ctx
.
font_size
=
20
ctx
.
font_size
=
20
ctx
.
move_to
(
self
.
PETAL_POS
[
0
][
0
]
-
off_x
,
self
.
PETAL_POS
[
0
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
R+
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
0
][
0
]
-
off_x
,
self
.
PETAL_POS
[
0
][
1
]
-
off_y
).
rgb
(
ctx
.
move_to
(
self
.
PETAL_POS
[
1
][
0
]
-
off_x
,
self
.
PETAL_POS
[
1
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
R-
"
)
255
,
255
,
255
ctx
.
move_to
(
self
.
PETAL_POS
[
2
][
0
]
-
off_x
,
self
.
PETAL_POS
[
2
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
G+
"
)
).
text
(
"
R+
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
3
][
0
]
-
off_x
,
self
.
PETAL_POS
[
3
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
G-
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
1
][
0
]
-
off_x
,
self
.
PETAL_POS
[
1
][
1
]
-
off_y
).
rgb
(
ctx
.
move_to
(
self
.
PETAL_POS
[
4
][
0
]
-
off_x
,
self
.
PETAL_POS
[
4
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B+
"
)
255
,
255
,
255
ctx
.
move_to
(
self
.
PETAL_POS
[
5
][
0
]
-
off_x
,
self
.
PETAL_POS
[
5
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B-
"
)
).
text
(
"
R-
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
6
][
0
]
-
off_x
,
self
.
PETAL_POS
[
6
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
2
][
0
]
-
off_x
,
self
.
PETAL_POS
[
2
][
1
]
-
off_y
).
rgb
(
ctx
.
move_to
(
self
.
PETAL_POS
[
7
][
0
]
-
off_x
,
self
.
PETAL_POS
[
7
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
W
"
)
255
,
255
,
255
).
text
(
"
G+
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
3
][
0
]
-
off_x
,
self
.
PETAL_POS
[
3
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
G-
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
4
][
0
]
-
off_x
,
self
.
PETAL_POS
[
4
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B+
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
5
][
0
]
-
off_x
,
self
.
PETAL_POS
[
5
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B-
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
6
][
0
]
-
off_x
,
self
.
PETAL_POS
[
6
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
B
"
)
ctx
.
move_to
(
self
.
PETAL_POS
[
7
][
0
]
-
off_x
,
self
.
PETAL_POS
[
7
][
1
]
-
off_y
).
rgb
(
255
,
255
,
255
).
text
(
"
W
"
)
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
)
...
@@ -112,44 +140,44 @@ class LEDPainter(Application):
...
@@ -112,44 +140,44 @@ class LEDPainter(Application):
else
:
else
:
self
.
_cursor
=
0
self
.
_cursor
=
0
# log.info(self._cursor)
# log.info(self._cursor)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_R_PLUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_R_PLUS
].
whole
.
pressed
:
if
self
.
r
+
self
.
STEPS
<=
255
:
if
self
.
r
+
self
.
STEPS
<=
255
:
self
.
r
+=
self
.
STEPS
self
.
r
+=
self
.
STEPS
else
:
else
:
self
.
r
=
255
self
.
r
=
255
# log.info(self.r)
# log.info(self.r)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_R_MINUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_R_MINUS
].
whole
.
pressed
:
if
self
.
r
-
self
.
STEPS
>=
0
:
if
self
.
r
-
self
.
STEPS
>=
0
:
self
.
r
-=
self
.
STEPS
self
.
r
-=
self
.
STEPS
else
:
else
:
self
.
r
=
0
self
.
r
=
0
# log.info(self.r)
# log.info(self.r)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_G_PLUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_G_PLUS
].
whole
.
pressed
:
if
self
.
g
+
self
.
STEPS
<=
255
:
if
self
.
g
+
self
.
STEPS
<=
255
:
self
.
g
+=
self
.
STEPS
self
.
g
+=
self
.
STEPS
else
:
else
:
self
.
g
=
255
self
.
g
=
255
# log.info(self.g)
# log.info(self.g)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_G_MINUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_G_MINUS
].
whole
.
pressed
:
if
self
.
g
-
self
.
STEPS
>=
0
:
if
self
.
g
-
self
.
STEPS
>=
0
:
self
.
g
-=
self
.
STEPS
self
.
g
-=
self
.
STEPS
else
:
else
:
self
.
g
=
0
self
.
g
=
0
# log.info(self.g)
# log.info(self.g)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_B_PLUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_B_PLUS
].
whole
.
pressed
:
if
self
.
b
+
self
.
STEPS
<=
255
:
if
self
.
b
+
self
.
STEPS
<=
255
:
self
.
b
+=
self
.
STEPS
self
.
b
+=
self
.
STEPS
else
:
else
:
self
.
b
=
255
self
.
b
=
255
# log.info(self.b)
# log.info(self.b)
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_B_MINUS
].
whole
.
pressed
:
if
self
.
input
.
captouch
.
petals
[
self
.
PETAL_B_MINUS
].
whole
.
pressed
:
if
self
.
b
-
self
.
STEPS
>=
0
:
if
self
.
b
-
self
.
STEPS
>=
0
:
self
.
b
-=
self
.
STEPS
self
.
b
-=
self
.
STEPS
else
:
else
:
self
.
b
=
0
self
.
b
=
0
...
@@ -165,7 +193,6 @@ class LEDPainter(Application):
...
@@ -165,7 +193,6 @@ class LEDPainter(Application):
self
.
g
=
255
self
.
g
=
255
self
.
b
=
255
self
.
b
=
255
# if __name__ == '__main__':
# if __name__ == '__main__':
# # Continue to make runnable via mpremote run.
# # Continue to make runnable via mpremote run.
...
...
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