wordclock: various tidy ups

Handle more errors so the clock doesn't stop.

Reset if any other exception occurs.

Handle an empty response from iptime.

Blink less often.

Dim the clock outside hours.
master
Michael Hope 2 years ago
parent a08ad836c2
commit af5e3d44b8

@ -15,6 +15,9 @@ def _fetch():
except OSError as ex:
print(ex)
return None
except ValueError as ex:
print(ex)
return None
def _jitter(mid: int) -> int:

@ -1,5 +1,7 @@
import time
import microcontroller
import wordclock
@ -9,4 +11,7 @@ def main():
if __name__ == '__main__':
main()
try:
main()
finally:
microcontroller.reset()

@ -162,6 +162,14 @@ def intensity(num: int, den: int) -> int:
return CIEL8[idx]
def brightness(secs):
hour = int(secs) // 60 // 60
if hour >= 7 and hour < 22:
return 255
return 1200
def run() -> generator:
words = None
fade = 2000
@ -176,16 +184,16 @@ def run() -> generator:
src = Frame()
while True:
yield src
yield None
s, m2 = next(secs)
nxt = split(s)
if nxt == words:
yield from asynced.delay(1)
yield from asynced.delay(2)
continue
dest = render(prefix() + nxt)
for at in asynced.wait(fade):
yield merge(src, dest, intensity(fade - at, fade),
intensity(at, fade), 255)
intensity(at, fade), brightness(s))
words = nxt
src = dest
@ -194,9 +202,9 @@ def blink() -> generator:
led = machine.Pin(16, machine.Pin.OUT)
while True:
led.off()
yield from asynced.delay(0.1)
yield from asynced.delay(0.03)
led.on()
yield from asynced.delay(0.8)
yield from asynced.delay(2.9)
def bench() -> generator:
@ -206,8 +214,8 @@ def bench() -> generator:
start = time.monotonic()
yield from range(i)
elapsed = time.monotonic() - start
print('%d in %.3f %.3f/1 %.1f FPS' % (i, elapsed, elapsed / i,
i / elapsed))
print('%d in %.3f %.3f/1 %.1f FPS' %
(i, elapsed, elapsed / i, i / elapsed))
def main():

Loading…
Cancel
Save