diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-05 08:43:26 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-06 21:04:20 (GMT) |
| commit | 83cc56969e13d1e0e3ea4b2a6b8c9c6875110688 (patch) | |
| tree | c2b6558cc7f55368d2d4e57efd2357937c3b6c4c | |
| parent | 6a6e393d1fc389102733fe182ea41b803bd05755 (diff) | |
wasp: manager: make sleep() and background() callbacks optional
Making callbacks optional reduces pointless boilerplate in applications.
| -rw-r--r-- | wasp/apps/clock.py | 10 | ||||
| -rw-r--r-- | wasp/apps/flashlight.py | 7 | ||||
| -rw-r--r-- | wasp/apps/testapp.py | 7 | ||||
| -rw-r--r-- | wasp/wasp.py | 5 |
4 files changed, 7 insertions, 22 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py index c9099be..4feba63 100644 --- a/wasp/apps/clock.py +++ b/wasp/apps/clock.py @@ -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 diff --git a/wasp/apps/flashlight.py b/wasp/apps/flashlight.py index c6c4726..13e3443 100644 --- a/wasp/apps/flashlight.py +++ b/wasp/apps/flashlight.py @@ -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) diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py index 849ed5f..e7016d7 100644 --- a/wasp/apps/testapp.py +++ b/wasp/apps/testapp.py @@ -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': diff --git a/wasp/wasp.py b/wasp/wasp.py index a49948b..a18c466 100644 --- a/wasp/wasp.py +++ b/wasp/wasp.py @@ -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() |
