diff options
author | Jakob Stendahl <jakob.stendahl@outlook.com> | 2018-12-01 00:26:50 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2018-12-01 00:26:50 +0100 |
commit | 227b9e7d22cddb45deee1558e51d9b792b31f12b (patch) | |
tree | 1791216bb7163aa1128a1df4f41449739e4a48a6 /src | |
parent | bf3ff628acf6e597d76f57c9a908f7136027187c (diff) | |
download | Luxcena-Neo-227b9e7d22cddb45deee1558e51d9b792b31f12b.tar.gz Luxcena-Neo-227b9e7d22cddb45deee1558e51d9b792b31f12b.zip |
:memo: Written docs for supportlib
Diffstat (limited to 'src')
-rw-r--r-- | src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py | 49 | ||||
-rw-r--r-- | src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py | 27 |
2 files changed, 70 insertions, 6 deletions
diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py new file mode 100644 index 0000000..0986b45 --- /dev/null +++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py @@ -0,0 +1,49 @@ +def getSegmentRange(segments, n): + """ Return a list of all the actual led-numbers in a segment """ + # Sum all the segments prior to the one we are looking for + i = 0 + start = 0 + while True: + if i >= n: break + start += segments[i] # Add number of leds in this segment to the start-index + i += 1 + + # Add all numbers in the segment we are looking for to a list + i = start + breakPoint = i + segments[n] + range = [] + while True: + range.append(i) + i += 1 + if i >= breakPoint: break + return range + + +class Matrix: + + def __init__(self, segments, matrix): + self.matrix = [] + for yPos in range(len(matrix)): + yVal = matrix[yPos] + + thisY = [] + for xPos in range(len(yVal)): + if matrix[yPos][xPos][1] == True: + thisY += reversed(getSegmentRange(segments, matrix[yPos][xPos][0])) + else: + thisY += getSegmentRange(segments, matrix[yPos][xPos][0]) + self.matrix.append(thisY) + + def get(self, x, y): + """ Return the value of a place in the matrix given x and y coordinates """ + return self.matrix[y][x] + +if __name__ == "__main__": + testMatrix = Matrix( + [2, 2, 2, 2, 2, 2, 2, 2, 2], + [ + [[0, False], [1, True], [2, False]], + [[3, True], [4, False], [5, True]], + [[6, False], [7, True], [8, False]] + ] + ) diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py index 219bc17..8feca0e 100644 --- a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py +++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py @@ -1,9 +1,5 @@ from neopixel import * - -class Matrix: - - def __init__(self, matrix, segments): - self.t = [] +from Matrix import Matrix, getSegmentRange class Strip: @@ -35,7 +31,7 @@ class Strip: # Setup matrix try: - pixelMatrix = Matrix(stripConf["matrix"], self.segments) + pixelMatrix = Matrix(self.segments, stripConf["matrix"]) except: print("Something went wrong while setting up your self-defined matrix.") @@ -48,6 +44,11 @@ class Strip: """ self.strip.setPixelColor(n, color) + def setPixelColorXY(self, x, y, color): + """Set LED at position n to the provided 24-bit color value (in RGB order). + """ + self.strip.setPixelColor(self.pixelMatrix.get(x, y), color) + def setPixelColorRGB(self, n, red, green, blue, white = 0): """Set LED at position n to the provided red, green, and blue color. Each color component should be a value from 0 to 255 (where 0 is the @@ -55,6 +56,20 @@ class Strip: """ self.strip.setPixelColor(n, Color(red, green, blue, white)) + def setPixelColorXYRGB(self, x, y, red, green, blue, white = 0): + """Set LED at position n to the provided red, green, and blue color. + Each color component should be a value from 0 to 255 (where 0 is the + lowest intensity and 255 is the highest intensity). + """ + self.strip.setPixelColor(self.pixelMatrix.get(x, y), Color(red, green, blue, white)) + + def setSegmentColorRGB(self, segment, red, green, blue, white = 0): + """Set a whole segment to the provided red, green and blue color. + Each color component should be a value from 0 to 255 (where 0 is the + lowest intensity and 255 is the highest intensity).""" + for n in getSegmentRange(self.segments, segment): + self.strip.setPixelColor(n, Color(red, green, blue, white)) + def setBrightness(self, brightness): """Scale each LED in the buffer by the provided brightness. A brightness of 0 is the darkest and 255 is the brightest. |