1
0
Fork 0

wasp: clock: Add some docstrings

This commit is contained in:
Daniel Thompson 2020-02-23 20:51:58 +00:00
parent 5c0d86d938
commit c3d4ddafbc

View file

@ -19,12 +19,17 @@ DIGITS = (
MONTH = 'JanFebMarAprMayJunJulAugSepOctNovDec' MONTH = 'JanFebMarAprMayJunJulAugSepOctNovDec'
class ClockApp(object): class ClockApp(object):
"""Simple digital clock application.
Shows a time (as HH:MM) together with a battery meter and the date.
"""
def __init__(self): def __init__(self):
self.on_screen = ( -1, -1, -1, -1, -1, -1 ) self.on_screen = ( -1, -1, -1, -1, -1, -1 )
self.meter = widgets.BatteryMeter() self.meter = widgets.BatteryMeter()
def draw(self, watch): def draw(self, watch):
"""Redraw the display from scratch."""
display = watch.display display = watch.display
display.fill(0) display.fill(0)
@ -34,6 +39,11 @@ class ClockApp(object):
self.meter.draw() self.meter.draw()
def update(self, watch): def update(self, watch):
"""Update the display (if needed).
The updates are a lazy as possible and rely on an prior call to
draw() to ensure the screen is suitably prepared.
"""
now = watch.rtc.get_localtime() now = watch.rtc.get_localtime()
if now[3] == self.on_screen[3] and now[4] == self.on_screen[4]: if now[3] == self.on_screen[3] and now[4] == self.on_screen[4]:
if now[5] != self.on_screen[5]: if now[5] != self.on_screen[5]:
@ -51,7 +61,7 @@ class ClockApp(object):
draw = Draw565(display) draw = Draw565(display)
month = now[1] - 1 month = now[1] - 1
month = MONTH[month*3:(month+1)*3] month = MONTH[month*3:(month+1)*3]
draw.string('{}-{}-{}'.format(now[2], month, now[0]), draw.string('{} {} {}'.format(now[2], month, now[0]),
0, 180, width=240) 0, 180, width=240)
self.meter.update() self.meter.update()