From 231f3b6fdd531b1f3fcec927bc297f4c89853aec Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sun, 3 Jan 2021 14:54:34 +0000 Subject: apps: software: Add an apps to enable/disable other apps Currently wasp-os enables a narrow set of applications because we don't want to consume RAM by importing the module and constructing the application. We can improve on this situation by providing a small (stateless) application that can be used to enable or diable applications. This allows all the ROMed applications to be enabled using the GUI without compromising on the ability to develop applications. In fact this application significantlly reduces the RAM consumed in the default case becasue the Self Test app does not need to maintain its state. Signed-off-by: Daniel Thompson diff --git a/res/app_icon.png b/res/app_icon.png index 438cded..48a31db 100644 Binary files a/res/app_icon.png and b/res/app_icon.png differ diff --git a/res/software_icon.png b/res/software_icon.png new file mode 100644 index 0000000..438cded Binary files /dev/null and b/res/software_icon.png differ diff --git a/wasp/apps/flashlight.py b/wasp/apps/flashlight.py index 95c44b2..f5b8684 100644 --- a/wasp/apps/flashlight.py +++ b/wasp/apps/flashlight.py @@ -11,7 +11,7 @@ import wasp import icons -class FlashlightApp(object): +class TorchApp(object): """Trivial flashlight application. .. figure:: res/TorchApp.png diff --git a/wasp/apps/software.py b/wasp/apps/software.py new file mode 100644 index 0000000..2c7869c --- /dev/null +++ b/wasp/apps/software.py @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (C) 2020 Daniel Thompson +"""Wizard to generate main.py.""" + +import wasp +import icons + +class SoftwareApp(): + """Enable and disable applications.""" + NAME = 'Software' + ICON = icons.software + + def foreground(self): + """Activate the application.""" + self.db = ( + ('alarm', wasp.widgets.Checkbox(0, 0, 'Alarm')), + ('calc', wasp.widgets.Checkbox(0, 40, 'Calculator')), + ('chrono', wasp.widgets.Checkbox(0, 80, 'Chrono')), + ('fibonacci_clock', wasp.widgets.Checkbox(0, 120, 'Fibonacci Clock')), + ('gameoflife', wasp.widgets.Checkbox(0, 160, 'Game Of Life')), + ('musicplayer', wasp.widgets.Checkbox(0, 0, 'Music Player')), + ('snake', wasp.widgets.Checkbox(0, 40, 'Snake Game')), + ('flashlight', wasp.widgets.Checkbox(0, 80, 'Torch')), + ('testapp', wasp.widgets.Checkbox(0, 120, 'Test')), + ) + self.si = wasp.widgets.ScrollIndicator() + self.page = 0 + + # Get the initial state for the checkboxes + for _, checkbox in self.db: + label = checkbox.label.replace(' ', '') + for app in wasp.system.launcher_ring: + if type(app).__name__.startswith(label): + checkbox.state = True + break + + self._draw() + wasp.system.request_event(wasp.EventMask.TOUCH | + wasp.EventMask.SWIPE_UPDOWN) + + def get_page(self): + i = self.page * 5 + return self.db[i:i+5] + + def swipe(self, event): + """Notify the application of a touchscreen swipe event.""" + page = self.page + pages = 1 + if event[0] == wasp.EventType.UP: + page = page - 1 if page > 0 else pages + if event[0] == wasp.EventType.DOWN: + page = page + 1 if page < pages else 0 + self.page = page + + mute = wasp.watch.display.mute + mute(True) + self._draw() + mute(False) + + def touch(self, event): + """Notify the application of a touchscreen touch event.""" + for module, checkbox in self.get_page(): + if checkbox.touch(event): + label = checkbox.label.replace(' ', '') + if checkbox.state: + exec('import apps.{}'.format(module)) + exec('wasp.system.register(apps.{}.{}App())'.format(module, label)) + else: + for app in wasp.system.launcher_ring: + if type(app).__name__.startswith(label): + wasp.system.launcher_ring.remove(app) + break + break + + def _draw(self): + """Draw the display from scratch.""" + wasp.watch.drawable.fill() + self.si.draw() + for _, checkbox in self.get_page(): + checkbox.draw() diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py index 8b8ff67..acd1735 100644 --- a/wasp/apps/testapp.py +++ b/wasp/apps/testapp.py @@ -133,7 +133,7 @@ class TestApp(): t = machine.Timer(id=1, period=8000000) t.start() for i in range(0, 128, 16): - draw.blit(self.ICON, i+16, i+32) + draw.blit(icons.software, i+16, i+32) elapsed = t.time() t.stop() del t diff --git a/wasp/icons.py b/wasp/icons.py index 7eb2e22..2ccd140 100644 --- a/wasp/icons.py +++ b/wasp/icons.py @@ -27,12 +27,56 @@ bomb = ( b'\x0e' ) -# 2-bit RLE, generated from res/app_icon.png, 460 bytes +# 2-bit RLE, generated from res/app_icon.png, 224 bytes app = ( b'\x02' b'`@' b'\x1e@\x81d