From 59ee61200c9bce3b2e977303e034fc4fb6194282 Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Wed, 11 Dec 2019 15:27:29 -0700 Subject: [PATCH] added the backlight control and some code for doing repaints --- scripts/demo1.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/demo1.py b/scripts/demo1.py index 955c17d..2f71408 100755 --- a/scripts/demo1.py +++ b/scripts/demo1.py @@ -2,6 +2,7 @@ import upiwin # Save off some color values. +BLACK = upiwin.rgb(0, 0, 0) WHITE = upiwin.rgb(255, 255, 255) LTGRAY = upiwin.rgb(204, 204, 204) RED = upiwin.rgb(255, 0, 0) @@ -33,6 +34,21 @@ cmd4_rect = (command_rect[0], 180, command_rect[2], command_rect[3]) def point_in_rect(rect, x, y): return (x >= rect[0]) and (x < rect[2]) and (y >= rect[1]) and (y < rect[3]) + +# --- Backlight control --- + +backlight_level_list = [1023, 768, 512, 256] +current_backlight = 0 + +def do_backlight(): + upiwin.set_backlight_level(backlight_level_list[current_backlight]) + +def select_next_backlight(): + global current_backlight + current_backlight += 1 + if (current_backlight == len(backlight_level_list): + current_backlight = 0 + do_backlight() # --- Color selections --- @@ -83,6 +99,14 @@ def draw_object(obj): objects_drawn = [] +def repaint(): + global drawing_rect, objects_drawn + hdc.text_color = BLACK + hdc.rop2 = upiwin.R2_COPYPEN + hdc.solid_rectangle(drawing_rect[0], drawing_rect[1], drawing_rect[2], drawing_rect[3]) + for obj in objects_drawn: + draw_object(obj) + # --- Graphic feedback -- origin_x = 0 @@ -197,11 +221,15 @@ def on_touchclick(x, y): print("Click command 4") def on_button_click(button): + if button == 1: # Button 1 = Set backlight level + select_next_backlight() if button == 4: # Button 4 = Exit app upiwin.post_quit_message(0) # --- Initialize and start message loop --- +do_backlight() + # Draw the basic layout. hdc.text_color = LTGRAY hdc.rop2 = upiwin.R2_COPYPEN