apps: SportsApp: Initial sports app implementation

This app is functional... although it lacking in almost every
costmetic way, from the icon to the main screen.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2021-06-20 17:24:10 +01:00
parent ae0d59dbe3
commit b0bab534ff
6 changed files with 99 additions and 0 deletions

View file

@ -153,6 +153,10 @@ simulator:
:alt: Heart rate application running on the wasp-os simulator :alt: Heart rate application running on the wasp-os simulator
:width: 179 :width: 179
.. image:: res/SportsApp.png
:alt: Sports applications, a combined stopwatch and step counter
:width: 179
.. image:: res/StopclockApp.png .. image:: res/StopclockApp.png
:alt: Stop watch application running on the wasp-os simulator :alt: Stop watch application running on the wasp-os simulator
:width: 179 :width: 179

View file

@ -53,6 +53,8 @@ Applications
.. automodule:: apps.musicplayer .. automodule:: apps.musicplayer
.. automodule:: apps.sports
.. automodule:: apps.testapp .. automodule:: apps.testapp
.. automodule:: apps.timer .. automodule:: apps.timer

BIN
res/SportsApp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

View file

@ -44,6 +44,7 @@ class SoftwareApp():
db.append(('musicplayer', factory('Music Player'))) db.append(('musicplayer', factory('Music Player')))
db.append(('play2048', factory('Play 2048'))) db.append(('play2048', factory('Play 2048')))
db.append(('snake', factory('Snake Game'))) db.append(('snake', factory('Snake Game')))
db.append(('sports', factory('Sports')))
db.append(('flashlight', factory('Torch'))) db.append(('flashlight', factory('Torch')))
db.append(('testapp', factory('Test'))) db.append(('testapp', factory('Test')))
db.append(('timer', factory('Timer'))) db.append(('timer', factory('Timer')))

91
wasp/apps/sports.py Normal file
View file

@ -0,0 +1,91 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Daniel Thompson
"""Sports timer
~~~~~~~~~~~~~~~
A combined stopwatch and step counter.
.. figure:: res/SportsApp.png
:width: 179
"""
import wasp
import icons
import fonts
class SportsApp():
"""Sports timer application."""
NAME = 'Sports'
ICON = icons.app
def __init__(self):
self._timer = wasp.widgets.Stopwatch(120-36)
self._reset()
def foreground(self):
"""Activate the application."""
wasp.system.bar.clock = True
self._draw()
wasp.system.request_tick(97)
wasp.system.request_event(wasp.EventMask.TOUCH | wasp.EventMask.BUTTON)
def background(self):
if not self._timer.started:
self._timer.reset()
def sleep(self):
return True
def wake(self):
self._update()
def press(self, button, state):
if not state:
return
steps = wasp.watch.accel.steps
if self._timer.started:
self._timer.stop()
else:
self._timer.start()
self._last_steps = steps
def touch(self, event):
if not self._timer.started:
self._reset()
self._update()
def tick(self, ticks):
self._update()
def _reset(self):
self._timer.reset()
self._steps = 0
self._last_steps = 0
def _draw(self):
"""Draw the display from scratch."""
draw = wasp.watch.drawable
draw.fill()
wasp.system.bar.draw()
self._timer.draw()
def _update(self):
wasp.system.bar.update()
self._timer.update()
if self._timer.started:
steps = wasp.watch.accel.steps
redraw = bool(steps - self._last_steps)
self._steps += steps - self._last_steps
self._last_steps = steps
else:
redraw = True
if redraw:
draw = wasp.watch.drawable
draw.set_font(fonts.sans36)
draw.set_color(draw.lighten(wasp.system.theme('spot1'), wasp.system.theme('contrast')))
draw.string(str(self._steps), 0, 170, 228, True)

View file

@ -20,6 +20,7 @@ manifest = (
'apps/play2048.py', 'apps/play2048.py',
'apps/settings.py', 'apps/settings.py',
'apps/software.py', 'apps/software.py',
'apps/sports.py',
'apps/steps.py', 'apps/steps.py',
'apps/stopwatch.py', 'apps/stopwatch.py',
'apps/snake.py', 'apps/snake.py',