wasp: manager: make sleep() and background() callbacks optional
Making callbacks optional reduces pointless boilerplate in applications.
This commit is contained in:
parent
6a6e393d1f
commit
83cc56969e
4 changed files with 7 additions and 22 deletions
|
@ -35,19 +35,15 @@ class ClockApp():
|
||||||
self.draw()
|
self.draw()
|
||||||
wasp.system.request_tick(1000)
|
wasp.system.request_tick(1000)
|
||||||
|
|
||||||
def tick(self, ticks):
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def background(self):
|
|
||||||
"""De-activate the application (without losing state)."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def sleep(self):
|
def sleep(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def wake(self):
|
def wake(self):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def tick(self, ticks):
|
||||||
|
self.update()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
"""Redraw the display from scratch."""
|
"""Redraw the display from scratch."""
|
||||||
draw = wasp.watch.drawable
|
draw = wasp.watch.drawable
|
||||||
|
|
|
@ -11,7 +11,6 @@ class FlashlightApp(object):
|
||||||
|
|
||||||
def foreground(self):
|
def foreground(self):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
|
||||||
self.draw()
|
self.draw()
|
||||||
wasp.system.request_tick(1000)
|
wasp.system.request_tick(1000)
|
||||||
|
|
||||||
|
@ -22,13 +21,9 @@ class FlashlightApp(object):
|
||||||
"""De-activate the application (without losing state)."""
|
"""De-activate the application (without losing state)."""
|
||||||
wasp.system.brightness = self._brightness
|
wasp.system.brightness = self._brightness
|
||||||
|
|
||||||
def sleep(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def tick(self, ticks):
|
def tick(self, ticks):
|
||||||
wasp.system.keep_awake()
|
wasp.system.keep_awake()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
"""Redraw the display from scratch."""
|
"""Redraw the display from scratch."""
|
||||||
display = wasp.watch.display
|
wasp.watch.display.fill(0xffff)
|
||||||
display.fill(0xffff)
|
|
||||||
|
|
|
@ -20,13 +20,6 @@ class TestApp():
|
||||||
wasp.EventMask.SWIPE_UPDOWN |
|
wasp.EventMask.SWIPE_UPDOWN |
|
||||||
wasp.EventMask.BUTTON)
|
wasp.EventMask.BUTTON)
|
||||||
|
|
||||||
def background(self):
|
|
||||||
"""De-activate the application (without losing state)."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def sleep(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def press(self, button, state):
|
def press(self, button, state):
|
||||||
draw = wasp.watch.drawable
|
draw = wasp.watch.drawable
|
||||||
if self.test == 'Touch':
|
if self.test == 'Touch':
|
||||||
|
|
|
@ -115,7 +115,8 @@ class Manager():
|
||||||
"""Switch to the requested application.
|
"""Switch to the requested application.
|
||||||
"""
|
"""
|
||||||
if self.app:
|
if self.app:
|
||||||
self.app.background()
|
if 'background' in dir(self.app):
|
||||||
|
self.app.background()
|
||||||
else:
|
else:
|
||||||
# System start up...
|
# System start up...
|
||||||
watch.display.poweron()
|
watch.display.poweron()
|
||||||
|
@ -186,7 +187,7 @@ class Manager():
|
||||||
"""Enter the deepest sleep state possible.
|
"""Enter the deepest sleep state possible.
|
||||||
"""
|
"""
|
||||||
watch.backlight.set(0)
|
watch.backlight.set(0)
|
||||||
if not self.app.sleep():
|
if 'sleep' not in dir(self.app) or not self.app.sleep():
|
||||||
self.switch(self.applications[0])
|
self.switch(self.applications[0])
|
||||||
self.app.sleep()
|
self.app.sleep()
|
||||||
watch.display.poweroff()
|
watch.display.poweroff()
|
||||||
|
|
Loading…
Add table
Reference in a new issue