summaryrefslogtreecommitdiff
path: root/wasp/apps
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-07-19 19:50:33 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-07-19 19:50:33 (GMT)
commita01fb7df573e13a6f6b9fbf2e7688d4e9713df6d (patch)
tree5118831a0fa174681ade9aaf850b7613309a2803 /wasp/apps
parent6686f17e724b9a22318ff2248ce126a97dd19db4 (diff)
Introduction basic notification support
This requires a modified version of Gadgetbridge and currently works by implementing the BangleJS protocol. In Gadgetbridge ensure "Sync time" is *not* set and choose "Don't pair" when adding the PineTime device.
Diffstat (limited to 'wasp/apps')
-rw-r--r--wasp/apps/clock.py2
-rw-r--r--wasp/apps/pager.py34
-rw-r--r--wasp/apps/testapp.py22
3 files changed, 50 insertions, 8 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py
index f09f2d4..a3134a0 100644
--- a/wasp/apps/clock.py
+++ b/wasp/apps/clock.py
@@ -35,6 +35,7 @@ class ClockApp():
def __init__(self):
self.meter = wasp.widgets.BatteryMeter()
+ self.notifier = wasp.widgets.Notifier()
def foreground(self):
"""Activate the application."""
@@ -87,4 +88,5 @@ class ClockApp():
0, 180, width=240)
self.meter.update()
+ self.notifier.update()
return True
diff --git a/wasp/apps/pager.py b/wasp/apps/pager.py
index 18322d2..edb5418 100644
--- a/wasp/apps/pager.py
+++ b/wasp/apps/pager.py
@@ -26,16 +26,13 @@ class PagerApp():
def foreground(self):
"""Activate the application."""
- self._page = 0
- self._chunks = wasp.watch.drawable.wrap(self._msg, 240)
- self._numpages = (len(self._chunks) - 2) // 9
wasp.system.request_event(wasp.EventMask.SWIPE_UPDOWN)
- self._draw()
+ self._redraw()
def background(self):
"""De-activate the application."""
- del self._chunks
- del self._numpages
+ self._chunks = None
+ self._numpages = None
def swipe(self, event):
"""Swipe to page up/down."""
@@ -55,8 +52,15 @@ class PagerApp():
self._draw()
mute(False)
+ def _redraw(self):
+ """Redraw from scratch (jump to the first page)"""
+ self._page = 0
+ self._chunks = wasp.watch.drawable.wrap(self._msg, 240)
+ self._numpages = (len(self._chunks) - 2) // 9
+ self._draw()
+
def _draw(self):
- """Draw the display from scratch."""
+ """Draw a page from scratch."""
draw = wasp.watch.drawable
draw.fill()
@@ -73,6 +77,22 @@ class PagerApp():
scroll.down = page < self._numpages
scroll.draw()
+class NotificationApp(PagerApp):
+ NAME = 'Notifications'
+
+ def __init__(self):
+ super().__init__('')
+
+ def foreground(self):
+ notes = wasp.system.notifications
+
+ id = next(iter(notes))
+ note = notes[id]
+ del notes[id]
+ self._msg = '{}\n\n{}'.format(note['title'], note['body'])
+
+ super().foreground()
+
class CrashApp():
"""Crash handler application.
diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py
index a312530..e2e8828 100644
--- a/wasp/apps/testapp.py
+++ b/wasp/apps/testapp.py
@@ -16,7 +16,7 @@ class TestApp():
ICON = icons.app
def __init__(self):
- self.tests = ('Button', 'Crash', 'Colours', 'Fill', 'Fill-H', 'Fill-V', 'RLE', 'String', 'Touch', 'Wrap')
+ self.tests = ('Button', 'Crash', 'Colours', 'Fill', 'Fill-H', 'Fill-V', 'Notifications', 'RLE', 'String', 'Touch', 'Wrap')
self.test = self.tests[0]
self.scroll = wasp.widgets.ScrollIndicator()
@@ -70,6 +70,19 @@ class TestApp():
self._update_colours()
elif self.test.startswith('Fill'):
self._benchmark_fill()
+ elif self.test == 'Notifications':
+ if event[1] < 120:
+ wasp.system.notify(wasp.watch.rtc.get_uptime_ms(),
+ {
+ "src":"Hangouts",
+ "title":"A Name",
+ "body":"message contents"
+ })
+ else:
+ if wasp.system.notifications:
+ wasp.system.unnotify(
+ next(iter(wasp.system.notifications.keys())))
+ self._update_notifications()
elif self.test == 'RLE':
self._benchmark_rle()
elif self.test == 'String':
@@ -166,6 +179,10 @@ class TestApp():
for s in self._sliders:
s.draw()
self._update_colours()
+ elif self.test == 'Notifications':
+ draw.string('+', 24, 100)
+ draw.string('-', 210, 100)
+ self._update_notifications()
elif self.test == 'RLE':
draw.blit(self.ICON, 120-48, 120-32)
@@ -181,3 +198,6 @@ class TestApp():
draw.string('RGB565 #{:04x}'.format(rgb), 0, 6, width=240)
draw.fill(rgb, 60, 35, 120, 50)
+
+ def _update_notifications(self):
+ wasp.watch.drawable.string(str(len(wasp.system.notifications)), 0, 140, 240)