From 03609127b8ac8e786c962f8af677744eb16cdd60 Mon Sep 17 00:00:00 2001 From: Gigo Date: Mon, 1 Jul 2013 20:03:25 +0200 Subject: [PATCH 1/6] moved old scripts to archive --- {scripts => archive/scripts}/gen_string.py | 0 {scripts => archive/scripts}/golflip.py | 0 {scripts => archive/scripts}/invaderflip.py | 0 {scripts => archive/scripts}/noise.py | 0 {scripts => archive/scripts}/sinus.py | 0 {scripts => archive/scripts}/smileyflip.py | 0 {scripts => archive/scripts}/snake/.gitignore | 0 {scripts => archive/scripts}/snake/lvl/40_16/bottleneck | 0 {scripts => archive/scripts}/snake/lvl/40_16/classic | 0 {scripts => archive/scripts}/snake/lvl/40_16/highway | 0 {scripts => archive/scripts}/snake/lvl/40_16/splitbrain | 0 {scripts => archive/scripts}/snake/snake.py | 0 {scripts => archive/scripts}/testsender.py | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename {scripts => archive/scripts}/gen_string.py (100%) rename {scripts => archive/scripts}/golflip.py (100%) rename {scripts => archive/scripts}/invaderflip.py (100%) rename {scripts => archive/scripts}/noise.py (100%) rename {scripts => archive/scripts}/sinus.py (100%) rename {scripts => archive/scripts}/smileyflip.py (100%) rename {scripts => archive/scripts}/snake/.gitignore (100%) rename {scripts => archive/scripts}/snake/lvl/40_16/bottleneck (100%) rename {scripts => archive/scripts}/snake/lvl/40_16/classic (100%) rename {scripts => archive/scripts}/snake/lvl/40_16/highway (100%) rename {scripts => archive/scripts}/snake/lvl/40_16/splitbrain (100%) rename {scripts => archive/scripts}/snake/snake.py (100%) rename {scripts => archive/scripts}/testsender.py (100%) diff --git a/scripts/gen_string.py b/archive/scripts/gen_string.py similarity index 100% rename from scripts/gen_string.py rename to archive/scripts/gen_string.py diff --git a/scripts/golflip.py b/archive/scripts/golflip.py similarity index 100% rename from scripts/golflip.py rename to archive/scripts/golflip.py diff --git a/scripts/invaderflip.py b/archive/scripts/invaderflip.py similarity index 100% rename from scripts/invaderflip.py rename to archive/scripts/invaderflip.py diff --git a/scripts/noise.py b/archive/scripts/noise.py similarity index 100% rename from scripts/noise.py rename to archive/scripts/noise.py diff --git a/scripts/sinus.py b/archive/scripts/sinus.py similarity index 100% rename from scripts/sinus.py rename to archive/scripts/sinus.py diff --git a/scripts/smileyflip.py b/archive/scripts/smileyflip.py similarity index 100% rename from scripts/smileyflip.py rename to archive/scripts/smileyflip.py diff --git a/scripts/snake/.gitignore b/archive/scripts/snake/.gitignore similarity index 100% rename from scripts/snake/.gitignore rename to archive/scripts/snake/.gitignore diff --git a/scripts/snake/lvl/40_16/bottleneck b/archive/scripts/snake/lvl/40_16/bottleneck similarity index 100% rename from scripts/snake/lvl/40_16/bottleneck rename to archive/scripts/snake/lvl/40_16/bottleneck diff --git a/scripts/snake/lvl/40_16/classic b/archive/scripts/snake/lvl/40_16/classic similarity index 100% rename from scripts/snake/lvl/40_16/classic rename to archive/scripts/snake/lvl/40_16/classic diff --git a/scripts/snake/lvl/40_16/highway b/archive/scripts/snake/lvl/40_16/highway similarity index 100% rename from scripts/snake/lvl/40_16/highway rename to archive/scripts/snake/lvl/40_16/highway diff --git a/scripts/snake/lvl/40_16/splitbrain b/archive/scripts/snake/lvl/40_16/splitbrain similarity index 100% rename from scripts/snake/lvl/40_16/splitbrain rename to archive/scripts/snake/lvl/40_16/splitbrain diff --git a/scripts/snake/snake.py b/archive/scripts/snake/snake.py similarity index 100% rename from scripts/snake/snake.py rename to archive/scripts/snake/snake.py diff --git a/scripts/testsender.py b/archive/scripts/testsender.py similarity index 100% rename from scripts/testsender.py rename to archive/scripts/testsender.py From d962fbf90708c6d39bb6e97d428bfb5ea6c735d3 Mon Sep 17 00:00:00 2001 From: Gigo Date: Mon, 1 Jul 2013 20:05:03 +0200 Subject: [PATCH 2/6] added .pyc and project-files to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 010dfe0..5e68935 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ Gemfile.lock .rvmrc tmp/ Gemfile.lock +.project +.pydevproject +*.py[cod] From cd733fe42d7f44941f1367e228488e744e0c5705 Mon Sep 17 00:00:00 2001 From: Gigo Date: Mon, 1 Jul 2013 20:05:32 +0200 Subject: [PATCH 3/6] New python api with hq status script --- scripts/FlipdotAPI/FlipdotMatrix.py | 180 ++++++++ scripts/FlipdotAPI/__init__.py | 0 scripts/FlipdotAPI/font.py | 638 ++++++++++++++++++++++++++++ scripts/hqstatus.py | 47 ++ 4 files changed, 865 insertions(+) create mode 100644 scripts/FlipdotAPI/FlipdotMatrix.py create mode 100644 scripts/FlipdotAPI/__init__.py create mode 100644 scripts/FlipdotAPI/font.py create mode 100755 scripts/hqstatus.py diff --git a/scripts/FlipdotAPI/FlipdotMatrix.py b/scripts/FlipdotAPI/FlipdotMatrix.py new file mode 100644 index 0000000..5e16658 --- /dev/null +++ b/scripts/FlipdotAPI/FlipdotMatrix.py @@ -0,0 +1,180 @@ +import socket +from font import font8px + +class FlipdotMatrix(): + def __init__(self, + udpHostAndPort = ("2001:7f0:3003:cafe:222:f9ff:fe01:c65",2323), + imageSize=(40, 16) + ): + self.__sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + self.udpHostAndPort=udpHostAndPort + self.flipdotImage = FlipdotImage.newBlackFlipdotImage(imageSize[0], imageSize[1]) + + def resetAll(self): + """ + flip every pixel at least once, end with cleared Matrix + """ + width = self.flipdotImage.width + height = self.flipdotImage.height + whiteImage = FlipdotImage.newWhiteFlipdotImage(width, height) + blackImage = FlipdotImage.newBlackFlipdotImage(width, height) + self.show(whiteImage) + self.show(blackImage) + + def __showSerializedArrayOfPixels(self, imageArray): + udpPacket = FlipdotMatrix.__arrayToPacket(imageArray) + self.__sendUdpPackage(udpPacket) + + def show(self, image): + """ + send FlipdotImage to display. fills up with black pixels + """ + self.__clearFlipdotImageWithoutUpdate() + self.flipdotImage.blitImageAtPosition(image) + self.__updateFlipdotMatrix() + + def showBlit (self, image, xPos=0, yPos=0): + """ + send FlipdotImage to display, keeps old pixels around + """ + self.flipdotImage.blitImageAtPosition(image, xPos, yPos) + self.__updateFlipdotMatrix() + + def __updateFlipdotMatrix(self): + serializedImageArray = self.flipdotImage.serializeImageArray() + self.__showSerializedArrayOfPixels(serializedImageArray) + + def clear(self): + """ + clears display. fills with black pixels + """ + self.__clearFlipdotImageWithoutUpdate() + self.__updateFlipdotMatrix() + + def __clearFlipdotImageWithoutUpdate(self): + width = self.flipdotImage.width + height = self.flipdotImage.height + self.flipdotImage = FlipdotImage.newBlackFlipdotImage(width, height) + + def showText(self, text, linebreak = False, xPos=0, yPos = 0): + """ + print text to display + """ + self.__clearFlipdotImageWithoutUpdate() + self.flipdotImage.blitTextAtPosition(text, linebreak, xPos, yPos) + self.__updateFlipdotMatrix() + + def showBlitText(self, text, linebreak=False, xPos=0, yPos=0): + """ + print text to display, keeps old pixels around + """ + self.flipdotImage.blitTextAtPosition(text, linebreak, xPos, yPos) + self.__updateFlipdotMatrix() + + @staticmethod + def __arrayToPacket(imageArray): + return str(bytearray([FlipdotMatrix.__list2byte(imageArray[i*8:i*8+8]) for i in range(len(imageArray)/8)])) + + @staticmethod + def __list2byte(ArrayOfBinaryInts): + byte = 0 + for i in range(8): + byte += 2**(7-i) if ArrayOfBinaryInts[i] else 0 + return byte + + + def __sendUdpPackage(self, udpPacket): + self.__sock.sendto(udpPacket, self.udpHostAndPort) + + + +class FlipdotImage(object): + BLACKPIXEL = 0 + WHITEPIXEL = 1 + + def __init__(self, pixel2DArray): + self.width = len(pixel2DArray[0]) + self.height = len(pixel2DArray) + self.rowArrayOfLineArraysOfPixels = pixel2DArray + + def blitImageAtPosition(self, flipdotImage, xPos=0, yPos=0): + for lineNr in range(self.height): + newImageLineNr = lineNr-yPos + if newImageLineNr >= 0 and flipdotImage.height > newImageLineNr: + self.__blitLineAtPosition(flipdotImage, lineNr, newImageLineNr, xPos, yPos) + + def __blitLineAtPosition(self, flipdotImage, lineNr, newImageLineNr, xPos, yPos): + for rowNr in range(self.width): + newImageRowNr = rowNr - xPos + if newImageRowNr >= 0 and flipdotImage.width > newImageRowNr: + self.rowArrayOfLineArraysOfPixels[lineNr][rowNr] = flipdotImage.rowArrayOfLineArraysOfPixels[newImageLineNr][newImageRowNr] + + def blitTextAtPosition(self, text, autoLineBreak = False, xPos = 0, yPos = 0, __indentXPos=None): + if __indentXPos==None: + __indentXPos = xPos + + if len(text) <= 0: + return + + letterImage = self.__getLetterImageForNextLetter(text) + + if autoLineBreak and self.__isLineBreakRequired(letterImage, xPos): + xPos = __indentXPos + yPos = yPos + font8px["lineheight"] + + self.blitImageAtPosition(letterImage, xPos, yPos) + + nextLetterXPos = xPos + letterImage.width + font8px["whitespace"] + self.blitTextAtPosition(text[1:], autoLineBreak, nextLetterXPos, yPos, __indentXPos) + + + def __isLineBreakRequired(self, letterImage, xPos): + return letterImage.width > self.width-xPos + + def __getLetterImageForNextLetter(self, text): + nextLetter = text[:1].upper() + if not nextLetter in font8px: + nextLetter="?" + return FlipdotImage(font8px[nextLetter]) + + def serializeImageArray(self): + imageArray = [] + for y in range(self.height): + for x in range(self.width): + imageArray.append(self.rowArrayOfLineArraysOfPixels[y][x]) + return imageArray + + def getLine(self, line): + return self.rowArrayOfLineArraysOfPixels[line] + + @classmethod + def newBlackFlipdotImage(cls, width, height): + pixel2DArray = cls.generateColoredRowArrayOfLineArraysOfPixels(width, height, FlipdotImage.BLACKPIXEL) + return cls(pixel2DArray) + + @classmethod + def newWhiteFlipdotImage(cls, width, height): + pixel2DArray = cls.generateColoredRowArrayOfLineArraysOfPixels(width, height, FlipdotImage.WHITEPIXEL) + return cls(pixel2DArray) + + @staticmethod + def generateColoredRowArrayOfLineArraysOfPixels(width, height, color): + rowArrayOfLineArrayOfPixels = [] + for y in range(height): + rowArrayOfLineArrayOfPixels.append(FlipdotImage.generateColoredLineArrayOfPixels(width, color)) + return rowArrayOfLineArrayOfPixels + + @staticmethod + def generateColoredLineArrayOfPixels(width, color): + lineArrayOfPixels = [] + for x in range(width): + lineArrayOfPixels.append(color) + return lineArrayOfPixels + +#main +if (__name__=="__main__"): + matrix = FlipdotMatrix() + matrix.resetAll() + matrix.showText("flip the dots!", True) + + diff --git a/scripts/FlipdotAPI/__init__.py b/scripts/FlipdotAPI/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/FlipdotAPI/font.py b/scripts/FlipdotAPI/font.py new file mode 100644 index 0000000..61c514c --- /dev/null +++ b/scripts/FlipdotAPI/font.py @@ -0,0 +1,638 @@ +# -*- coding: utf-8 -*- + + +font8px={ + "lineheight":8, + "whitespace":0, + "A": [ + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [1,1,1,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "B": [ + [0,0,0,0,0], + [1,1,1,0,0], + [1,0,0,1,0], + [1,1,1,0,0], + [1,0,0,1,0], + [1,1,1,0,0], + [0,0,0,0,0], + ], + "C": [ + [0,0,0,0,0], + [0,1,1,1,0], + [1,0,0,0,0], + [1,0,0,0,0], + [1,0,0,0,0], + [0,1,1,1,0], + [0,0,0,0,0], + ], + "D": [ + [0,0,0,0,0], + [1,1,1,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,1,1,0,0], + [0,0,0,0,0], + ], + "E": [ + [0,0,0,0,0], + [1,1,1,1,0], + [1,0,0,0,0], + [1,1,1,1,0], + [1,0,0,0,0], + [1,1,1,1,0], + [0,0,0,0,0], + ], + "F": [ + [0,0,0,0,0], + [1,1,1,1,0], + [1,0,0,0,0], + [1,1,1,1,0], + [1,0,0,0,0], + [1,0,0,0,0], + [0,0,0,0,0], + ], + "G": [ + [0,0,0,0,0,0], + [0,1,1,1,0,0], + [1,0,0,0,0,0], + [1,0,0,1,1,0], + [1,0,0,0,1,0], + [0,1,1,1,0,0], + [0,0,0,0,0,0], + ], + "H": [ + [0,0,0,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,1,1,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "I": [ + [0,0], + [1,0], + [1,0], + [1,0], + [1,0], + [1,0], + [0,0], + ], + "J": [ + [0,0,0,0], + [0,0,1,0], + [0,0,1,0], + [0,0,1,0], + [1,0,1,0], + [0,1,0,0], + ], + "K": [ + [0,0,0,0], + [1,0,1,0], + [1,0,1,0], + [1,1,0,0], + [1,0,1,0], + [1,0,1,0], + [0,0,0,0], + ], + "L": [ + [0,0,0,0], + [1,0,0,0], + [1,0,0,0], + [1,0,0,0], + [1,0,0,0], + [1,1,1,0], + [0,0,0,0], + ], + "M": [ + [0,0,0,0,0,0], + [1,0,0,0,1,0], + [1,1,0,1,1,0], + [1,0,1,0,1,0], + [1,0,0,0,1,0], + [1,0,0,0,1,0], + [0,0,0,0,0,0], + ], + "N": [ + [0,0,0,0,0], + [1,0,0,1,0], + [1,1,0,1,0], + [1,0,1,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "O": [ + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,1,0,0], + [0,0,0,0,0], + ], + "P": [ + [0,0,0,0,0], + [1,1,1,0,0], + [1,0,0,1,0], + [1,1,1,0,0], + [1,0,0,0,0], + [1,0,0,0,0], + [0,0,0,0,0], + ], + "Q": [ + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,1,0,0], + [0,0,0,1,0], + ], + "R": [ + [0,0,0,0,0], + [1,1,1,0,0], + [1,0,0,1,0], + [1,1,1,0,0], + [1,0,1,0,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "S": [ + [0,0,0,0,0], + [0,1,1,1,0], + [1,0,0,0,0], + [0,1,1,0,0], + [0,0,0,1,0], + [1,1,1,0,0], + [0,0,0,0,0], + ], + "T": [ + [0,0,0,0], + [1,1,1,0], + [0,1,0,0], + [0,1,0,0], + [0,1,0,0], + [0,1,0,0], + [0,0,0,0], + ], + "U": [ + [0,0,0,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,1,1,0], + [0,0,0,0,0], + ], + "V": [ + [0,0,0,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,0,1,0], + [0,0,1,1,0], + [0,0,0,1,0], + [0,0,0,0,0], + ], + "W": [ + [0,0,0,0,0,0], + [1,0,0,0,1,0], + [1,0,0,0,1,0], + [1,0,1,0,1,0], + [1,1,0,1,1,0], + [1,0,0,0,1,0], + [0,0,0,0,0,0], + ], + "X": [ + [0,0,0,0], + [1,0,1,0], + [1,0,1,0], + [0,1,0,0], + [1,0,1,0], + [1,0,1,0], + [0,0,0,0], + ], + "Y": [ + [0,0,0,0], + [1,0,1,0], + [1,0,1,0], + [0,1,0,0], + [0,1,0,0], + [0,1,0,0], + [0,0,0,0], + ], + "Z": [ + [0,0,0,0,0], + [1,1,1,1,0], + [0,0,1,0,0], + [0,0,1,0,0], + [0,1,0,0,0], + [1,1,1,1,0], + [0,0,0,0,0], + ], + "Ä": [ + [1,0,0,1,0], + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [1,1,1,1,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "Ö": [ + [1,0,0,1,0], + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,1,0,0], + [0,0,0,0,0], + ], + "Ü": [ + [1,0,0,1,0], + [0,0,0,0,0], + [1,0,0,1,0], + [1,0,0,1,0], + [1,0,0,1,0], + [0,1,1,0,0], + [0,0,0,0,0], + ], + "-": [ + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + [1,1,1,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + ], + "?": [ + [0,0,0,0], + [0,1,1,0], + [1,0,1,0], + [0,0,1,0], + [0,1,0,0], + [0,0,0,0], + [0,1,0,0], + ], + "!": [ + [0,0], + [1,0], + [1,0], + [1,0], + [0,0], + [1,0], + [0,0], + ], + "\"": [ + [0,0,0,0], + [1,0,1,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + ], + "$": [ + [0,0,1,0,0], + [0,1,1,1,0], + [1,0,1,0,0], + [0,1,1,0,0], + [0,0,1,1,0], + [1,1,1,0,0], + [0,0,1,0,0], + ], + "%": [ + [0,0,0,0,0], + [1,0,0,1,0], + [0,0,1,0,0], + [0,0,1,0,0], + [0,1,0,0,0], + [1,0,0,1,0], + [0,0,0,0,0], + ], + "&": [ + [0,0,0,0,0], + [0,1,0,0,0], + [1,0,1,0,0], + [0,1,0,0,0], + [1,0,1,0,0], + [0,1,0,1,0], + [0,0,0,0,0], + ], + "/": [ + [0,0,0,0,0], + [0,0,0,0,0], + [0,0,0,1,0], + [0,0,1,0,0], + [0,1,0,0,0], + [1,0,0,0,0], + [0,0,0,0,0], + ], + "(": [ + [0,0,0], + [0,1,0], + [1,0,0], + [1,0,0], + [1,0,0], + [0,1,0], + [0,0,0], + ], + ")": [ + [0,0,0], + [1,0,0], + [0,1,0], + [0,1,0], + [0,1,0], + [1,0,0], + [0,0,0], + ], + "=": [ + [0,0,0], + [0,0,0], + [1,1,0], + [0,0,0], + [1,1,0], + [0,0,0], + [0,0,0], + ], + "`": [ + [0,0,0], + [1,0,0], + [0,1,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + ], + "+": [ + [0,0,0,0], + [0,0,0,0], + [0,1,0,0], + [1,1,1,0], + [0,1,0,0], + [0,0,0,0], + [0,0,0,0], + ], + "-": [ + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + [1,1,1,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + ], + "#": [ + [0,0,0,0,0,0], + [0,1,0,1,0,0], + [1,1,1,1,1,0], + [0,1,0,1,0,0], + [1,1,1,1,1,0], + [0,1,0,1,0,0], + [0,0,0,0,0,0], + ], + ".": [ + [0,0], + [0,0], + [0,0], + [0,0], + [0,0], + [1,0], + [0,0], + ], + " ": [ + [0,0], + [0,0], + [0,0], + [0,0], + [0,0], + [0,0], + [0,0], + ], + ",": [ + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,1,0], + [0,1,0], + [1,0,0], + ], + ";": [ + [0,0,0], + [0,0,0], + [0,1,0], + [0,0,0], + [0,1,0], + [0,1,0], + [1,0,0], + ], + ":": [ + [0,0], + [0,0], + [1,0], + [0,0], + [1,0], + [0,0], + [0,0], + ], + "_": [ + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [1,1,0], + [0,0,0], + ], + "'": [ + [0,0], + [1,0], + [1,0], + [0,0], + [0,0], + [0,0], + [0,0], + ], + "*": [ + [0,0,0,0,0,0], + [0,0,1,0,0,0], + [1,0,1,0,1,0], + [0,1,1,1,0,0], + [1,0,1,0,1,0], + [0,0,1,0,0,0], + [0,0,0,0,0,0], + ], + "'": [ + [0,0,0], + [0,1,0], + [1,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + [0,0,0], + ], + "^": [ + [0,0,0,0], + [0,1,0,0], + [1,0,1,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + [0,0,0,0], + ], + "<": [ + [0,0,0], + [0,0,0], + [0,1,0], + [1,0,0], + [0,1,0], + [0,0,0], + [0,0,0], + ], + ">": [ + [0,0,0], + [0,0,0], + [1,0,0], + [0,1,0], + [1,0,0], + [0,0,0], + [0,0,0], + ], + "[": [ + [0,0,0], + [1,1,0], + [1,0,0], + [1,0,0], + [1,0,0], + [1,1,0], + [0,0,0], + ], + "]": [ + [0,0,0], + [1,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + [1,1,0], + [0,0,0], + ], + "|": [ + [0,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + ], + "\n": [ + [], + [], + [], + [], + [], + [], + [], + ], + "1": [ + [0,0,0], + [0,1,0], + [1,1,0], + [0,1,0], + [0,1,0], + [0,1,0], + [0,0,0], + ], + "2": [ + [0,0,0,0], + [0,1,0,0], + [1,0,1,0], + [0,0,1,0], + [0,1,0,0], + [1,1,1,0], + [0,0,0,0], + ], + "3": [ + [0,0,0,0], + [1,1,0,0], + [0,0,1,0], + [0,1,0,0], + [0,0,1,0], + [1,1,0,0], + [0,0,0,0], + ], + "4": [ + [0,0,0,0], + [0,0,1,0], + [0,1,0,0], + [1,0,0,0], + [1,1,1,0], + [0,1,0,0], + [0,0,0,0], + ], + "5": [ + [0,0,0,0], + [1,1,1,0], + [1,0,0,0], + [1,1,0,0], + [0,0,1,0], + [1,1,0,0], + [0,0,0,0], + ], + "6": [ + [0,0,0,0], + [0,1,1,0], + [1,0,0,0], + [1,1,0,0], + [1,0,1,0], + [0,1,0,0], + [0,0,0,0], + ], + "7": [ + [0,0,0,0], + [1,1,1,0], + [0,0,1,0], + [0,1,0,0], + [0,1,0,0], + [0,1,0,0], + [0,0,0,0], + ], + "8": [ + [0,0,0,0,0], + [0,1,1,0,0], + [1,0,0,1,0], + [0,1,1,0,0], + [1,0,0,1,0], + [0,1,1,0,0], + [0,0,0,0,0], + ], + "9": [ + [0,0,0,0], + [0,1,0,0], + [1,0,1,0], + [0,1,1,0], + [0,0,1,0], + [1,1,0,0], + [0,0,0,0], + ], + "0": [ + [0,0,0,0], + [0,1,0,0], + [1,0,1,0], + [1,0,1,0], + [1,0,1,0], + [0,1,0,0], + [0,0,0,0], + ], + } + + diff --git a/scripts/hqstatus.py b/scripts/hqstatus.py new file mode 100755 index 0000000..74c070d --- /dev/null +++ b/scripts/hqstatus.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +import httplib, time +from FlipdotAPI.FlipdotMatrix import FlipdotMatrix + +class HqStatusFlipdotAdapter(object): + def __init__(self, + flipdotMatrix = FlipdotMatrix(), + uberbusHostAndPort=("uberbus.club.muc.ccc.de", 8080) + ): + self.__flipdotMatrix = flipdotMatrix + self.__uberbusHostAndPort = uberbusHostAndPort + self.__oldHqStatus = "" + + def runOnce(self): + hqstatus = self.getHqStatusFromUberbus() + self.showStatusTextWithoutBeginningHq(hqstatus) + + def showStatusTextWithoutBeginningHq(self, hqstatus): + hqstatus = hqstatus[3:] + self.showStatusText(hqstatus) + + def showStatusText(self, hqstatus): + self.__flipdotMatrix.showBlitText(hqstatus) + + def run(self): + while True: + newHqStatus = self.getHqStatusFromUberbus() + if (newHqStatus != self.__oldHqStatus): + self.showStatusTextWithoutBeginningHq(newHqStatus) + self.__oldHqStatus = newHqStatus + time.sleep(5.0) + + def getHqStatusFromUberbus(self): + try: + conn = httplib.HTTPConnection(self.__uberbusHostAndPort[0]+":"+str(self.__uberbusHostAndPort[1])) + conn.request("GET", "/") + r1 = conn.getresponse() + if (r1.status == 200): + return r1.read() + else: + return "hq unknown" + except: + return "hq fnord" + +#main +if (__name__=="__main__"): + HqStatusFlipdotAdapter().run() From cc4cff07e2c96621751c5daa1ed0df01cc5dc21d Mon Sep 17 00:00:00 2001 From: Gigo Date: Mon, 1 Jul 2013 20:14:23 +0200 Subject: [PATCH 4/6] fixed a small bug in hqstatus --- scripts/hqstatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/hqstatus.py b/scripts/hqstatus.py index 74c070d..6d1dcf3 100755 --- a/scripts/hqstatus.py +++ b/scripts/hqstatus.py @@ -20,7 +20,7 @@ def showStatusTextWithoutBeginningHq(self, hqstatus): self.showStatusText(hqstatus) def showStatusText(self, hqstatus): - self.__flipdotMatrix.showBlitText(hqstatus) + self.__flipdotMatrix.showText(hqstatus) def run(self): while True: From cf34afba2595fb0f981ef1ac59ed403fa8fe7aa6 Mon Sep 17 00:00:00 2001 From: Gigo Date: Mon, 1 Jul 2013 20:27:51 +0200 Subject: [PATCH 5/6] gen_string --- scripts/gen_string.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 scripts/gen_string.py diff --git a/scripts/gen_string.py b/scripts/gen_string.py new file mode 100644 index 0000000..8bdf879 --- /dev/null +++ b/scripts/gen_string.py @@ -0,0 +1,9 @@ +import sys +from FlipdotAPI.FlipdotMatrix import FlipdotMatrix + +matrix = FlipdotMatrix() +while True: + text = sys.stdin.readline().decode('utf-8') + if text == "": + break + matrix.showText(text, True) From 20330fe89bf657ec06e361bd141788a5bf39a18a Mon Sep 17 00:00:00 2001 From: Gigo Date: Tue, 2 Jul 2013 17:46:58 +0200 Subject: [PATCH 6/6] LineBreak --- scripts/FlipdotAPI/FlipdotMatrix.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/FlipdotAPI/FlipdotMatrix.py b/scripts/FlipdotAPI/FlipdotMatrix.py index 5e16658..cfa4798 100644 --- a/scripts/FlipdotAPI/FlipdotMatrix.py +++ b/scripts/FlipdotAPI/FlipdotMatrix.py @@ -118,7 +118,7 @@ def blitTextAtPosition(self, text, autoLineBreak = False, xPos = 0, yPos = 0, __ letterImage = self.__getLetterImageForNextLetter(text) - if autoLineBreak and self.__isLineBreakRequired(letterImage, xPos): + if self.__isLineBreakRequired(text, autoLineBreak, letterImage, xPos): xPos = __indentXPos yPos = yPos + font8px["lineheight"] @@ -126,9 +126,16 @@ def blitTextAtPosition(self, text, autoLineBreak = False, xPos = 0, yPos = 0, __ nextLetterXPos = xPos + letterImage.width + font8px["whitespace"] self.blitTextAtPosition(text[1:], autoLineBreak, nextLetterXPos, yPos, __indentXPos) - + + def __isLineBreakRequired(self, text, autoLineBreak, letterImage, xPos): + if text[:1] == "\n": + return True + elif autoLineBreak and self.__isEndOfLineReached(letterImage, xPos): + return True + else: + return False - def __isLineBreakRequired(self, letterImage, xPos): + def __isEndOfLineReached(self, letterImage, xPos): return letterImage.width > self.width-xPos def __getLetterImageForNextLetter(self, text):