2020-03-22 16:40:18 +01:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
# Copyright (C) 2020 Daniel Thompson
|
|
|
|
|
2020-05-14 23:29:35 +02:00
|
|
|
"""Flashlight
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
2022-04-11 15:23:26 +02:00
|
|
|
Shows a bright screen that you can tap to change brightness or switch to redlight.
|
2021-01-13 22:51:17 +01:00
|
|
|
|
2023-03-07 02:02:07 +01:00
|
|
|
.. figure:: res/screenshots/FlashlightApp.png
|
2021-01-13 22:51:17 +01:00
|
|
|
:width: 179
|
2020-05-14 23:29:35 +02:00
|
|
|
"""
|
|
|
|
|
2020-03-22 13:37:19 +01:00
|
|
|
import wasp
|
2020-04-06 23:03:05 +02:00
|
|
|
import icons
|
|
|
|
|
2022-04-12 09:53:23 +02:00
|
|
|
|
2023-03-07 02:02:07 +01:00
|
|
|
class FlashlightApp(object):
|
2021-01-13 22:51:17 +01:00
|
|
|
"""Trivial flashlight application."""
|
2020-04-06 23:03:05 +02:00
|
|
|
NAME = 'Torch'
|
|
|
|
ICON = icons.torch
|
2020-03-08 11:18:08 +01:00
|
|
|
|
2020-03-28 18:19:34 +01:00
|
|
|
def foreground(self):
|
2020-03-08 11:18:08 +01:00
|
|
|
"""Activate the application."""
|
2022-04-12 09:53:23 +02:00
|
|
|
wasp.system.request_tick(3000)
|
2022-04-11 15:23:26 +02:00
|
|
|
wasp.system.request_event(wasp.EventMask.TOUCH)
|
2020-03-08 11:18:08 +01:00
|
|
|
|
2020-03-26 23:12:05 +01:00
|
|
|
self._brightness = wasp.system.brightness
|
|
|
|
wasp.system.brightness = 3
|
2022-04-12 09:53:23 +02:00
|
|
|
self._ntouch = 1
|
|
|
|
wasp.watch.drawable.fill(0xffff) # white
|
2020-03-26 23:12:05 +01:00
|
|
|
|
2020-03-08 11:18:08 +01:00
|
|
|
def background(self):
|
2022-04-11 15:23:26 +02:00
|
|
|
"""De-activate the application (without losing original state)."""
|
2020-03-26 23:12:05 +01:00
|
|
|
wasp.system.brightness = self._brightness
|
2020-03-08 11:18:08 +01:00
|
|
|
|
|
|
|
def tick(self, ticks):
|
2020-03-26 23:12:05 +01:00
|
|
|
wasp.system.keep_awake()
|
2020-03-08 11:18:08 +01:00
|
|
|
|
2022-04-11 15:23:26 +02:00
|
|
|
def touch(self, event):
|
2022-04-12 09:53:23 +02:00
|
|
|
self._ntouch += 1
|
|
|
|
self._ntouch %= 6
|
|
|
|
wasp.system.brightness = (-self._ntouch) % 3 + 1
|
|
|
|
if (-self._ntouch + 1) % 3 == 0:
|
|
|
|
if -self._ntouch % 6 < 3:
|
|
|
|
wasp.watch.drawable.fill(0xf800) # red
|
|
|
|
else:
|
|
|
|
wasp.watch.drawable.fill(0xffff) # white
|