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()
|
||||
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):
|
||||
return True
|
||||
|
||||
def wake(self):
|
||||
self.update()
|
||||
|
||||
def tick(self, ticks):
|
||||
self.update()
|
||||
|
||||
def draw(self):
|
||||
"""Redraw the display from scratch."""
|
||||
draw = wasp.watch.drawable
|
||||
|
|
|
@ -11,7 +11,6 @@ class FlashlightApp(object):
|
|||
|
||||
def foreground(self):
|
||||
"""Activate the application."""
|
||||
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
|
||||
self.draw()
|
||||
wasp.system.request_tick(1000)
|
||||
|
||||
|
@ -22,13 +21,9 @@ class FlashlightApp(object):
|
|||
"""De-activate the application (without losing state)."""
|
||||
wasp.system.brightness = self._brightness
|
||||
|
||||
def sleep(self):
|
||||
return False
|
||||
|
||||
def tick(self, ticks):
|
||||
wasp.system.keep_awake()
|
||||
|
||||
def draw(self):
|
||||
"""Redraw the display from scratch."""
|
||||
display = wasp.watch.display
|
||||
display.fill(0xffff)
|
||||
wasp.watch.display.fill(0xffff)
|
||||
|
|
|
@ -20,13 +20,6 @@ class TestApp():
|
|||
wasp.EventMask.SWIPE_UPDOWN |
|
||||
wasp.EventMask.BUTTON)
|
||||
|
||||
def background(self):
|
||||
"""De-activate the application (without losing state)."""
|
||||
pass
|
||||
|
||||
def sleep(self):
|
||||
return False
|
||||
|
||||
def press(self, button, state):
|
||||
draw = wasp.watch.drawable
|
||||
if self.test == 'Touch':
|
||||
|
|
|
@ -115,7 +115,8 @@ class Manager():
|
|||
"""Switch to the requested application.
|
||||
"""
|
||||
if self.app:
|
||||
self.app.background()
|
||||
if 'background' in dir(self.app):
|
||||
self.app.background()
|
||||
else:
|
||||
# System start up...
|
||||
watch.display.poweron()
|
||||
|
@ -186,7 +187,7 @@ class Manager():
|
|||
"""Enter the deepest sleep state possible.
|
||||
"""
|
||||
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.app.sleep()
|
||||
watch.display.poweroff()
|
||||
|
|
Loading…
Add table
Reference in a new issue