The Flipdot works now and the Disco command too ^^
This commit is contained in:
parent
6656934b01
commit
4900a2154a
|
@ -1,8 +1,6 @@
|
|||
###
|
||||
# Copyright (c) 2011, henne
|
||||
# Copyright (c) 2011, fionera
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
from threading import Event, Thread
|
||||
import subprocess
|
||||
|
@ -12,64 +10,18 @@ import supybot.plugins as plugins
|
|||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import socket, time
|
||||
import Image, ImageFont, ImageDraw, sys
|
||||
import fileinput
|
||||
import socket, time, httplib, urllib
|
||||
|
||||
class Flipdot(callbacks.Plugin):
|
||||
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||
def list2byte(l):
|
||||
byte = 0
|
||||
i = 0
|
||||
for i in range(8):
|
||||
byte += 2**(7-i) if l[i] else 0
|
||||
return byte
|
||||
|
||||
def array2packet(a):
|
||||
return str(bytearray([list2byte(a[i*8:i*8+8]) for i in range(len(a)/8)]))
|
||||
|
||||
def str2array(s):
|
||||
IMG_SIZE = (80,16)
|
||||
FONT_SIZE = 11
|
||||
FONT_OFFSET= (1, 3)
|
||||
|
||||
C_BLACK = (0, 0, 0)
|
||||
C_WHITE = (255, 255, 255)
|
||||
|
||||
image = Image.new("RGBA", IMG_SIZE, C_BLACK)
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.fontmode = "1" # No AA
|
||||
#font = ImageFont.load_default()
|
||||
font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", FONT_SIZE)
|
||||
|
||||
draw.text(FONT_OFFSET, s, font=font, fill=C_WHITE)
|
||||
|
||||
imgmap = []
|
||||
for pixel in image.getdata():
|
||||
r, g, b, a = pixel
|
||||
if r == 255:
|
||||
imgmap.append(1)
|
||||
else:
|
||||
imgmap.append(0)
|
||||
return imgmap
|
||||
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Flipdot, self)
|
||||
self.__parent.__init__(irc)
|
||||
# def __del__(self, irc):
|
||||
# ampel.connection.close()
|
||||
def start(self, irc, msg, args):
|
||||
irc.reply("Lampel kann nun gesteuert werden (noch nicht.....)")
|
||||
# ampel.connection.open(self.registryValue('host'), self.registryValue('port'))
|
||||
# ampel.connection.write("io get port 2\n")
|
||||
# buf = ampel.connection.read_until("\n", 1)
|
||||
# self.state = buf[-2]
|
||||
# irc.reply(self.state)
|
||||
start = wrap(start)
|
||||
def hilfe(self, irc, msg, args):
|
||||
irc.reply("hilfe: Hilft dir...")
|
||||
hilfe = wrap(hilfe)
|
||||
def send(self, irc, msg, args):
|
||||
sock.sendto(array2packet(str2array(msg.strip())), (self.registryValue('host'), self.registryValue('port')))
|
||||
send = wrap(send)
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
||||
def text(self, irc, msg, args):
|
||||
irc.reply("Zeigen nun: " + "Wer das liest ist doof")
|
||||
conn = httplib.HTTPConnection("raum.ctdo.de:8000")
|
||||
conn.request("POST", "text=" + "Wer das liest ist doof")
|
||||
response = conn.getresponse()
|
||||
conn.close()
|
||||
text = wrap(text)
|
|
@ -133,6 +133,7 @@ class Lampel(callbacks.Plugin):
|
|||
irc.reply("The Party is over")
|
||||
self.discoTimer.cancel()
|
||||
self.discoan = False
|
||||
self.aus();
|
||||
disco = wrap(disco)
|
||||
def discof(self, irc):
|
||||
ampel.connection.open(self.registryValue('host'), self.registryValue('port'))
|
||||
|
|
Loading…
Reference in New Issue