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 --- NeoRuntime/builtin/static/script.py | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 NeoRuntime/builtin/static/script.py (limited to 'NeoRuntime/builtin/static/script.py') diff --git a/NeoRuntime/builtin/static/script.py b/NeoRuntime/builtin/static/script.py new file mode 100644 index 0000000..0f07304 --- /dev/null +++ b/NeoRuntime/builtin/static/script.py @@ -0,0 +1,38 @@ +from luxcena_neo import NeoBehaviour, VariableType, utils +import time + +class Main(NeoBehaviour): + + def declare_variables(self): + self.vars.declare("color", "#fafafa", VariableType.COLOR, self.set_color) + + def on_start(self): + print(f"Script started, color: {self.vars.color}") + self.set_color(self.vars.color) + strip.power_on = True + # self.current_color = self.vars.color + + def set_color(self, value): + print(f"Color var changed: {value}") + # transition_color(self.current_color, value, 1) + +def lerp(a, b, u): + return (1 - u) * a + u * b + +def transition_color(start_color, end_color, duration): + start_color = utils.hex_to_rgb(start_color) + end_color = utils.hex_to_rgb(end_color) + interval = 10 + steps = duration / interval + step_u = 1.0 / steps + u = 0 + + while u < 1: + r = round(lerp(start_color[0], end_color[0], u)) + g = round(lerp(start_color[1], end_color[1], u)) + b = round(lerp(start_color[2], end_color[2], u)) + for i in len(strip.LED_COUNT): + strip.set_pixel_color(i, (r, g, b)) + strip.show() + + time.sleep(interval / 100) \ No newline at end of file -- cgit v1.2.3 From f911008c589efd6fc43b8a81c9208fd07f04c586 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Wed, 6 Oct 2021 17:30:49 +0200 Subject: :construction: Update after changes --- NeoRuntime/builtin/static/script.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'NeoRuntime/builtin/static/script.py') diff --git a/NeoRuntime/builtin/static/script.py b/NeoRuntime/builtin/static/script.py index 0f07304..505ab67 100644 --- a/NeoRuntime/builtin/static/script.py +++ b/NeoRuntime/builtin/static/script.py @@ -1,16 +1,17 @@ -from luxcena_neo import NeoBehaviour, VariableType, utils +from luxcena_neo import NeoBehaviour, ColorVariable, utils import time class Main(NeoBehaviour): def declare_variables(self): - self.vars.declare("color", "#fafafa", VariableType.COLOR, self.set_color) + self.declare(ColorVariable("color", "#fafafa", on_change=self.set_color)) + self.declare(ColorVariable("color2", "#fafafa", on_change=self.set_color)) def on_start(self): - print(f"Script started, color: {self.vars.color}") - self.set_color(self.vars.color) + print(f"Script started, color: {self.var.color}") + self.set_color(self.var.color) strip.power_on = True - # self.current_color = self.vars.color + self.current_color = self.var.color def set_color(self, value): print(f"Color var changed: {value}") -- cgit v1.2.3 From 76cd8292c5b80749ece1ab6558f3ed410a618f0d Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Sun, 10 Oct 2021 23:27:32 +0200 Subject: :hammer: Update some of the builtin scripts --- NeoRuntime/Runtime/luxcena_neo/strip.py | 14 ++++++++----- NeoRuntime/builtin/static/script.py | 36 +++++++-------------------------- NeoRuntime/builtin/strandtest/script.py | 2 +- app.js | 21 ++++++++++++------- 4 files changed, 31 insertions(+), 42 deletions(-) (limited to 'NeoRuntime/builtin/static/script.py') diff --git a/NeoRuntime/Runtime/luxcena_neo/strip.py b/NeoRuntime/Runtime/luxcena_neo/strip.py index 32380da..e8bf476 100644 --- a/NeoRuntime/Runtime/luxcena_neo/strip.py +++ b/NeoRuntime/Runtime/luxcena_neo/strip.py @@ -1,6 +1,10 @@ import json from os import path +<<<<<<< Updated upstream import rpi_ws281x as ws +======= +# from .neopixel import * +>>>>>>> Stashed changes from .matrix import Matrix, get_segment_range from .power_calc import calcCurrent @@ -20,7 +24,7 @@ class Strip: if ("color_calibration" in strip_conf) and (strip_conf["color_calibration"] != ""): self.COLOR_CALIBRATION = strip_conf["led_calibration"] else: - self.COLOR_CALIBRATION = [(1,1,1) for x in range(self.LED_COUNT)] + self.COLOR_CALIBRATION = [0xffffffff for x in range(self.LED_COUNT)] self.TMPCOLORSTATE = [0 for x in range(self.LED_COUNT)] self.COLORSTATE = [0 for x in range(self.LED_COUNT)] @@ -70,14 +74,14 @@ class Strip: except: print("Could not load saved globvars...") - + def save_globvars(self): with open(self.__globvars_path, "w") as f: f.write(json.dumps({ "power_on": self.__power_on, "brightness": self.__brightness })) - + @property def power_on(self): return self.__power_on @@ -115,7 +119,7 @@ class Strip: def show(self): """Update the display with the data from the LED buffer.""" self.COLORSTATE = self.TMPCOLORSTATE - self.strip.show() + # self.strip.show() def set_pixel_color(self, n, *color): """Set LED at position n to the provided 24-bit color value (in RGB order). @@ -152,7 +156,7 @@ class Strip: def color_from_rgb(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. diff --git a/NeoRuntime/builtin/static/script.py b/NeoRuntime/builtin/static/script.py index 505ab67..8916106 100644 --- a/NeoRuntime/builtin/static/script.py +++ b/NeoRuntime/builtin/static/script.py @@ -1,39 +1,17 @@ from luxcena_neo import NeoBehaviour, ColorVariable, utils -import time class Main(NeoBehaviour): - + def declare_variables(self): self.declare(ColorVariable("color", "#fafafa", on_change=self.set_color)) - self.declare(ColorVariable("color2", "#fafafa", on_change=self.set_color)) def on_start(self): - print(f"Script started, color: {self.var.color}") - self.set_color(self.var.color) - strip.power_on = True - self.current_color = self.var.color - + print("Script started, color: {}".format(self.var.color)) + def set_color(self, value): - print(f"Color var changed: {value}") - # transition_color(self.current_color, value, 1) - -def lerp(a, b, u): - return (1 - u) * a + u * b - -def transition_color(start_color, end_color, duration): - start_color = utils.hex_to_rgb(start_color) - end_color = utils.hex_to_rgb(end_color) - interval = 10 - steps = duration / interval - step_u = 1.0 / steps - u = 0 - - while u < 1: - r = round(lerp(start_color[0], end_color[0], u)) - g = round(lerp(start_color[1], end_color[1], u)) - b = round(lerp(start_color[2], end_color[2], u)) - for i in len(strip.LED_COUNT): - strip.set_pixel_color(i, (r, g, b)) + print("Color var changed: {}".format(value)) + print(utils.detect_format_convert_color(value)) + for i in range(strip.LED_COUNT): + strip.set_pixel_color(i, value) strip.show() - time.sleep(interval / 100) \ No newline at end of file diff --git a/NeoRuntime/builtin/strandtest/script.py b/NeoRuntime/builtin/strandtest/script.py index f7d013a..6d263ab 100644 --- a/NeoRuntime/builtin/strandtest/script.py +++ b/NeoRuntime/builtin/strandtest/script.py @@ -60,7 +60,7 @@ def theaterChaseRainbow(wait_ms=50): class Main(NeoBehaviour): - def onStart(self): + def on_start(self): # Do an endless loop with some default ixel test patterns while True: colorWipe(*(255, 0, 0)) # Red wipe diff --git a/app.js b/app.js index 715108b..044f68a 100644 --- a/app.js +++ b/app.js @@ -78,16 +78,24 @@ function getNetworkAddress() { } return results[Object.keys(results)[0]][0] } +let http = require("http"); function tryBroadcastSelf() { if (neoModules.userData.config.DiscoveryServer.broadcastSelf) { + let address = neoModules.userData.config.DiscoveryServer.address; + let port = 443; + if (address.includes(":")) { + address = address.split(":"); + port = parseInt(address[1]); + address = address[0]; + } const data = JSON.stringify({ address: `https://${getNetworkAddress()}:${neoModules.userData.config.HTTP.port}`, name: neoModules.userData.config.instanceName, widgetaddr: "/#/widget" }) const options = { - hostname: `${neoModules.userData.config.DiscoveryServer.address}`, - port: 443, + hostname: address, + port: port, path: "/HEY", method: "POST", headers: { @@ -95,12 +103,11 @@ function tryBroadcastSelf() { "Content-length": data.length } }; - let req = https.request(options, res => { + let req = http.request(options, res => { if (res.statusCode != 200) { res.on("data", (d) => logger.warning(d.toString())); } else { - res.on("data", (d) => logger.info(d.toString())); - logger.info("Broadcasted self") + // res.on("data", (d) => logger.info(d.toString())); } }); req.on("error", (error) => logger.warning(error.toString())) @@ -108,7 +115,7 @@ function tryBroadcastSelf() { req.end(); } } -// setInterval(tryBroadcastSelf, 30000); -// tryBroadcastSelf(); +setInterval(tryBroadcastSelf, 30000); +tryBroadcastSelf(); // setInterval(() => { logger.notice("I feel FANTASTIC, an I'm still alive. Uptime: " + process.uptime()); }, 600000); -- cgit v1.2.3