summaryrefslogtreecommitdiff
path: root/wasp/apps/fibonacci_clock.py
diff options
context:
space:
mode:
Diffstat (limited to 'wasp/apps/fibonacci_clock.py')
-rw-r--r--wasp/apps/fibonacci_clock.py78
1 files changed, 35 insertions, 43 deletions
diff --git a/wasp/apps/fibonacci_clock.py b/wasp/apps/fibonacci_clock.py
index de59bc3..3f0ca95 100644
--- a/wasp/apps/fibonacci_clock.py
+++ b/wasp/apps/fibonacci_clock.py
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
# Copyright (C) 2020 Johannes Wache
+
"""Fibonacci clock
+~~~~~~~~~~~~~~~~~~
The Fibonacci sequence is a sequence of numbers created by the Italian
mathematician Fibonacci in the 13th century. This is a sequence starting with
@@ -22,6 +24,8 @@ result by 5 to get the actual number.
import wasp
import icons
+COLORS = [0xffff,0xf800,0x07e0,0x001f] # White, red, green and blue
+FIELDS = b'\x05\x03\x02\x01\x01'
MONTH = 'JanFebMarAprMayJunJulAugSepOctNovDec'
# 2-bit RLE, generated from res/fibo_icon.png, 246 bytes
@@ -48,54 +52,45 @@ icon = (
class FibonacciClockApp():
"""Displays the time as a Fibonacci Clock
+
+ .. figure:: res/FiboApp.png
+ :width: 179
+
+ Screenshot of the fibonacci clock application
"""
NAME = 'Fibo'
ICON = icon
def __init__(self):
- self.meter = wasp.widgets.BatteryMeter()
- self.notifier = wasp.widgets.NotificationBar()
- self.fields = b'\x05\x03\x02\x01\x01'
- self.color_codes = [0xffff,0xf800,0x07e0,0x001f] # White, red, green and blue
+ self._bar = wasp.widgets.StatusBar()
def foreground(self):
"""Activate the application."""
- self.on_screen = ( -1, -1, -1, -1, -1, -1 )
- self.draw()
+ self._bar.clock = False
+ self._draw(True)
wasp.system.request_tick(1000)
def sleep(self):
return True
def wake(self):
- self.update()
+ self._draw()
def tick(self, ticks):
- self.update()
+ self._draw()
- def draw(self):
- """Redraw the display from scratch."""
+ def _draw(self, redraw=False):
+ """Draw or lazily update the display."""
draw = wasp.watch.drawable
- draw.fill()
- self.on_screen = ( -1, -1, -1, -1, -1, -1 )
- self.update()
- self.meter.draw()
-
- def update(self):
- """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 = wasp.watch.rtc.get_localtime()
- if now[3] == self.on_screen[3] and now[4] == self.on_screen[4]:
- if now[5] != self.on_screen[5]:
- self.meter.update()
- self.notifier.update()
- self.on_screen = now
- return False
- draw = wasp.watch.drawable
+ if redraw:
+ now = wasp.watch.rtc.get_localtime()
+ draw.fill()
+ self._bar.draw()
+ else:
+ now = self._bar.update()
+ if not now or self._min == now[4]:
+ return
#calculate colors of fields:
field_colors = bytearray(5)
@@ -104,27 +99,24 @@ class FibonacciClockApp():
if (hr >= 12):
hr -= 12
for i in range(5):
- if ((hr - self.fields[i]) >= 0):
- hr -= self.fields[i]
+ if ((hr - FIELDS[i]) >= 0):
+ hr -= FIELDS[i]
field_colors[i] += 1
- if ((mn - self.fields[i]) >= 0):
- mn -= self.fields[i]
+ if ((mn - FIELDS[i]) >= 0):
+ mn -= FIELDS[i]
field_colors[i] += 2
- draw.fill(x=71,y=60,w=23,h=23,bg=self.color_codes[field_colors[4]]) # 1 field
- draw.fill(x=71,y=85,w=23,h=23,bg=self.color_codes[field_colors[3]]) # 1 field
- draw.fill(x=21,y=60,w=48,h=48,bg=self.color_codes[field_colors[2]]) # 2 field
- draw.fill(x=21,y=110,w=73,h=73,bg=self.color_codes[field_colors[1]]) # 3 field
- draw.fill(x=96,y=60,w=123,h=123,bg=self.color_codes[field_colors[0]]) # 5 field
-
- self.on_screen = now
+ draw.fill(x=71,y=60,w=23,h=23,bg=COLORS[field_colors[4]]) # 1 field
+ draw.fill(x=71,y=85,w=23,h=23,bg=COLORS[field_colors[3]]) # 1 field
+ draw.fill(x=21,y=60,w=48,h=48,bg=COLORS[field_colors[2]]) # 2 field
+ draw.fill(x=21,y=110,w=73,h=73,bg=COLORS[field_colors[1]]) # 3 field
+ draw.fill(x=96,y=60,w=123,h=123,bg=COLORS[field_colors[0]]) # 5 field
month = now[1] - 1
month = MONTH[month*3:(month+1)*3]
draw.string('{} {} {}'.format(now[2], month, now[0]),
0, 202, width=240)
- self.meter.update()
- self.notifier.update()
- return True
+ # Record the minute that is currently being displayed
+ self._min = now[4]