Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
interfisch | b0d1573a25 | |
interfisch | ffc8eac909 | |
interfisch | 1251a0ad90 |
|
@ -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)
|
||||
|
|
|
@ -48,7 +48,7 @@ class Hangman(object):
|
|||
self._fo_word2= (15, 7) #(15,7)
|
||||
#self._wordlist="/home/pi/mqtt-to-flipdot/hangman/wordlists/nomenliste_de.txt"
|
||||
#self._wordlist="/home/pi/mqtt-to-flipdot/hangman/wordlists/wordsonly.txt"
|
||||
self._wordlist="/root/mqtt-to-flipdot/hangman/wordlists/wordsonly.txt"
|
||||
self._wordlist="/root/mqtt-to-flipdot/hangman/wordlists/wordsonly.txt" #<- on flipdot pi
|
||||
|
||||
#self._wordlist="/home/pi/mqtt-to-flipdot/hangman/wordlists/nerdwords.txt"
|
||||
#self._wordlist="./hangman/wordlists/nerdwords.txt" #<- use for local testing
|
||||
|
@ -58,7 +58,7 @@ class Hangman(object):
|
|||
self._g_chars="" #used characters
|
||||
|
||||
# self._hmdir="/home/pi/mqtt-to-flipdot/hangman/stdhm/"
|
||||
self._hmdir="/root/mqtt-to-flipdot/hangman/stdhm/"
|
||||
self._hmdir="/root/mqtt-to-flipdot/hangman/stdhm/" #<- on flipdot pi
|
||||
#self._hmdir="./hangman/stdhm/" #<- use for local testing
|
||||
|
||||
self._hmimg=[]
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -133,7 +167,7 @@ hangman= Hangman("localhost", 2323,flipdot)
|
|||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.connect("raum.ctdo.de", 1883, 60)
|
||||
client.connect("mqtt.ctdo.de", 1883, 60)
|
||||
client.loop_start()
|
||||
|
||||
|
||||
|
@ -150,5 +184,3 @@ while True:
|
|||
timeout=0
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue