1
0
Fork 0

apps: chrono: Implement a simple analogue watch face

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-12-27 09:13:49 +00:00
parent 0ae31a53b3
commit 726d5c8554
5 changed files with 118 additions and 0 deletions

View file

@ -165,6 +165,10 @@ wasp-os also contains a library of additional applications for you to choose.
These are disabled by default but can be easily enabled by adding them These are disabled by default but can be easily enabled by adding them
using one of the techniques is the Application Writer's guide. using one of the techniques is the Application Writer's guide.
.. image:: res/ChronoApp.png
:alt: Analogue clock application running in the wasp-os simulator
:width: 179
.. image:: res/FiboApp.png .. image:: res/FiboApp.png
:alt: Fibonacci clock application running in the wasp-os simulator :alt: Fibonacci clock application running in the wasp-os simulator
:width: 179 :width: 179

View file

@ -39,6 +39,7 @@ Wasp-os
* [ ] Introduce fwd/back/vol+/vol- buttons to the music player * [ ] Introduce fwd/back/vol+/vol- buttons to the music player
* [ ] Update icon for Alarm app * [ ] Update icon for Alarm app
* [ ] Update art work for buttons in Confirmation view * [ ] Update art work for buttons in Confirmation view
* [ ] Reduce the size of the battery charge icon slightly (match bell)
* [ ] Applications * [ ] Applications

View file

@ -23,6 +23,17 @@ treated as examples they are described in detail as part of the
Watch faces Watch faces
----------- -----------
.. automodule:: apps.chrono
This application is very simple and largely serves as an example of how to
implement traditional watch faces.
It is not included by default in any image.
Instead it can be transferred to the device dynamically using wasptool:
.. code-block:: sh
./tools/wasptool --exec wasp/apps/chrono.py --eval 'wasp.system.register(ChronoApp())'
.. automodule:: apps.fibonacci_clock .. automodule:: apps.fibonacci_clock
This app is enabled by default in the simulator. This app is enabled by default in the simulator.

BIN
res/ChronoApp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

102
wasp/apps/chrono.py Normal file
View file

@ -0,0 +1,102 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson
"""Analogue clock
~~~~~~~~~~~~~~~~~
Shows the time as a traditional watch face together with a battery meter.
.. figure:: res/ChronoApp.png
:width: 179
Screenshot of the analogue clock application
"""
import wasp
class ChronoApp():
"""Simple analogue clock application.
"""
NAME = 'Chrono'
def foreground(self):
"""Activate the application.
Configure the status bar, redraw the display and request a periodic
tick callback every second.
"""
wasp.system.bar.clock = False
self._draw(True)
wasp.system.request_tick(1000)
def sleep(self):
"""Prepare to enter the low power mode.
:returns: True, which tells the system manager not to automatically
switch to the default application before sleeping.
"""
return True
def wake(self):
"""Return from low power mode.
Time will have changes whilst we have been asleep so we must
udpate the display (but there is no need for a full redraw because
the display RAM is preserved during a sleep.
"""
self._draw()
def tick(self, ticks):
"""Periodic callback to update the display."""
self._draw()
def _draw(self, redraw=False):
"""Draw or lazily update the display.
The updates are as lazy by default and avoid spending time redrawing
if the time on display has not changed. However if redraw is set to
True then a full redraw is be performed.
"""
draw = wasp.watch.drawable
hi = wasp.system.theme('accent-hi')
mid = wasp.system.theme('accent-mid')
lo = wasp.system.theme('accent-lo')
if redraw:
now = wasp.watch.rtc.get_localtime()
# Clear the display and draw that static parts of the watch face
draw.fill()
# Redraw the status bar
wasp.system.bar.draw()
# Draw the dividers
draw.set_color(mid)
for theta in range(12):
draw.polar(120, 120, theta * 360 // 12, 111, 119, 2)
self._hh = 0
self._mm = 0
else:
now = wasp.system.bar.update()
if not now or self._mm == now[4]:
# Skip the update
return
# Undraw old time
hh = (30 * (self._hh % 12)) + (self._mm / 2)
mm = 6 * self._mm
draw.polar(120, 120, hh, 5, 80, 5, 0)
draw.polar(120, 120, mm, 5, 110, 3, 0)
# Record the minute that is currently being displayed
self._hh = now[3]
self._mm = now[4]
# Draw the new time
hh = (30 * (self._hh % 12)) + (self._mm / 2)
mm = 6 * self._mm
draw.polar(120, 120, hh, 5, 80, 5, hi)
draw.polar(120, 120, hh, 5, 60, 3, lo)
draw.polar(120, 120, mm, 5, 110, 3, hi)