diff options
| -rw-r--r-- | wasp/apps/analog24.py | 117 | ||||
| -rw-r--r-- | wasp/apps/faces.py | 1 | ||||
| -rw-r--r-- | wasp/boards/simulator/main.py | 6 |
3 files changed, 123 insertions, 1 deletions
diff --git a/wasp/apps/analog24.py b/wasp/apps/analog24.py new file mode 100644 index 0000000..7768414 --- /dev/null +++ b/wasp/apps/analog24.py @@ -0,0 +1,117 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (C) 2020 Daniel Thompson +# Copyright (C) 2022 Michele Bini + +"""Analogue 24 clock +~~~~~~~~~~~~~~~~~ + +Shows the time as a single-hand 24h analog watch face together with a battery meter. +""" + +import wasp + +class Analog24App(): + """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(20000) + + 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 preview(self): + """Provide a preview for the watch face selection.""" + wasp.system.bar.clock = False + self._draw(True) + + def drawmark(self, draw, theta, color): + # Cool effect: l = 5 * ((theta&3)*4+1) + l = 5 * (1 if theta&3 else (4 if theta%3 else 12)) + draw.polar(120, 120, theta * 360 // 96, 120-l, 120, 1, color) + + 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 = 0x7e0 # wasp.system.theme('bright') + c1 = draw.darken(wasp.system.theme('spot1'), wasp.system.theme('contrast')) + + 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(wasp.system.theme('mid')) + for theta in range(96): + self.drawmark(draw, theta, 0xffff) + self._hh = 99 + self._mm = 0 + for theta in range(4): + draw.polar(120,120,theta*45,5,-5,4,hi) + else: + now = wasp.system.bar.update() + + if self._hh < 99: + self.drawmark(draw, 86, 0xffff) # It seems that the status icons often overdraw this mark... + # Undraw old time + hh = (15 * (self._hh % 24)) + (self._mm / 4) + draw.polar(120, 120, hh, -15, 120, 2, 0) + # # Redraw nearby marks + # rr = (int(hh) * 96 // 360) + # self.drawmark(draw, rr, 0xffff) + # self.drawmark(draw, (rr+1)%96, 0xffff) + # Redraw nearest mark + rr = ((int(hh) + 3) * 96 // 360) + self.drawmark(draw, rr, 0xffff) + # self.drawmark(draw, (rr+1)%96, 0xffff) + + if now is None: + # Added this because of a random crash at 'now[3]' in the simulator after 'waking up' the watch + return + + # Record the minute that is currently being displayed + self._hh = now[3] + self._mm = now[4] + + # Draw the new time + hh = (15 * (self._hh % 24)) + (self._mm / 4) + draw.polar(120, 120, hh, -15, 120, 2, hi) + # draw.polar(120, 120, hh, 5, 60, 3, draw.darken(c1, 2)) + draw.polar(120,120,hh,5,-5,4,hi) + diff --git a/wasp/apps/faces.py b/wasp/apps/faces.py index 1079417..c45a9cd 100644 --- a/wasp/apps/faces.py +++ b/wasp/apps/faces.py @@ -26,6 +26,7 @@ class FacesApp(): choices.append(('clock', 'Clock')) choices.append(('week_clock', 'WeekClock')) choices.append(('chrono', 'Chrono')) + choices.append(('analog24', 'Analog24')) choices.append(('dual_clock', 'DualClock')) choices.append(('fibonacci_clock', 'FibonacciClock')) choices.append(('word_clock', 'WordClock')) diff --git a/wasp/boards/simulator/main.py b/wasp/boards/simulator/main.py index e63d469..f06ea30 100644 --- a/wasp/boards/simulator/main.py +++ b/wasp/boards/simulator/main.py @@ -26,9 +26,13 @@ wasp.system.set_weather_info({ # with backlight activations. wasp.system.blank_after = 300 +# from apps.chrono import ChronoApp + # Replace the default (digital) clock with an alternative # (digital) clock with this alternative. -#wasp.system.register('apps.chrono.ChronoApp', watch_face=True) +wasp.system.register('apps.analog24.Analog24App', True) +# wasp.system.register('apps.chrono.ChronoApp', True) +# wasp.system.register('apps.clock.ClockApp', True) # Enable the demostration application #wasp.system.register('apps.demo.DemoApp') |
