-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.py
executable file
·75 lines (57 loc) · 1.77 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
import led_panel
from led_panel import panels, compile_image
from fontutil import base_font
from PIL import Image
import time
import signal
import sys
import threading
debug = False
def internet_time():
"Swatch Internet Time. Biel meridian."
h, m, s = time.gmtime()[3:6]
h += 1 # Biel time zone: UTC+1
seconds = s + (60.0*m) + (60.0*60.0*h)
beats = seconds * 1000.0 / (60.0*60.0*24.0)
beats = beats % 1000.0
return beats
def internet_time2():
"More granular Swatch time. Courtesy https://github.com/gcohen55/pebble-beapoch"
return (((time.time() + 3600) % 86400) * 1000) / 86400
def render_time_bitmap():
"Render local time + Swatch beats into a 2-panel bitmap"
beats = internet_time2()
msg = time.strftime("%H:%M:%S")
txtimg = base_font.strImg(msg)
img = Image.new("1",(120,7))
img.paste(txtimg,(15,0))
bmsg = "{0:03.2f}".format(beats)
txt2img = base_font.strImg(bmsg)
img.paste(txt2img,(62,0))
img.paste(base_font.strImg(".beats"),(93,0))
bitmap = compile_image(img,0,0)
return bitmap
class PanelThread(threading.Thread):
def __init__(self, panel):
pass
class ServiceThread:
pass
if __name__=="__main__":
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
debug = True
led_panel.init(debug)
panels[0].setRelay(True)
def sigint_handler(signal,frame):
print("Caught ctrl-C; shutting down.")
panels[0].setRelay(False)
led_panel.shutdown()
sys.exit(0)
signal.signal(signal.SIGINT,sigint_handler)
while True:
bitmap = render_time_bitmap()
for j in range(3):
panels[j].setCompiledImage(bitmap)
time.sleep(0.10)
panels[0].setRelay(False)
led_panel.shutdown()