Skip to content
Snippets Groups Projects
Commit efbc8792 authored by dx's avatar dx
Browse files

python_payload: Add demo_worms to the menu, use ctx in the menu

Changes by moon2 from a merge commit in dev_p4 branch
parent 709deef4
No related branches found
No related tags found
No related merge requests found
......@@ -28,8 +28,8 @@ GREY = (0.5,0.5,0.5)
# Get the global context (representing the whole screen)
global ctx
ctx = hardware.get_ctx()
'''
#center the text horizontally and vertically
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
......@@ -42,7 +42,7 @@ 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,6 +57,7 @@ class Worm():
self._lastdist = 0.0
def draw(self):
global ctx
ctx.rgb(*self.color)
ctx.round_rectangle(
self.x-self.size/2,
......@@ -88,20 +89,28 @@ class Worm():
self.mutate()
self._lastdist = dist
worms = []
global worms
def init():
global worms
global ctx
worms = []
for i in range(23):
worms.append(Worm())
ctx = hardware.get_ctx()
while True:
def run():
global worms
for w in worms:
w.draw()
w.move()
hardware.display_update()
time.sleep(0.001)
print ("done")
def foreground():
pass
#Known problems:
#ctx.rotate(math.pi) turns the display black until powercycled
......
......@@ -3,32 +3,48 @@ 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,
]
CURRENT_APP_RUN = None
VOLUME = 0
SELECT_TEXT = [
" ## #### # #### ## ##### ",
"# # # # # # # # ##" ,
"# # # # # # # #",
" ## #### # #### # # #" ,
" # # # # # # # #",
"# # # # # # # # ## ",
" ## #### #### #### ## # ",
]
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)
utils.draw_text_big(SELECT_TEXT, 0, 0)
utils.draw_volume_slider(VOLUME)
draw_volume_slider(VOLUME)
ctx.move_to(0,0).rgb(255,0,255).text("select :3")
display_update()
selected_petal = None
......@@ -53,8 +69,9 @@ def foreground_menu():
utils.clear_all_leds()
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)
utils.draw_text_big(SELECT_TEXT, 0, 0)
display_update()
def set_rel_volume(vol):
......@@ -71,12 +88,36 @@ 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()
captouch_autocalib() #dry run
while(captouch_calibration_active()):
pass
ctx = get_ctx()
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
captouch_cal()
for module in MODULES:
module.init()
......@@ -86,12 +127,15 @@ def main():
set_global_volume_dB(VOLUME)
while True:
if(get_button(0) == 2):
if CURRENT_APP_RUN == run_menu:
captouch_autocalib()
if((get_button(1) == 2) and (CURRENT_APP_RUN == run_menu)):
captouch_cal()
foreground_menu()
else:
if(get_button(0) == 2):
if CURRENT_APP_RUN != run_menu:
CURRENT_APP_RUN = run_menu
foreground_menu()
else:
if(get_button(0) == 1):
set_rel_volume(+1)
if(get_button(0) == -1):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment