From 9397bdb86b57982ab3f36738d415651a413c004a Mon Sep 17 00:00:00 2001 From: Sebastian Muszytowski Date: Fri, 29 Jan 2016 21:10:13 +0100 Subject: add blinkenrocket tests and some additions to main class --- utilities/blinkenrocket.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'utilities/blinkenrocket.py') diff --git a/utilities/blinkenrocket.py b/utilities/blinkenrocket.py index fe79695..545d25f 100644 --- a/utilities/blinkenrocket.py +++ b/utilities/blinkenrocket.py @@ -103,7 +103,12 @@ class modem: wav.writeframes(self.generateAudioFrames()) wav.close() -class textFrame(): +class Frame( object ): + """ Returns the representation """ + def getRepresentation( self ): + raise NotImplementedError( "Should have implemented this" ) + +class textFrame(Frame): text = "" speed = 0 delay = 0 @@ -131,7 +136,7 @@ class textFrame(): def getRepresentation(self): return self.getHeader().append(list(self.text)) -class animationFrame(): +class animationFrame(Frame): animation = [] speed = 0 delay = 0 @@ -164,9 +169,27 @@ class animationFrame(): class blinkenrocket(): eeprom_size = 65536 + startcode = chr(0x99) + patterncode = chr(0xA9) + frames = [] def __init__(self,eeprom_size=65536): - pass + self.eeprom_size = eeprom_size if eeprom_size < 256*1024*1024 else 65536 + + def addFrame(self, frame): + if not isinstance(frame, Frame): + raise RuntimeError("Incorrect frame supplied") + else: + frames.append(frame) + + def getMessage(self): + output = [self.startcode, self.startcode] + for frame in self.frames: + output.extend([self.patterncode,self.patterncode]) + output.extend(frame.getRepresentation()) + return output + + if __name__ == '__main__': -- cgit v1.2.3