diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-26 22:12:05 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-26 22:12:05 (GMT) |
| commit | afb9bd16b6c811f1a211e3a159b57aa1a787073f (patch) | |
| tree | 96ada2501478518d328855cd9396669d1602f5ef | |
| parent | af33c7d79b46ffbaabc399e51d0040cf2bacf720 (diff) | |
wasp: Add support for brightness caching and keep-awake signalling
| -rw-r--r-- | wasp/apps/flashlight.py | 10 | ||||
| -rw-r--r-- | wasp/wasp.py | 22 |
2 files changed, 24 insertions, 8 deletions
diff --git a/wasp/apps/flashlight.py b/wasp/apps/flashlight.py index 3336cfa..161aade 100644 --- a/wasp/apps/flashlight.py +++ b/wasp/apps/flashlight.py @@ -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.""" diff --git a/wasp/wasp.py b/wasp/wasp.py index 4c0689c..e9647a9 100644 --- a/wasp/wasp.py +++ b/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() |
