- def _stream2Matrix(self, stream):
- cols = ord(stream[0]) # Obtiene tamaño
- stream = stream[1:1+cols*self.LED_BYTES] # me quedo con el resto
- matrix = {}
- for col in xrange(cols-1, -1, -1):
- for row_byte in xrange(self.LED_BYTES):
- byte = ord(stream[(cols-col-1)*self.LED_BYTES+row_byte])
- for i in xrange(8):
- shift = 8 - i - 1
- matrix[col, row_byte*8+i] = (byte >> shift) & 1
- return matrix
-
- def _matrix2Stream(self, matrix):
- cols = len(matrix) / (self.LED_BYTES*8)
- stream = chr(cols) # primero va el tamaño
- for col in xrange(cols-1, -1, -1):
- for i in xrange(self.LED_BYTES):
- byte = 0
- for row in xrange(8):
- shift = 8 - row - 1
- byte += matrix[col,row] << shift
- stream += chr(byte)
- return stream
-