From 4e121eab3a94f8bcb06744f8ecba313579330d67 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Tue, 21 Mar 2023 16:35:46 +0000 Subject: [PATCH] Image: Tidyup and fix battery quirks. Simplified image.py by removing help text and readme creation. Tried to avoid "state_save" right before updating the display. --- badger_os/examples/image.py | 38 +++---------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/badger_os/examples/image.py b/badger_os/examples/image.py index 95e4036..ab72e91 100644 --- a/badger_os/examples/image.py +++ b/badger_os/examples/image.py @@ -1,39 +1,20 @@ import os -import sys -import time import badger2040 from badger2040 import HEIGHT, WIDTH import badger_os import jpegdec -REAMDE = """ -Images must be 296x128 pixel JPEGs - -Create a new "images" directory via Thonny, and upload your .jpg files there. -""" - -OVERLAY_BORDER = 40 -OVERLAY_SPACING = 20 -OVERLAY_TEXT_SIZE = 0.5 - TOTAL_IMAGES = 0 # Turn the act LED on as soon as possible display = badger2040.Badger2040() display.led(128) +display.set_update_speed(badger2040.UPDATE_NORMAL) jpeg = jpegdec.JPEG(display.display) -# Try to preload BadgerPunk image -try: - os.mkdir("/images") - with open("/images/readme.txt", "w") as f: - f.write(REAMDE) - f.flush() -except (OSError, ImportError): - pass # Load images try: @@ -77,11 +58,7 @@ def show_image(n): if TOTAL_IMAGES == 0: - display.set_pen(15) - display.clear() - badger_os.warning(display, "To run this demo, create an /images directory on your device and upload some 1bit 296x128 pixel images.") - time.sleep(4.0) - sys.exit() + raise RuntimeError("To run this demo, create an /images directory on your device and upload some 1bit 296x128 pixel images.") badger_os.state_load("image", state) @@ -108,18 +85,9 @@ def show_image(n): state["show_info"] = not state["show_info"] changed = True - if display.pressed(badger2040.BUTTON_B) or display.pressed(badger2040.BUTTON_C): - display.set_pen(15) - display.clear() - badger_os.warning(display, "To add images connect Badger2040 to a PC, load up Thonny, and see readme.txt in images/") - display.update() - print(state["current_image"]) - time.sleep(4) - changed = True - if changed: - badger_os.state_save("image", state) show_image(state["current_image"]) + badger_os.state_save("image", state) changed = False # Halt the Badger to save power, it will wake up if any of the front buttons are pressed