add animations for textFull and image
This commit is contained in:
parent
1251a0ad90
commit
ffc8eac909
|
@ -134,6 +134,17 @@ class FlipdotSender(object):
|
||||||
|
|
||||||
self._sock.sendto(bytes(packet), (self._udphost, self._udpport))
|
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):
|
def send_text(self, text,fadespeed=0):
|
||||||
image = Image.new("RGBA", self._img_size, FlipdotSender.C_BLACK)
|
image = Image.new("RGBA", self._img_size, FlipdotSender.C_BLACK)
|
||||||
|
|
|
@ -72,21 +72,55 @@ def on_message(client, userdata, msg):
|
||||||
flipthread.start()
|
flipthread.start()
|
||||||
|
|
||||||
|
|
||||||
if msg.topic == "raum2/flipdot/textFull/set": #scale/break text automatically
|
if mode!="inuse" and msg.topic == "raum2/flipdot/textFull/set": #scale/break text automatically
|
||||||
mode="inuse"
|
#mode="inuse"
|
||||||
updateTimeout()
|
#updateTimeout()
|
||||||
payload = msg.payload.decode("utf-8")
|
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]=='~':
|
if len(payload)>0 and payload[0]=='~':
|
||||||
payload=payload[1:]
|
payload=payload[1:]
|
||||||
flipdot.send_textFull(payload,50)
|
#flipdot.send_textFull(payload,50)
|
||||||
flipdot.send_textFull(payload)
|
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":
|
if msg.topic == "raum2/flipdot/image/set":
|
||||||
|
'''
|
||||||
mode="inuse"
|
mode="inuse"
|
||||||
updateTimeout()
|
updateTimeout()
|
||||||
payload = msg.payload.decode("utf-8")
|
payload = msg.payload.decode("utf-8")
|
||||||
print(payload)
|
print(payload)
|
||||||
flipdot.send_bytes(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
|
timeout=0
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue