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
eb578558
Commit
eb578558
authored
2 years ago
by
dx
Committed by
q3k
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
python_payload: menu/worms cleanup
parent
d764e4a5
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
python_payload/demo_worms.py
+19
-24
19 additions, 24 deletions
python_payload/demo_worms.py
python_payload/main.py
+3
-43
3 additions, 43 deletions
python_payload/main.py
python_payload/utils.py
+11
-4
11 additions, 4 deletions
python_payload/utils.py
with
33 additions
and
71 deletions
python_payload/demo_worms.py
+
19
−
24
View file @
eb578558
...
@@ -6,10 +6,10 @@ import math
...
@@ -6,10 +6,10 @@ import math
def
xy_from_polar
(
r
,
deg
):
def
xy_from_polar
(
r
,
deg
):
#rad = deg/180*math.pi
#rad = deg/180*math.pi
return
(
(
return
(
r
*
math
.
sin
(
deg
),
#x
r
*
math
.
sin
(
deg
),
#x
r
*
math
.
cos
(
deg
)
#y
r
*
math
.
cos
(
deg
)
#y
)
)
)
def
randrgb
():
def
randrgb
():
return
((
random
.
random
(),
random
.
random
(),
random
.
random
()))
return
((
random
.
random
(),
random
.
random
(),
random
.
random
()))
...
@@ -26,23 +26,11 @@ BLUE = (0,0,1)
...
@@ -26,23 +26,11 @@ BLUE = (0,0,1)
WHITE
=
(
1
,
1
,
1
)
WHITE
=
(
1
,
1
,
1
)
GREY
=
(
0.5
,
0.5
,
0.5
)
GREY
=
(
0.5
,
0.5
,
0.5
)
#
Get t
he global context (representing the whole screen)
#
T
he global context (representing the whole screen)
global
ctx
ctx
=
None
'''
worms
=
None
#center the text horizontally and vertically
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
#ctx.rgb() expects individual values for the channels, so unpack a list/tuple with *
#operations on ctx can be chained
#create a blue background
ctx.rgb(*BLUE).rectangle(-WIDTH/2,-HEIGHT/2,WIDTH,HEIGHT).fill()
#Write some text
ctx.move_to(0,0).rgb(*WHITE).text(
"
Hi :)
"
)
hardware.display_update()
'''
class
Worm
():
class
Worm
():
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -57,7 +45,6 @@ class Worm():
...
@@ -57,7 +45,6 @@ class Worm():
self
.
_lastdist
=
0.0
self
.
_lastdist
=
0.0
def
draw
(
self
):
def
draw
(
self
):
global
ctx
ctx
.
rgb
(
*
self
.
color
)
ctx
.
rgb
(
*
self
.
color
)
ctx
.
round_rectangle
(
ctx
.
round_rectangle
(
self
.
x
-
self
.
size
/
2
,
self
.
x
-
self
.
size
/
2
,
...
@@ -90,8 +77,6 @@ class Worm():
...
@@ -90,8 +77,6 @@ class Worm():
self
.
_lastdist
=
dist
self
.
_lastdist
=
dist
global
worms
def
init
():
def
init
():
global
worms
global
worms
global
ctx
global
ctx
...
@@ -110,7 +95,17 @@ def run():
...
@@ -110,7 +95,17 @@ def run():
def
foreground
():
def
foreground
():
pass
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
#ctx.rgb() expects individual values for the channels, so unpack a list/tuple with *
#operations on ctx can be chained
#create a blue background
ctx
.
rgb
(
*
BLUE
).
rectangle
(
-
WIDTH
/
2
,
-
HEIGHT
/
2
,
WIDTH
,
HEIGHT
).
fill
()
#Write some text
ctx
.
move_to
(
0
,
0
).
rgb
(
*
WHITE
).
text
(
"
Hi :)
"
)
hardware
.
display_update
()
#Known problems:
#Known problems:
#ctx.rotate(math.pi) turns the display black until powercycled
#ctx.rotate(math.pi) turns the display black until powercycled
...
...
This diff is collapsed.
Click to expand it.
python_payload/main.py
+
3
−
43
View file @
eb578558
...
@@ -3,13 +3,11 @@ import utils
...
@@ -3,13 +3,11 @@ import utils
import
time
import
time
import
harmonic_demo
import
harmonic_demo
import
melodic_demo
import
melodic_demo
import
cap_touch_demo
import
demo_worms
import
demo_worms
MODULES
=
[
MODULES
=
[
harmonic_demo
,
harmonic_demo
,
melodic_demo
,
melodic_demo
,
cap_touch_demo
,
demo_worms
,
demo_worms
,
]
]
...
@@ -20,30 +18,12 @@ ctx = None
...
@@ -20,30 +18,12 @@ ctx = None
BACKGROUND_COLOR
=
0
BACKGROUND_COLOR
=
0
def
draw_volume_slider
(
volume
):
global
ctx
length
=
96
+
((
volume
-
20
)
*
1.6
)
if
length
>
96
:
length
=
96
if
length
<
0
:
length
=
0
length
=
int
(
length
)
ctx
.
rgb
(
0
,
0
,
0
)
#dummy
ctx
.
round_rectangle
(
-
49
,
41
,
98
,
8
,
3
).
fill
()
#dummy idk
ctx
.
rgb
(
0
,
255
,
0
)
ctx
.
round_rectangle
(
-
51
,
49
,
102
,
12
,
3
).
fill
()
ctx
.
rgb
(
0
,
0
,
0
)
ctx
.
round_rectangle
(
-
50
,
50
,
100
,
10
,
3
).
fill
()
ctx
.
rgb
(
0
,
255
,
0
)
ctx
.
round_rectangle
(
-
48
,
52
,
length
,
6
,
3
).
fill
()
def
run_menu
():
def
run_menu
():
global
CURRENT_APP_RUN
global
CURRENT_APP_RUN
global
ctx
global
ctx
display_fill
(
BACKGROUND_COLOR
)
display_fill
(
BACKGROUND_COLOR
)
draw_volume_slider
(
VOLUME
)
utils
.
draw_volume_slider
(
ctx
,
VOLUME
)
ctx
.
move_to
(
0
,
0
).
rgb
(
255
,
0
,
255
).
text
(
"
select :3
"
)
ctx
.
move_to
(
0
,
0
).
rgb
(
255
,
0
,
255
).
text
(
"
select :3
"
)
display_update
()
display_update
()
...
@@ -70,7 +50,6 @@ def foreground_menu():
...
@@ -70,7 +50,6 @@ def foreground_menu():
utils
.
highlight_bottom_petal
(
0
,
0
,
55
,
55
);
utils
.
highlight_bottom_petal
(
0
,
0
,
55
,
55
);
utils
.
highlight_bottom_petal
(
1
,
55
,
0
,
55
);
utils
.
highlight_bottom_petal
(
1
,
55
,
0
,
55
);
utils
.
highlight_bottom_petal
(
2
,
55
,
55
,
0
);
utils
.
highlight_bottom_petal
(
2
,
55
,
55
,
0
);
utils
.
highlight_bottom_petal
(
3
,
0
,
110
,
0
);
display_fill
(
BACKGROUND_COLOR
)
display_fill
(
BACKGROUND_COLOR
)
display_update
()
display_update
()
...
@@ -88,37 +67,18 @@ def set_rel_volume(vol):
...
@@ -88,37 +67,18 @@ def set_rel_volume(vol):
set_global_volume_dB
(
VOLUME
)
set_global_volume_dB
(
VOLUME
)
time
.
sleep_ms
(
100
)
time
.
sleep_ms
(
100
)
def
captouch_cal
():
global
ctx
display_fill
(
0b0000000111100111
)
ctx
.
move_to
(
0
,
0
).
rgb
(
0
,
255
,
0
).
text
(
"
cal
"
)
display_update
()
time
.
sleep_ms
(
500
)
display_fill
(
0b0011100000000111
)
ctx
.
move_to
(
0
,
0
).
rgb
(
0
,
255
,
0
).
text
(
"
cal
"
)
display_update
()
captouch_autocalib
()
while
(
captouch_calibration_active
()):
pass
display_fill
(
0
)
display_update
()
def
main
():
def
main
():
global
CURRENT_APP_RUN
global
CURRENT_APP_RUN
global
ctx
global
ctx
while
not
init_done
():
while
not
init_done
():
pass
pass
captouch_autocalib
()
#dry run
captouch_autocalib
()
while
(
captouch_calibration_active
()):
pass
ctx
=
get_ctx
()
ctx
=
get_ctx
()
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
ctx
.
text_baseline
=
ctx
.
MIDDLE
captouch_cal
()
for
module
in
MODULES
:
for
module
in
MODULES
:
module
.
init
()
module
.
init
()
...
@@ -128,7 +88,7 @@ def main():
...
@@ -128,7 +88,7 @@ def main():
while
True
:
while
True
:
if
((
get_button
(
1
)
==
2
)
and
(
CURRENT_APP_RUN
==
run_menu
)):
if
((
get_button
(
1
)
==
2
)
and
(
CURRENT_APP_RUN
==
run_menu
)):
captouch_cal
()
captouch_
auto
cal
ib
()
foreground_menu
()
foreground_menu
()
else
:
else
:
if
(
get_button
(
0
)
==
2
):
if
(
get_button
(
0
)
==
2
):
...
...
This diff is collapsed.
Click to expand it.
python_payload/utils.py
+
11
−
4
View file @
eb578558
...
@@ -39,13 +39,20 @@ def draw_rect(x,y,w,h,col):
...
@@ -39,13 +39,20 @@ def draw_rect(x,y,w,h,col):
for
k
in
range
(
h
):
for
k
in
range
(
h
):
display_draw_pixel
(
x
+
j
,
y
+
k
,
col
)
display_draw_pixel
(
x
+
j
,
y
+
k
,
col
)
def
draw_volume_slider
(
volume
):
def
draw_volume_slider
(
ctx
,
volume
):
length
=
96
+
((
volume
-
20
)
*
1.6
)
length
=
96
+
((
volume
-
20
)
*
1.6
)
if
length
>
96
:
if
length
>
96
:
length
=
96
length
=
96
if
length
<
0
:
if
length
<
0
:
length
=
0
length
=
0
length
=
int
(
length
)
length
=
int
(
length
)
draw_rect
(
70
,
20
,
100
,
10
,
GREEN
)
draw_rect
(
71
,
21
,
98
,
8
,
0
)
ctx
.
rgb
(
0
,
0
,
0
)
#dummy
draw_rect
(
72
+
96
-
length
,
22
,
length
,
6
,
GREEN
)
ctx
.
round_rectangle
(
-
49
,
41
,
98
,
8
,
3
).
fill
()
#dummy idk
ctx
.
rgb
(
0
,
255
,
0
)
ctx
.
round_rectangle
(
-
51
,
49
,
102
,
12
,
3
).
fill
()
ctx
.
rgb
(
0
,
0
,
0
)
ctx
.
round_rectangle
(
-
50
,
50
,
100
,
10
,
3
).
fill
()
ctx
.
rgb
(
0
,
255
,
0
)
ctx
.
round_rectangle
(
-
48
,
52
,
length
,
6
,
3
).
fill
()
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