From 3fb1faceab8c4067cf636e0628ab44fe77582f72 Mon Sep 17 00:00:00 2001 From: Carlosgg Date: Tue, 27 Oct 2020 17:10:56 +0000 Subject: [PATCH] Notify level in settings app Signed-off-by: Carlos Gil Gonzalez [daniel@redfelineninja.org.uk: Fixed board support for simulator and sphinx (a.k.a. doc builder)] Signed-off-by: Daniel Thompson --- wasp/apps/settings.py | 56 ++++++++++++++++++++++++++++------ wasp/boards/simulator/watch.py | 3 +- wasp/boards/sphinx/watch.py | 2 ++ wasp/gadgetbridge.py | 1 + wasp/wasp.py | 21 +++++++++++++ 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/wasp/apps/settings.py b/wasp/apps/settings.py index a50cd9c..8dae9c0 100644 --- a/wasp/apps/settings.py +++ b/wasp/apps/settings.py @@ -19,29 +19,65 @@ class SettingsApp(): def __init__(self): self._slider = wasp.widgets.Slider(3, 10, 90) + self._nfy_slider = wasp.widgets.Slider(3, 10, 90) + self._settings = ['Brightness', 'Notification Level'] + self._sett_index = 0 + self._current_setting = self._settings[0] def foreground(self): self._slider.value = wasp.system.brightness - 1 self._draw() wasp.system.request_event(wasp.EventMask.TOUCH) + wasp.system.request_event(wasp.EventMask.SWIPE_UPDOWN) def touch(self, event): - self._slider.touch(event) - wasp.system.brightness = self._slider.value + 1 + if self._current_setting == 'Brightness': + self._slider.touch(event) + wasp.system.brightness = self._slider.value + 1 + elif self._current_setting == 'Notification Level': + self._nfy_slider.touch(event) + wasp.system.notify_level = self._nfy_slider.value + 1 self._update() + def swipe(self, event): + """Handle NEXT events by augmenting the default processing by resetting + the count if we are not currently timing something. + + No other swipe event is possible for this application. + """ + if event[0] == wasp.EventType.UP: + self._sett_index += 1 + self._draw() + elif event[0] == wasp.EventType.DOWN: + self._sett_index -= 1 + self._draw() + def _draw(self): """Redraw the display from scratch.""" + self._current_setting = self._settings[self._sett_index % len(self._settings)] wasp.watch.drawable.fill() - wasp.watch.drawable.string('Brightness', 0, 6, width=240) + wasp.watch.drawable.string(self._current_setting, 0, 6, width=240) + if self._current_setting == 'Brightness': + self._slider.value = wasp.system.brightness - 1 + elif self._current_setting == 'Notification Level': + self._nfy_slider.value = wasp.system.notify_level - 1 self._update() def _update(self): - if wasp.system.brightness == 3: - say = "High" - elif wasp.system.brightness == 2: - say = "Mid" - else: - say = "Low" + if self._current_setting == 'Brightness': + if wasp.system.brightness == 3: + say = "High" + elif wasp.system.brightness == 2: + say = "Mid" + else: + say = "Low" + self._slider.update() + elif self._current_setting == 'Notification Level': + if wasp.system.notify_level == 3: + say = "High" + elif wasp.system.notify_level == 2: + say = "Mid" + else: + say = "Silent" + self._nfy_slider.update() wasp.watch.drawable.string(say, 0, 150, width=240) - self._slider.update() diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py index e19e728..98d9246 100644 --- a/wasp/boards/simulator/watch.py +++ b/wasp/boards/simulator/watch.py @@ -12,8 +12,9 @@ def print_exception(exc, file=sys.stdout): traceback.print_exception(exc_type, exc_value, exc_traceback, file=file) sys.print_exception = print_exception -import draw565 import array +import draw565 +import os from machine import I2C from machine import Pin diff --git a/wasp/boards/sphinx/watch.py b/wasp/boards/sphinx/watch.py index 6ffcd5f..2a6e498 100644 --- a/wasp/boards/sphinx/watch.py +++ b/wasp/boards/sphinx/watch.py @@ -46,6 +46,8 @@ def sleep_ms(ms): time.sleep(ms / 1000) time.sleep_ms = sleep_ms +import os + class Accel(): def reset(self): pass diff --git a/wasp/gadgetbridge.py b/wasp/gadgetbridge.py index 8401d0c..18285ab 100644 --- a/wasp/gadgetbridge.py +++ b/wasp/gadgetbridge.py @@ -49,6 +49,7 @@ def GB(cmd): id = cmd['id'] del cmd['id'] wasp.system.notify(id, cmd) + wasp.watch.vibrator.pulse(ms=wasp.system.notify_duration) elif task == 'notify-': wasp.system.unnotify(cmd['id']) elif task == 'musicstate': diff --git a/wasp/wasp.py b/wasp/wasp.py index a44a61c..7f4d0d4 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -122,6 +122,12 @@ class Manager(): self._alarms = [] self._brightness = 2 + self._notifylevel = 2 + if 'P8' in watch.os.uname().machine: + self._nfylevels = [0, 225, 450] + else: + self._nfylevels = [0, 40, 80] + self._nfylev_ms = self._nfylevels[self._notifylevel - 1] self._button = PinHandler(watch.button) self._charging = True self._scheduled = False @@ -163,6 +169,21 @@ class Manager(): self._brightness = value watch.backlight.set(self._brightness) + @property + def notify_level(self): + """Cached copy of the current notify level""" + return self._notifylevel + + @notify_level.setter + def notify_level(self, value): + self._notifylevel = value + self._nfylev_ms = self._nfylevels[self._notifylevel - 1] + + @property + def notify_duration(self): + """Cached copy of the current vibrator pulse duration in milliseconds""" + return self._nfylev_ms + def switch(self, app): """Switch to the requested application. """