From 8305cd323eba789da8fce8342f0d2ddc313ec18e Mon Sep 17 00:00:00 2001 From: Matthew Wilkes Date: Sat, 25 May 2024 00:14:16 +0100 Subject: [PATCH] Updates testing on real hardware --- modules/app_components/dialog.py | 5 ++--- modules/firmware_apps/text_demo.py | 13 +++++++++++-- modules/system/launcher/app.py | 2 ++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/app_components/dialog.py b/modules/app_components/dialog.py index a2666e0..0a85fcf 100644 --- a/modules/app_components/dialog.py +++ b/modules/app_components/dialog.py @@ -1,5 +1,4 @@ import asyncio -import string import display from events.input import BUTTON_TYPES, ButtonDownEvent @@ -70,7 +69,7 @@ def _handle_buttondown(self, event: ButtonDownEvent): class TextDialog: - alphabet = string.ascii_letters + alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" def __init__(self, message, app, masked=False, on_complete=None, on_cancel=None): self.open = True @@ -94,7 +93,7 @@ async def run(self, render_update): # Tightly loop, waiting for a result, then return it while self._result is None: - await asyncio.sleep(0.05) + await render_update() self.app.overlays.pop() await render_update() return self._result diff --git a/modules/firmware_apps/text_demo.py b/modules/firmware_apps/text_demo.py index eeb70ac..2f781c7 100644 --- a/modules/firmware_apps/text_demo.py +++ b/modules/firmware_apps/text_demo.py @@ -1,5 +1,7 @@ import app from app_components import TextDialog, clear_background +from events.input import BUTTON_TYPES, ButtonDownEvent +from system.eventbus import eventbus class TextDemo(app.App): @@ -16,14 +18,21 @@ async def run(self, render_update): if await dialog.run(render_update): self.name = dialog.text + eventbus.on(ButtonDownEvent, self._handle_buttondown, self) + self.overlays = [] - await render_update() + while True: + await render_update() + + def _handle_buttondown(self, event: ButtonDownEvent): + if BUTTON_TYPES["CANCEL"] in event.button: + self.minimise() def draw(self, ctx): clear_background(ctx) ctx.save() - ctx.text_align = "center" + ctx.text_align = ctx.CENTER ctx.gray(1).move_to(0, 0).text("Hello " + self.name) ctx.restore() diff --git a/modules/system/launcher/app.py b/modules/system/launcher/app.py index dc8a6b0..c525d5b 100644 --- a/modules/system/launcher/app.py +++ b/modules/system/launcher/app.py @@ -78,6 +78,7 @@ def list_core_apps(self): # ("Name Badge", "hello", "Hello"), ("Logo", "firmware_apps.intro_app", "IntroApp"), ("Menu demo", "firmware_apps.menu_demo", "MenuDemo"), + ("Kbd demo", "firmware_apps.text_demo", "TextDemo"), # ("Update Firmware", "otaupdate", "OtaUpdate"), # ("Wi-Fi Connect", "wifi_client", "WifiClient"), # ("Sponsors", "sponsors", "Sponsors"), @@ -85,6 +86,7 @@ def list_core_apps(self): # ("Accelerometer", "accel_app", "Accel"), # ("Magnetometer", "magnet_app", "Magnetometer"), ("Update", "system.ota.ota", "OtaUpdate"), + ("Power Off", "firmware_apps.poweroff", "PowerOff"), # ("Settings", "settings_app", "SettingsApp"), ] core_apps = []