Commit cd4b18b7 authored by Michael Murtaugh's avatar Michael Murtaugh

changes on pi

parent aea5e8a1
[Unit]
Description=Collective Conditions
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/pi/etherlamp/python
ExecStart=/home/pi/etherlamp/python/run.sh
Restart=always
[Install]
WantedBy=multi-user.target
\ No newline at end of file
......@@ -10,6 +10,12 @@ from etherpad import changeset_parse, perform_changeset_curline
# from BdfFontFile import BdfFontFile
def listlooper (ll):
while True:
for l in ll:
yield(l)
class ImageScroller(SampleBase):
def __init__(self, *args, **kwargs):
super(ImageScroller, self).__init__(*args, **kwargs)
......@@ -17,47 +23,78 @@ class ImageScroller(SampleBase):
self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!")
self.parser.add_argument("--pad", type=argparse.FileType("r"), default="../constantcodeofconduct2.etherpad.json")
self.parser.add_argument("--padname", default="constantcodeofconduct2")
self.parser.add_argument("--font", default="fonts/9x18.bdf")
self.parser.add_argument("--font", default="fonts/6x13.pil")
self.parser.add_argument("--sleep", type=float, default=0.1)
def run(self):
# if not 'image' in self.__dict__:
# self.image = Image.open(self.args.image).convert('RGB')
# self.image.resize((self.matrix.width, self.matrix.height), Image.ANTIALIAS)
padname = self.args.padname
sleeptime = self.args.sleep
data = json.load(self.args.pad)
pad_data = data["pad:{0}".format(padname)]
last_rev = pad_data['head']
text = "\n"
cursorcolors = [(255, 255, 0), (255, 0, 0), (255, 0, 255), (0, 255, 0), (0, 255, 255), (0, 0, 255)]
cursoriter = listlooper(cursorcolors)
cursorcolor = cursoriter.next()
self.image = Image.new("RGB", (self.matrix.width * 2, self.matrix.height), (0,0,0))
draw = ImageDraw.ImageDraw(self.image)
# font = ImageFont.load(self.args.font)
font = ImageFont.load(self.args.font)
double_buffer = self.matrix.CreateFrameCanvas()
img_width, img_height = self.image.size
for r in range(0, last_rev+1):
d = data["pad:{0}:revs:{1}".format(padname, r)]
cs = changeset_parse(d['changeset'])
text, linepos, charpos = perform_changeset_curline(text, cs)
lines = text.splitlines()
if charpos == 0 and linepos > 0:
line = lines[linepos-1]
charpos = len(line)
else:
line = lines[linepos]
while True:
text = "\n"
curline = None
for r in range(0, last_rev+1):
d = data["pad:{0}:revs:{1}".format(padname, r)]
cs = changeset_parse(d['changeset'])
text, linepos, charpos, inserts = perform_changeset_curline(text, cs)
# change cursor color when linepos changes
if curline != None and linepos != curline:
cursorcolor = cursoriter.next()
curline = linepos
pre, post = line[:charpos], line[charpos:]
pre = pre[-10:]
post = post[:5]
# sys.stdout.write("\r{0}|{1}{2}".format(pre, post, " "*64))
# sys.stdout.flush()
msg = "{0}|{1}".format(pre, post)
draw.rectangle((0, 0, img_width, img_height), fill=(0,0,0))
draw.text((0, 10), msg)
lines = text.splitlines()
if charpos == 0 and linepos > 0:
line = lines[linepos-1]
charpos = len(line)
else:
line = lines[linepos]
pre, post = line[:charpos], line[charpos:]
pre = pre[-10:]
post = post[:5]
# sys.stdout.write("\r{0}|{1}{2}".format(pre, post, " "*64))
# sys.stdout.flush()
draw.rectangle((0, 0, img_width, img_height), fill=(0,0,0))
if inserts:
pre, insert = pre[:-inserts], pre[-inserts:]
x = 0
draw.text((x, 10), pre, font=font)
tw, th = font.getsize(pre)
x += tw
tw, th = font.getsize(insert)
draw.rectangle((x, 10, x+tw, 10+th), fill=cursorcolor)
draw.text((x, 10), insert, font=font, fill=(0,0,0))
x += tw
draw.text((x, 10), post, font=font)
else:
# msg = "{0}|{1}".format(pre, post)
msg = "{0}{1}".format(pre, post)
draw.text((0, 10), msg, font=font)
double_buffer.SetImage(self.image, 0)
double_buffer = self.matrix.SwapOnVSync(double_buffer)
time.sleep(sleeptime)
draw.rectangle((0, 0, img_width, img_height), fill=(0,0,0))
double_buffer.SetImage(self.image, 0)
double_buffer = self.matrix.SwapOnVSync(double_buffer)
time.sleep(0.1)
time.sleep(5.0)
# Main function
......
#!/bin/bash
python ethertest.py --font fonts/6x13B.pil --sleep 0.25
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment