forked from tanzilli/ledpanel-utils
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sliding_clock.py
executable file
·61 lines (47 loc) · 1.31 KB
/
sliding_clock.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
#!/usr/bin/python
# Sliding digital clock on RGB led panel
# multiple module capability added by A.Montefusco 2017,
# requires ledpanel.ko 2.0
import time
import sys
import os
from datetime import datetime
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import StringIO
import probe
if len(sys.argv)<2 or len(sys.argv)>4:
print "Syntax:"
print " %s r g b" % (sys.argv[0])
quit()
print "Panel size: %d x %d\n" % (probe.panel_w, probe.panel_h)
font = ImageFont.truetype('fonts/Ubuntu-B.ttf', probe.panel_h)
r=int(sys.argv[1])
g=int(sys.argv[2])
b=int(sys.argv[3])
im = Image.new("RGB", (probe.panel_w, probe.panel_h), "black")
draw = ImageDraw.Draw(im)
draw.fontmode="1" #No antialias
width, height = font.getsize("88:88:88")
def format_time():
d = datetime.now()
return "{:%H:%M:%S}".format(d)
message = format_time()
x = probe.panel_w
out_file = open("/sys/class/ledpanel/rgb_buffer","w")
output = StringIO.StringIO()
while True:
x = x - 1
if x < -(width):
x = probe.panel_w
message = format_time()
continue
draw.rectangle((0, 0, probe.panel_w - 1, height), outline=0, fill=0)
draw.text((x, -1), message, (r<<5,g<<5,b<<5), font=font)
output.truncate(0)
im.save(output, format='PPM')
buf=output.getvalue()
out_file.seek(0)
out_file.write(buf[13:])
out_file.close()