From 7bdce37fd3f18e2712e18c4e2c64cac69af0aca1 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 19 Sep 2021 19:43:11 +0200 Subject: :boom: Introduce new UI based on svelte, and rewrite a lot of the node app and the NeoRuntime --- .../pythonSupportFiles/LuxcenaNeo/Matrix.py | 73 ------------- .../pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py | 29 ----- .../pythonSupportFiles/LuxcenaNeo/Strip.py | 121 --------------------- .../pythonSupportFiles/LuxcenaNeo/__init__.py | 10 -- src/compileAndRun/pythonSupportFiles/entry.py | 76 ------------- 5 files changed, 309 deletions(-) delete mode 100644 src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py delete mode 100644 src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py delete mode 100644 src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py delete mode 100644 src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py delete mode 100644 src/compileAndRun/pythonSupportFiles/entry.py (limited to 'src/compileAndRun/pythonSupportFiles') diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py deleted file mode 100644 index 320da02..0000000 --- a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Matrix.py +++ /dev/null @@ -1,73 +0,0 @@ -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 = [] # Holds the matrix - self.xLen = 0 # The width of the matrix - self.yLen = len(matrix) # The heigth of the matrix - - for yPos in range(len(matrix)): - yVal = matrix[yPos] - - thisY = [] - for xPos in range(len(yVal)): - # This gets the range of segment n - segmentRange = getSegmentRange(segments, matrix[yPos][xPos][0]) - - # This adds the range to the current row's list - # if in the config [, ] - # reversed == true, revese the list before adding it - thisY += reversed(segmentRange) if matrix[yPos][xPos][1] else segmentRange - - # This just finds the longest row in the matrix - if (len(thisY) > self.xLen): - self.xLen = len(thisY) - - 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] - - def dump(self): - nSpacers = (self.xLen*6) // 2 - 6 - print( ("=" * nSpacers) + "Matrix dump" + ("=" * nSpacers) ) - - for y in self.matrix: - thisYLine = "" - for x in y: - thisYLine += ( ' ' * (5 - len(str(x))) ) + str(x) + ' ' - print(thisYLine) - - print("=" * (self.xLen*6)) - - -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/NeoBehaviour.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py deleted file mode 100644 index b0238e7..0000000 --- a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py +++ /dev/null @@ -1,29 +0,0 @@ -# This is the base-class "main" should inherit from! -# All methods are blocking :) This means that you could potentially loose a "tick" -# For example, if "eachSecond" is taking up the thread, and the clock goes from 11:58 to 12:02, "eachHour", will not be called. -class NeoBehaviour: - - # THIS METHOD SHOULD NOT BE OVERIDDEN! Use onStart if you want a setup-method!!! - # Contains basic setup - def __init__(self): - return - - # This method will be run right after __init__ - def onStart(self): - return - - # This method is called every second (on the clock), given that the thread is open - def eachSecond(self): - return - - # This method is called every mintue (on the clock), given that the thread is open - def eachMinute(self): - return - - # This method is called every whole hour (on the clock), given that the thread is open - def eachHour(self): - return - - # This method is called every day at noon, given that the thread is open - def eachDay(self): - return diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py deleted file mode 100644 index c3a913f..0000000 --- a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py +++ /dev/null @@ -1,121 +0,0 @@ -from neopixel import * -from Matrix import Matrix, getSegmentRange - -class Strip: - - def __init__(self, stripConf): - self.SEGMENTS = stripConf["segments"] - self.SEGMENT_CONFIG = stripConf["segment_config"] - - self.LED_FREQ_HZ = stripConf["led_freq_hz"] # LED signal frequency in hertz (usually 800khz) - self.LED_CHANNEL = stripConf["led_channel"] # Set to '1' for GPIOs 13, 19, 41, 45, 53 - self.LED_INVERT = stripConf["led_invert"] # True to invert the signal, (when using NPN transistor level shift) - self.LED_PIN = stripConf["led_pin"] # 18 uses PWM, 10 uses SPI /dev/spidev0.0 - self.LED_DMA = stripConf["led_dma"] # DMA channel for generating the signal, on the newer ones, try 10 - self.LED_COUNT = sum(self.SEGMENTS) # Number of LEDs in strip - - - self.LED_BRIGHTNESS = 255 - - self.strip = Adafruit_NeoPixel( - self.LED_COUNT, - self.LED_PIN, - self.LED_FREQ_HZ, - self.LED_DMA, - self.LED_INVERT, - self.LED_BRIGHTNESS, - self.LED_CHANNEL - ) - - self.strip.begin() - - # Blank out all the LEDs - i = 0 - while True: - self.strip.setPixelColor(i, 0) - i += 1 - if (i > self.LED_COUNT): break - self.strip.show() - - # Setup matrix - print(" * Generating matrix") - #try: - self.pixelMatrix = Matrix(self.SEGMENTS, stripConf["matrix"]) - self.pixelMatrix.dump() - #except: - # print("Something went wrong while setting up your self-defined matrix.") - - def show(self): - """Update the display with the data from the LED buffer.""" - self.strip.show() - - def setPixelColor(self, n, color): - """Set LED at position n to the provided 24-bit color value (in RGB order). - """ - 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 - lowest intensity and 255 is the highest intensity). - """ - 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. - """ - self.strip.setBrightness(brightness) - - def getBrightness(self): - """Get the brightness value for each LED in the buffer. A brightness - of 0 is the darkest and 255 is the brightest. - """ - return self.strip.getBrightness() - - def getPixels(self): - """Return an object which allows access to the LED display data as if - it were a sequence of 24-bit RGB values. - """ - return self.strip.getPixels() - - def numPixels(self): - """Return the number of pixels in the display.""" - return self.LED_COUNT - - def getPixelColor(self, n): - """Get the 24-bit RGB color value for the LED at position n.""" - return self.strip.getPixelColor(n) - - -def Color(red, green, blue, white = 0): - """Convert the provided red, green, blue color to a 24-bit color value. - Each color component should be a value 0-255 where 0 is the lowest intensity - and 255 is the highest intensity. - """ - return (white << 24) | (red << 16)| (green << 8) | blue - -def hexColor(value): - value = value.lstrip('#') - lv = len(value) - rgb = tuple(int(value[i:i+lv/3], 16) for i in range(0, lv, lv/3)) - return (0 << 24) | (rgb[1] << 16) | (rgb[0] << 8) | rgb[2] diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py deleted file mode 100644 index 40b8e2d..0000000 --- a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from NeoBehaviour import * -from Strip import * - -strip = None # The strip object, should be set in entry.py, and is then accessible in the script-file -forceStop = False # When set to true, execution of the script will halt - -# A function that could be used to halt the script -def stop(): - global forceStop - forceStop = True diff --git a/src/compileAndRun/pythonSupportFiles/entry.py b/src/compileAndRun/pythonSupportFiles/entry.py deleted file mode 100644 index 45de822..0000000 --- a/src/compileAndRun/pythonSupportFiles/entry.py +++ /dev/null @@ -1,76 +0,0 @@ -# This is the entry-point for all Luxcena-Neo python-scripts -# The script should be in the same folder as this, and be named "script.py" -# In the future you could possibly have more files and stuff alongside the "script.py"-file as well -import sys -import json -import importlib -import datetime - -def runSync(moduleSc, sc): - timeNow = datetime.datetime.now() - lastDay = timeNow.day - lastHour = timeNow.hour - lastMinute = timeNow.minute - lastSecond = timeNow.second - - while True: - timeNow = datetime.datetime.now() - - if ("LuxcenaNeo" in dir(moduleSc)): - if moduleSc.LuxcenaNeo.forceStop: break - elif ("neo" in dir(moduleSc)): - if moduleSc.neo.forceStop == True: break - - if (timeNow.second != lastSecond): - lastSecond = timeNow.second - sc.eachSecond() - - if (timeNow.minute != lastMinute): - lastMinute = timeNow.minute - sc.eachMinute() - - if (timeNow.hour != lastHour): - lastHour = timeNow.hour - sc.eachHour() - - if (timeNow.day != lastDay): - lastDay = timeNow.lastDay - sc.eachDay() - -def runAsync(moduleSc, sc): - return - -def main(): - print ("Starting script named \"{0}\"".format("test")) - - root_dir = sys.argv[1] - config_dir = root_dir + "/config/" - - print ("> Loading pixel-configuration...") - with open(config_dir + "strip.json", "r") as rawStripConf: - stripConf = json.load(rawStripConf) - - print ("> Initializing script...") - moduleSc = importlib.import_module("script") - - if ("LuxcenaNeo" in dir(moduleSc)): - moduleSc.LuxcenaNeo.strip = moduleSc.LuxcenaNeo.Strip(stripConf) - elif ("neo" in dir(moduleSc)): - moduleSc.neo.strip = moduleSc.neo.Strip(stripConf) - else: - raise Exception("Neither LuxcenaNeo nor neo found in script, check docs!") - - sc = moduleSc.Main() - - print ("> Running the script...") - sc.onStart() - - if (("async" in dir(moduleSc)) and (moduleSc.async == True)): - runAsync(moduleSc, sc) - else: - runSync(moduleSc, sc) - - print ("> Script exited...") - -if __name__ == "__main__": - main() -- cgit v1.2.3