Lustige neue Funktionen gemacht
This commit is contained in:
parent
863e07d89e
commit
796d950ec3
|
@ -4,6 +4,8 @@ import binascii
|
|||
import io
|
||||
import time
|
||||
import re
|
||||
import numpy as np
|
||||
|
||||
|
||||
class FlipdotSender(object):
|
||||
'''
|
||||
|
@ -63,6 +65,22 @@ class FlipdotSender(object):
|
|||
|
||||
self._sock.sendto(bytes(packet), (self._udphost, self._udpport))
|
||||
|
||||
def send_bytes(self, img):
|
||||
imgmap = []
|
||||
for pixel in img:
|
||||
if pixel == "1":
|
||||
imgmap.append(1)
|
||||
else:
|
||||
imgmap.append(0)
|
||||
|
||||
if len(img) < 1280:
|
||||
imgmap = np.hstack((imgmap, np.zeros(1280-len(img), dtype=int)))
|
||||
|
||||
packet = self._array2packet(imgmap)
|
||||
|
||||
self._sock.sendto(bytes(packet), (self._udphost, self._udpport))
|
||||
|
||||
|
||||
def send_text(self, text):
|
||||
image = Image.new("RGBA", self._img_size, FlipdotSender.C_BLACK)
|
||||
draw = ImageDraw.Draw(image)
|
||||
|
|
|
@ -8,6 +8,7 @@ def on_connect(client, userdata, flags, rc):
|
|||
print("Connected with result code " + str(rc))
|
||||
client.subscribe("raum2/flipdot/text")
|
||||
client.subscribe("raum2/flipdot/scroll")
|
||||
client.subscribe("raum2/flipdot/image")
|
||||
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
|
@ -28,6 +29,10 @@ def on_message(client, userdata, msg):
|
|||
payload = msg.payload.decode("utf-8")
|
||||
flipdot.send_text(payload)
|
||||
|
||||
if msg.topic == "raum2/flipdot/image":
|
||||
payload = msg.payload.decode("utf-8")
|
||||
print(payload)
|
||||
flipdot.send_bytes(payload)
|
||||
|
||||
|
||||
flipdot = FlipdotSender("2001:67c:275c:a9::c", 2323)
|
||||
|
|
Loading…
Reference in New Issue