aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2021-10-10 23:27:32 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2021-10-10 23:27:32 +0200
commit76cd8292c5b80749ece1ab6558f3ed410a618f0d (patch)
treeaa5daeead7a51355b6e878d71d7be7d7800e7823
parent72ad29efeb4709572e789a57aa94d00a0eaeb97d (diff)
downloadLuxcena-Neo-76cd8292c5b80749ece1ab6558f3ed410a618f0d.tar.gz
Luxcena-Neo-76cd8292c5b80749ece1ab6558f3ed410a618f0d.zip
:hammer: Update some of the builtin scripts
-rw-r--r--NeoRuntime/Runtime/luxcena_neo/strip.py14
-rw-r--r--NeoRuntime/builtin/static/script.py36
-rw-r--r--NeoRuntime/builtin/strandtest/script.py2
-rw-r--r--app.js21
4 files changed, 31 insertions, 42 deletions
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);