Added some comments and a decoder for dat files
This commit is contained in:
parent
9235f28f6b
commit
5fb6fc196c
1 changed files with 22 additions and 10 deletions
32
Code/led.py
32
Code/led.py
|
|
@ -10,14 +10,14 @@ def askQuestion():
|
||||||
global matrixWith, matrixHeight
|
global matrixWith, matrixHeight
|
||||||
while True:
|
while True:
|
||||||
col = int(input("Column [0-" + str(matrixWith) + "]: "))
|
col = int(input("Column [0-" + str(matrixWith) + "]: "))
|
||||||
if col <= matrixWith and col >= 0:
|
if matrixWith >= col >= 0:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Column Number Must be Between 0 and " + str(matrixWith))
|
print("Column Number Must be Between 0 and " + str(matrixWith))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
row = int(input("Row [0-" + str(matrixHeight) + "]: "))
|
row = int(input("Row [0-" + str(matrixHeight) + "]: "))
|
||||||
if row <= matrixHeight and row >= 0:
|
if matrixHeight >= row >= 0:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Row Number Must be Between 0 and " + str(matrixHeight))
|
print("Row Number Must be Between 0 and " + str(matrixHeight))
|
||||||
|
|
@ -30,9 +30,9 @@ def getLedNumber(column, row):
|
||||||
pcbNum = int(column / 2)
|
pcbNum = int(column / 2)
|
||||||
colNum = column % 2
|
colNum = column % 2
|
||||||
if colNum == 0:
|
if colNum == 0:
|
||||||
return ((matrixHeight - row) + (pcbNum * ((matrixHeight + 1) * 2)))
|
return (matrixHeight - row) + (pcbNum * ((matrixHeight + 1) * 2))
|
||||||
else:
|
else:
|
||||||
return (((matrixHeight + 1) + row) + (pcbNum * ((matrixHeight + 1) * 2)))
|
return ((matrixHeight + 1) + row) + (pcbNum * ((matrixHeight + 1) * 2))
|
||||||
|
|
||||||
|
|
||||||
def compressFileToString(inputFile):
|
def compressFileToString(inputFile):
|
||||||
|
|
@ -51,18 +51,30 @@ def compressFileToString(inputFile):
|
||||||
|
|
||||||
def saveAnimationData(animation, fileName):
|
def saveAnimationData(animation, fileName):
|
||||||
datFile = open(fileName, 'wb')
|
datFile = open(fileName, 'wb')
|
||||||
for l in range(0, len(animation.matrices)):
|
for l in range(0, len(animation.matrices)): # Write whole animation
|
||||||
for i in range(0, len(animation.matrices[0].panels)):
|
for i in range(0, len(animation.matrices[0].panels)): # Write frame of animation
|
||||||
for j in range(0, len(animation.matrices[0].panels[0].leds)):
|
for j in range(0, len(animation.matrices[0].panels[0].leds)): # Write data for individual panel
|
||||||
datFile.write(
|
datFile.write(
|
||||||
animation.matrices[l].panels[i].leds[j].r.to_bytes(1, byteorder='big'))
|
animation.matrices[l].panels[i].leds[j].r.to_bytes(1, byteorder='big')) # Write red value for led
|
||||||
datFile.write(
|
datFile.write(
|
||||||
animation.matrices[l].panels[i].leds[j].g.to_bytes(1, byteorder='big'))
|
animation.matrices[l].panels[i].leds[j].g.to_bytes(1, byteorder='big')) # Write green value for led
|
||||||
datFile.write(
|
datFile.write(
|
||||||
animation.matrices[l].panels[i].leds[j].b.to_bytes(1, byteorder='big'))
|
animation.matrices[l].panels[i].leds[j].b.to_bytes(1, byteorder='big')) # Write blue value for led
|
||||||
datFile.close()
|
datFile.close()
|
||||||
|
|
||||||
|
|
||||||
|
def loadAnimationData(fileName):
|
||||||
|
datFile = open(fileName, 'rb')
|
||||||
|
retAnimation = Animation()
|
||||||
|
for i in range(0, len(retAnimation.matrices)): # Read whole animation
|
||||||
|
for j in range(0, len(retAnimation.matrices[0].panels)): # Read frame of animation
|
||||||
|
for k in range(0, len(retAnimation.matrices[0].panels[0].leds)): # Read data for individual panel
|
||||||
|
retAnimation.matrices[i].panels[j].leds[k].r = datFile.read(1) # Read red
|
||||||
|
retAnimation.matrices[i].panels[j].leds[k].g = datFile.read(1) # Read green
|
||||||
|
retAnimation.matrices[i].panels[j].leds[k].b = datFile.read(1) # Read blue
|
||||||
|
return retAnimation
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# askQuestion()
|
# askQuestion()
|
||||||
# mainMatrix = Matrix()
|
# mainMatrix = Matrix()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue