aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime/Runtime/luxcena_neo
diff options
context:
space:
mode:
authorjakobst1n <jakob.stendahl@outlook.com>2021-10-10 20:33:48 +0000
committerjakobst1n <jakob.stendahl@outlook.com>2021-10-10 20:33:48 +0000
commit72ad29efeb4709572e789a57aa94d00a0eaeb97d (patch)
tree7555a12d7302b59fe0b226a0fd0f18964bfd50fb /NeoRuntime/Runtime/luxcena_neo
parent5cf342cd4400d4f555732f80bfdf3639965c4f88 (diff)
downloadLuxcena-Neo-72ad29efeb4709572e789a57aa94d00a0eaeb97d.tar.gz
Luxcena-Neo-72ad29efeb4709572e789a57aa94d00a0eaeb97d.zip
:construction: Make python 3.5 compatible and fix some weird bugs
Diffstat (limited to 'NeoRuntime/Runtime/luxcena_neo')
-rw-r--r--NeoRuntime/Runtime/luxcena_neo/color_utils.py7
-rw-r--r--NeoRuntime/Runtime/luxcena_neo/neo_behaviour.py20
-rw-r--r--NeoRuntime/Runtime/luxcena_neo/strip.py36
3 files changed, 33 insertions, 30 deletions
diff --git a/NeoRuntime/Runtime/luxcena_neo/color_utils.py b/NeoRuntime/Runtime/luxcena_neo/color_utils.py
index ab29092..3b7ece4 100644
--- a/NeoRuntime/Runtime/luxcena_neo/color_utils.py
+++ b/NeoRuntime/Runtime/luxcena_neo/color_utils.py
@@ -31,10 +31,9 @@ def twentyfour_bit_from_rgb(red, green, blue, white=0):
def twentyfour_bit_from_hex(hex_color: str):
""" Convert the provided hex code to a 24-bit color value. """
+ print(hex_color)
value = hex_color.lstrip('#')
- lv = len(value)
- rgb = tuple(int(value[i:i+lv//3], 16) for i in range(0, lv, lv//3))
- return twentyfour_bit_from_rgb(red=rgb[1], green=rgb[0], blue=rgb[2])
+ return (int(value[0:2], 16) << 16) | (int(value[2:4], 16) << 8) | (int(value[4:6], 16))
def detect_format_convert_color(*color) -> int:
@@ -79,4 +78,4 @@ class Color:
def __invert__(self):
rgb_color = self.rgb
- return Color((255-rgb_color[0], 255-rgb_color[1], 255-rgb_color[2])) \ No newline at end of file
+ return Color((255-rgb_color[0], 255-rgb_color[1], 255-rgb_color[2]))
diff --git a/NeoRuntime/Runtime/luxcena_neo/neo_behaviour.py b/NeoRuntime/Runtime/luxcena_neo/neo_behaviour.py
index 5c89ca0..ce0fb62 100644
--- a/NeoRuntime/Runtime/luxcena_neo/neo_behaviour.py
+++ b/NeoRuntime/Runtime/luxcena_neo/neo_behaviour.py
@@ -61,7 +61,7 @@ class Variables:
def __init__(self, package_path):
self.__vars = {}
- self.__vars_save_file = f"{package_path}/state.json"
+ self.__vars_save_file = "{}/state.json".format(package_path)
self.__saved_variables = {}
self.read_saved_variables()
@@ -109,7 +109,7 @@ class Variables:
def declare(self, variable):
""" Declare a new variable. """
if variable.name in self.__vars:
- raise Exception(f"Variable with name {variable.name} already defined.")
+ raise Exception("Variable with name {} already defined.".format(variable.name))
if variable.name in self.__saved_variables:
variable.value = self.__saved_variables[variable.name]
@@ -164,7 +164,7 @@ class Variable:
return {"name": self.name, "value": self.value, "type": self.var_type}
def __str__(self):
- return f"{self.name}: {self.value}"
+ return "{}: {}".format(self.name, self.value)
def set_save_func(self, save_func):
self.__save_func = save_func
@@ -173,13 +173,13 @@ class ColorVariable(Variable):
def __init__(self, name: str, *color, **kwargs):
if not self.verify_color(*color):
- raise Exception(f"Invalid color {color}")
+ raise Exception("Invalid color {}".format(color))
super().__init__(name, self.extract_interesting(*color), VariableType.COLOR, **kwargs)
@Variable.value.setter
def value(self, *color):
if not self.verify_color(*color):
- print(f"Attempting to set {self.name} to invalid value {color}")
+ print("Attempting to set {} to invalid value {}".format(self.name, color))
return
super(ColorVariable, type(self)).value.fset(self, self.extract_interesting(*color))
@@ -218,9 +218,9 @@ class IntegerVariable(Variable):
if (self.__min <= value <= self.__max):
super(ColorVariable, type(self)).value.fset(self, value)
else:
- print(f"Attempted to set {self.name} to {value} but range is [{self.__min},{self.__max}].")
+ print("Attempted to set {} to {} but range is [{},{}].".format(self.name, value, self.__min, self.__max))
except ValueError:
- print(f"Attempted to set {self.name} to \"{value}\", which is not a valid integer...")
+ print("Attempted to set {} to \"{}\", which is not a valid integer...".format(self.name, value))
def to_dict(self):
return {"name": self.name, "value": self.value, "type": self.var_type, "min": self.__min, "max": self.__max}
@@ -240,9 +240,9 @@ class FloatVariable(Variable):
if (self.__min <= value <= self.__max):
super(ColorVariable, type(self)).value.fset(self, value)
else:
- print(f"Attempted to set {self.name} to {value} but range is [{self.__min},{self.__max}].")
+ print("Attempted to set {} to {} but range is [{},{}].".format(self.name, value, self.__min, self.__max))
except ValueError:
- print(f"Attempted to set {self.name} to \"{value}\", which is not a valid float...")
+ print("Attempted to set {} to \"{}\", which is not a valid float...".format(self.name, self.value))
def __str__(self):
return round(self.value, 2)
@@ -262,4 +262,4 @@ class BooleanVariable(Variable):
try:
value = bool(value)
except:
- print(f"Attempted to set {self.name} to \"{value}\", which is not a valid bool...")
+ print("Attempted to set {} to \"{}\", which is not a valid bool...".format(self.name, value))
diff --git a/NeoRuntime/Runtime/luxcena_neo/strip.py b/NeoRuntime/Runtime/luxcena_neo/strip.py
index bfe2bbc..32380da 100644
--- a/NeoRuntime/Runtime/luxcena_neo/strip.py
+++ b/NeoRuntime/Runtime/luxcena_neo/strip.py
@@ -1,6 +1,6 @@
import json
from os import path
-from .neopixel import *
+import rpi_ws281x as ws
from .matrix import Matrix, get_segment_range
from .power_calc import calcCurrent
@@ -10,11 +10,11 @@ class Strip:
def __init__(self, strip_conf):
self.SEGMENTS = strip_conf["segments"]
- self.LED_FREQ_HZ = strip_conf["led_freq_hz"] # LED signal frequency in hertz (usually 800khz)
- self.LED_CHANNEL = strip_conf["led_channel"] # Set to '1' for GPIOs 13, 19, 41, 45, 53
+ self.LED_FREQ_HZ = int(strip_conf["led_freq_hz"]) # LED signal frequency in hertz (usually 800khz)
+ self.LED_CHANNEL = int(strip_conf["led_channel"]) # Set to '1' for GPIOs 13, 19, 41, 45, 53
self.LED_INVERT = strip_conf["led_invert"] # True to invert the signal, (when using NPN transistor level shift)
- self.LED_PIN = strip_conf["led_pin"] # 18 uses PWM, 10 uses SPI /dev/spidev0.0
- self.LED_DMA = strip_conf["led_dma"] # DMA channel for generating the signal, on the newer ones, try 10
+ self.LED_PIN = int(strip_conf["led_pin"]) # 18 uses PWM, 10 uses SPI /dev/spidev0.0
+ self.LED_DMA = int(strip_conf["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
if ("color_calibration" in strip_conf) and (strip_conf["color_calibration"] != ""):
@@ -26,15 +26,16 @@ class Strip:
self.COLORSTATE = [0 for x in range(self.LED_COUNT)]
self.LED_BRIGHTNESS = 255
-
- self.strip = Adafruit_NeoPixel(
+
+ self.strip = ws.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.LED_CHANNEL,
+ strip_type=ws.WS2812_STRIP
)
self.strip.begin()
@@ -86,15 +87,17 @@ class Strip:
self.__power_on = value
if (self.power_on):
self.__actual_brightness = self.__brightness
- # self.strip.setBrightness(self.__brightness)
+ self.strip.setBrightness(self.__brightness)
+ self.strip.show()
else:
self.__actual_brightness = 0
- # self.strip.setBrightness(0)
+ self.strip.setBrightness(0)
+ self.strip.show()
self.save_globvars()
@property
def brightness(self):
- # return self.strip.getBrightness()
+ #return self.strip.getBrightness()
return self.__actual_brightness
@brightness.setter
@@ -103,10 +106,11 @@ class Strip:
self.__brightness = value
if (self.power_on):
self.__actual_brightness = value
- # self.strip.setBrightness(value)
+ self.strip.setBrightness(value)
+ self.strip.show()
self.save_globvars()
else:
- raise Exception(f"Value ({value}) outside allowed range (0-255)")
+ raise Exception("Value ({}) outside allowed range (0-255)".format(value))
def show(self):
"""Update the display with the data from the LED buffer."""
@@ -118,7 +122,7 @@ class Strip:
"""
c = detect_format_convert_color(*color)
self.TMPCOLORSTATE[n] = c
- # self.strip.setPixelColor(n, )
+ self.strip.setPixelColor(n, c)
def set_pixel_color_XY(self, x, y, *color):
"""Set LED at position n to the provided 24-bit color value (in RGB order).
@@ -161,7 +165,7 @@ def color_from_hex(hex_color: str):
value = hex_color.lstrip('#')
lv = len(value)
rgb = tuple(int(value[i:i+lv//3], 16) for i in range(0, lv, lv//3))
- return color_from_rgb(red=rgb[1], green=rgb[0], blue=rgb[2])
+ return color_from_rgb(red=rgb[0], green=rgb[1], blue=rgb[2])
def detect_format_convert_color(*color) -> int:
@@ -181,4 +185,4 @@ def detect_format_convert_color(*color) -> int:
return color[0]
if (len(color) == 3):
return color_from_rgb(*color)
- raise ValueError("Invalid parameters provided, check documentation.") \ No newline at end of file
+ raise ValueError("Invalid parameters provided, check documentation.")