wasp: Add support for brightness caching and keep-awake signalling
This commit is contained in:
parent
af33c7d79b
commit
afb9bd16b6
2 changed files with 24 additions and 8 deletions
|
@ -9,24 +9,24 @@ class FlashlightApp(object):
|
|||
Shows a pure white screen with the backlight set to maximum.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.backlight = None
|
||||
|
||||
def foreground(self, effect=None):
|
||||
"""Activate the application."""
|
||||
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
||||
self.draw(effect)
|
||||
wasp.system.request_tick(1000)
|
||||
|
||||
self._brightness = wasp.system.brightness
|
||||
wasp.system.brightness = 3
|
||||
|
||||
def background(self):
|
||||
"""De-activate the application (without losing state)."""
|
||||
pass
|
||||
wasp.system.brightness = self._brightness
|
||||
|
||||
def sleep(self):
|
||||
return False
|
||||
|
||||
def tick(self, ticks):
|
||||
pass
|
||||
wasp.system.keep_awake()
|
||||
|
||||
def draw(self, effect=None):
|
||||
"""Redraw the display from scratch."""
|
||||
|
|
22
wasp/wasp.py
22
wasp/wasp.py
|
@ -57,6 +57,18 @@ class Manager():
|
|||
]
|
||||
self.charging = True
|
||||
|
||||
self._brightness = 2
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Cached copy of the brightness current written to the hardware."""
|
||||
return self._brightness
|
||||
|
||||
@brightness.setter
|
||||
def brightness(self, value):
|
||||
self._brightness = value
|
||||
watch.backlight.set(self._brightness)
|
||||
|
||||
def switch(self, app):
|
||||
"""Switch to the requested application.
|
||||
"""
|
||||
|
@ -66,7 +78,7 @@ class Manager():
|
|||
# System start up...
|
||||
watch.display.poweron()
|
||||
watch.display.mute(True)
|
||||
watch.backlight.set(2)
|
||||
watch.backlight.set(self._brightness)
|
||||
self.sleep_at = watch.rtc.uptime + 90
|
||||
|
||||
# Clear out any configuration from the old application
|
||||
|
@ -117,6 +129,10 @@ class Manager():
|
|||
self.tick_period_ms = period_ms
|
||||
self.tick_expiry = watch.rtc.get_uptime_ms() + period_ms
|
||||
|
||||
def keep_awake(self):
|
||||
"""Reset the keep awake timer."""
|
||||
self.sleep_at = watch.rtc.uptime + 15
|
||||
|
||||
def _handle_event(self, event):
|
||||
"""Process an event.
|
||||
"""
|
||||
|
@ -155,7 +171,7 @@ class Manager():
|
|||
self.app.tick(ticks)
|
||||
|
||||
if watch.button.value():
|
||||
self.sleep_at = watch.rtc.uptime + 15
|
||||
self.keep_awake()
|
||||
|
||||
event = watch.touch.get_event()
|
||||
if event:
|
||||
|
@ -178,7 +194,7 @@ class Manager():
|
|||
if watch.button.value() or self.charging != charging:
|
||||
watch.display.poweron()
|
||||
self.app.wake()
|
||||
watch.backlight.set(2)
|
||||
watch.backlight.set(self._brightness)
|
||||
|
||||
# Discard any pending touch events
|
||||
_ = watch.touch.get_event()
|
||||
|
|
Loading…
Add table
Reference in a new issue