diff --git a/python_payload/demo_worms.py b/python_payload/demo_worms.py index b96beb1d57dd8275b25c21707d549cb4744813ae..87a11a598923570a4308935f1f9acbb02aa7fa9b 100644 --- a/python_payload/demo_worms.py +++ b/python_payload/demo_worms.py @@ -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 the global context (representing the whole screen) -global ctx +# The 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 diff --git a/python_payload/main.py b/python_payload/main.py index 033dae6964953b72d7ad5dd8450390ddff74616f..d678944c295b4d56a4bf2e61f4acf0c2244b6073 100644 --- a/python_payload/main.py +++ b/python_payload/main.py @@ -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_autocalib() foreground_menu() else: if(get_button(0) == 2): diff --git a/python_payload/utils.py b/python_payload/utils.py index 88ca4d3ba33ff0c8f5f66d5182b3f4dc97871ba9..8ad43e97cb24187401e82c37f10a09bc855fc857 100644 --- a/python_payload/utils.py +++ b/python_payload/utils.py @@ -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()