summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utilities/blinkenrocket.py29
-rw-r--r--utilities/test_blinkenrocket.py54
2 files changed, 80 insertions, 3 deletions
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__':
diff --git a/utilities/test_blinkenrocket.py b/utilities/test_blinkenrocket.py
new file mode 100644
index 0000000..35c3eec
--- /dev/null
+++ b/utilities/test_blinkenrocket.py
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+import unittest
+from blinkenrocket import *
+
+class TestFrame(unittest.TestCase):
+
+ def test_notImplemented(self):
+ frame = Frame()
+ with self.assertRaises(NotImplementedError):
+ frame.getRepresentation()
+
+class TestAnimation(unittest.TestCase):
+
+ def test_speedDefault(self):
+ anim = animationFrame([])
+ self.assertEquals(ord(anim.getHeader()[0]),1)
+
+ def test_speedOkay(self):
+ anim = animationFrame([],speed=7)
+ self.assertEquals(ord(anim.getHeader()[0]),7)
+
+ def test_speedNotOkay(self):
+ anim = animationFrame([],speed=70)
+ self.assertEquals(ord(anim.getHeader()[0]),1)
+
+ def test_delayDefault(self):
+ anim = animationFrame([])
+ self.assertEquals(ord(anim.getHeader()[1]),0)
+
+ def test_delayOkay(self):
+ anim = animationFrame([],delay=7)
+ self.assertEquals(ord(anim.getHeader()[1]),7)
+
+ def test_delayNotOkay(self):
+ anim = animationFrame([],delay=70)
+ self.assertEquals(ord(anim.getHeader()[1]),0)
+
+ def test_illegalLength(self):
+ with self.assertRaises(Exception):
+ anim = animationFrame([0x11,0x12,0x13,0x14])
+
+ def test_allowedLength(self):
+ anim = animationFrame([0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18])
+
+ def test_defaultHeaderOK(self):
+ anim = animationFrame([])
+ self.assertEquals(anim.getHeader(),[chr(1),chr(0)])
+
+ def test_differentHeaderOK(self):
+ anim = animationFrame([],speed=7,delay=8)
+ self.assertEquals(anim.getHeader(),[chr(7),chr(8)])
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file