Notify level in settings app
Signed-off-by: Carlos Gil Gonzalez <carlosgilglez@gmail.com> [daniel@redfelineninja.org.uk: Fixed board support for simulator and sphinx (a.k.a. doc builder)] Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
e450ccf9f0
commit
3fb1faceab
5 changed files with 72 additions and 11 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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':
|
||||
|
|
21
wasp/wasp.py
21
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.
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue