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
eb578558
Commit
eb578558
authored
1 year ago
by
dx
Committed by
q3k
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
python_payload: menu/worms cleanup
parent
d764e4a5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide 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
...
...
@@ -5,16 +5,16 @@ import math
def
xy_from_polar
(
r
,
deg
):
#rad = deg/180*math.pi
return
(
(
return
(
r
*
math
.
sin
(
deg
),
#x
r
*
math
.
cos
(
deg
)
#y
)
)
)
def
randrgb
():
return
((
random
.
random
(),
random
.
random
(),
random
.
random
()))
WIDTH
=
240
HEIGHT
=
240
...
...
@@ -26,23 +26,11 @@ BLUE = (0,0,1)
WHITE
=
(
1
,
1
,
1
)
GREY
=
(
0.5
,
0.5
,
0.5
)
#
Get t
he global context (representing the whole screen)
global
ctx
#
T
he global context (representing the whole screen)
ctx
=
None
'''
#center the text horizontally and vertically
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
worms
=
None
#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
():
def
__init__
(
self
):
...
...
@@ -57,7 +45,6 @@ class Worm():
self
.
_lastdist
=
0.0
def
draw
(
self
):
global
ctx
ctx
.
rgb
(
*
self
.
color
)
ctx
.
round_rectangle
(
self
.
x
-
self
.
size
/
2
,
...
...
@@ -90,8 +77,6 @@ class Worm():
self
.
_lastdist
=
dist
global
worms
def
init
():
global
worms
global
ctx
...
...
@@ -110,7 +95,17 @@ def run():
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:
#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
import
time
import
harmonic_demo
import
melodic_demo
import
cap_touch_demo
import
demo_worms
MODULES
=
[
harmonic_demo
,
melodic_demo
,
cap_touch_demo
,
demo_worms
,
]
...
...
@@ -20,30 +18,12 @@ ctx = None
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
():
global
CURRENT_APP_RUN
global
ctx
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
"
)
display_update
()
...
...
@@ -70,7 +50,6 @@ def foreground_menu():
utils
.
highlight_bottom_petal
(
0
,
0
,
55
,
55
);
utils
.
highlight_bottom_petal
(
1
,
55
,
0
,
55
);
utils
.
highlight_bottom_petal
(
2
,
55
,
55
,
0
);
utils
.
highlight_bottom_petal
(
3
,
0
,
110
,
0
);
display_fill
(
BACKGROUND_COLOR
)
display_update
()
...
...
@@ -88,37 +67,18 @@ def set_rel_volume(vol):
set_global_volume_dB
(
VOLUME
)
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
():
global
CURRENT_APP_RUN
global
ctx
while
not
init_done
():
pass
captouch_autocalib
()
#dry run
while
(
captouch_calibration_active
()):
pass
captouch_autocalib
()
ctx
=
get_ctx
()
ctx
.
text_align
=
ctx
.
CENTER
ctx
.
text_baseline
=
ctx
.
MIDDLE
captouch_cal
()
for
module
in
MODULES
:
module
.
init
()
...
...
@@ -128,7 +88,7 @@ def main():
while
True
:
if
((
get_button
(
1
)
==
2
)
and
(
CURRENT_APP_RUN
==
run_menu
)):
captouch_cal
()
captouch_
auto
cal
ib
()
foreground_menu
()
else
:
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):
for
k
in
range
(
h
):
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
)
if
length
>
96
:
length
=
96
if
length
<
0
:
length
=
0
length
=
int
(
length
)
draw_rect
(
70
,
20
,
100
,
10
,
GREEN
)
draw_rect
(
71
,
21
,
98
,
8
,
0
)
draw_rect
(
72
+
96
-
length
,
22
,
length
,
6
,
GREEN
)
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
()
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