add animations for textFull and image

This commit is contained in:
interfisch 2019-06-30 14:48:00 +02:00
parent 1251a0ad90
commit ffc8eac909
2 changed files with 94 additions and 51 deletions

View File

@ -134,6 +134,17 @@ class FlipdotSender(object):
self._sock.sendto(bytes(packet), (self._udphost, self._udpport))
def send_binimage(self, data,fadespeed=0): #works like send_bytes, but enables fadeanimation
image = Image.new("RGBA", self._img_size, FlipdotSender.C_BLACK)
draw = ImageDraw.Draw(image)
draw.fontmode = "1"
for i,d in enumerate(data):
if d=="1":
draw.point((i%self._img_size[0],int(i/self._img_size[0])), fill=FlipdotSender.C_WHITE)
self._send(image,fadespeed)
def send_text(self, text,fadespeed=0):
image = Image.new("RGBA", self._img_size, FlipdotSender.C_BLACK)

View File

@ -72,21 +72,55 @@ def on_message(client, userdata, msg):
flipthread.start()
if msg.topic == "raum2/flipdot/textFull/set": #scale/break text automatically
mode="inuse"
updateTimeout()
if mode!="inuse" and msg.topic == "raum2/flipdot/textFull/set": #scale/break text automatically
#mode="inuse"
#updateTimeout()
payload = msg.payload.decode("utf-8")
if flipthread is not None and flipthread.isAlive():
flipdot.stopAnimation()
while flipthread.isAlive():
flipdot.stopAnimation() #try to stop animation
time.sleep(0.1)
flipthread.join()
if len(payload)>0 and payload[0]=='~':
payload=payload[1:]
flipdot.send_textFull(payload,50)
flipdot.send_textFull(payload)
#flipdot.send_textFull(payload,50)
flipthread=Thread(target=flipdot.send_textFull, args=(payload,64))
else:
#flipdot.send_textFull(payload)
flipthread=Thread(target=flipdot.send_textFull, args=(payload,))
flipthread.start()
if msg.topic == "raum2/flipdot/image/set":
'''
mode="inuse"
updateTimeout()
payload = msg.payload.decode("utf-8")
print(payload)
flipdot.send_bytes(payload)
'''
payload = msg.payload.decode("utf-8")
if flipthread is not None and flipthread.isAlive():
flipdot.stopAnimation()
while flipthread.isAlive():
flipdot.stopAnimation() #try to stop animation
time.sleep(0.1)
flipthread.join()
if len(payload)>0 and payload[0]=='~':
payload=payload[1:]
#flipdot.send_textFull(payload,50)
flipthread=Thread(target=flipdot.send_binimage, args=(payload,64))
else:
#flipdot.send_textFull(payload)
flipthread=Thread(target=flipdot.send_binimage, args=(payload,))
flipthread.start()
@ -150,5 +184,3 @@ while True:
timeout=0
time.sleep(2)