summaryrefslogtreecommitdiff
path: root/wasp/apps
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-06 21:03:05 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-06 21:04:21 (GMT)
commit8ed80eeebab06dba5839a7f08703494a9917348a (patch)
tree42ae928cd966ca56ca23345cad6653fbca5dc727 /wasp/apps
parent59bb70fa649d1994d367e69fb6272f36a6176825 (diff)
wasp: launcher: Experimental launcher implementation
It is not really the launcher itself that is immature. Rather that the framework and UI concepts to move between applications isn't complete yet.
Diffstat (limited to 'wasp/apps')
-rw-r--r--wasp/apps/clock.py3
-rw-r--r--wasp/apps/flashlight.py4
-rw-r--r--wasp/apps/launcher.py80
-rw-r--r--wasp/apps/testapp.py4
4 files changed, 91 insertions, 0 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py
index 4feba63..4236d9a 100644
--- a/wasp/apps/clock.py
+++ b/wasp/apps/clock.py
@@ -3,6 +3,7 @@
import wasp
+import icons
import fonts.clock as digits
DIGITS = (
@@ -25,6 +26,8 @@ class ClockApp():
Shows a time (as HH:MM) together with a battery meter and the date.
"""
+ NAME = 'Clock'
+ ICON = icons.clock
def __init__(self):
self.meter = wasp.widgets.BatteryMeter()
diff --git a/wasp/apps/flashlight.py b/wasp/apps/flashlight.py
index 13e3443..c4702a0 100644
--- a/wasp/apps/flashlight.py
+++ b/wasp/apps/flashlight.py
@@ -3,11 +3,15 @@
import wasp
+import icons
+
class FlashlightApp(object):
"""Trivial flashlight application.
Shows a pure white screen with the backlight set to maximum.
"""
+ NAME = 'Torch'
+ ICON = icons.torch
def foreground(self):
"""Activate the application."""
diff --git a/wasp/apps/launcher.py b/wasp/apps/launcher.py
new file mode 100644
index 0000000..274ea9c
--- /dev/null
+++ b/wasp/apps/launcher.py
@@ -0,0 +1,80 @@
+# SPDX-License-Identifier: LGPL-3.0-or-later
+# Copyright (C) 2020 Daniel Thompson
+
+import wasp
+import icons
+
+class LauncherApp():
+ """An application launcher application.
+ """
+ NAME = 'Launcher'
+ ICON = icons.app
+
+ def foreground(self):
+ """Activate the application."""
+ self._page = 0
+ self._draw()
+ wasp.system.request_event(wasp.EventMask.TOUCH |
+ wasp.EventMask.SWIPE_UPDOWN)
+
+ def swipe(self, event):
+ i = self._page
+ n = self._num_pages
+ if event[0] == wasp.EventType.UP:
+ i += 1
+ if i >= n:
+ i -= 1
+ wasp.watch.vibrator.pulse()
+ return
+ else:
+ i -= 1
+ if i < 0:
+ wasp.system.switch(wasp.system.applications[0])
+ return
+
+ self._page = i
+ wasp.watch.display.mute(True)
+ self._draw()
+ wasp.watch.display.mute(False)
+
+ def touch(self, event):
+ page = self._get_page(self._page)
+ x = event[1]
+ y = event[2]
+ app = page[2 * (y // 120) + (x // 120)]
+ if app:
+ wasp.system.switch(app)
+ else:
+ wasp.watch.vibrator.pulse()
+
+ @property
+ def _num_pages(self):
+ """Work out what the highest possible pages it."""
+ num_apps = len(wasp.system.applications)
+ return (num_apps + 3) // 4
+
+ def _get_page(self, i):
+ apps = wasp.system.applications
+ page = apps[4*i: 4*(i+1)]
+ while len(page) < 4:
+ page.append(None)
+ return page
+
+ def _draw(self):
+ """Redraw the display from scratch."""
+ def draw_app(app, x, y):
+ if not app:
+ return
+ draw.set_color(0xffff)
+ draw.rleblit(app.ICON, (x+13, y+12))
+ draw.set_color(0xbdb6)
+ draw.string(app.NAME, x, y+120-30, 120)
+
+ draw = wasp.watch.drawable
+ page = self._get_page(self._page)
+
+ draw.fill()
+ draw_app(page[0], 0, 0)
+ draw_app(page[1], 120, 0)
+ draw_app(page[2], 0, 120)
+ draw_app(page[3], 120, 120)
diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py
index 8c15848..478249f 100644
--- a/wasp/apps/testapp.py
+++ b/wasp/apps/testapp.py
@@ -3,10 +3,13 @@
import machine
import wasp
+import icons
class TestApp():
"""Simple test application.
"""
+ NAME = 'Self Test'
+ ICON = icons.app
def __init__(self):
self.tests = ('Touch', 'String', 'Button', 'Crash')
@@ -57,6 +60,7 @@ class TestApp():
def benchmark_string(self):
draw = wasp.watch.drawable
draw.fill(0, 0, 30, 240, 240-30)
+ self.scroll.draw()
t = machine.Timer(id=1, period=8000000)
t.start()
draw.string("The quick brown", 12, 24+24)