aboutsummaryrefslogtreecommitdiff
path: root/NeoRuntime
diff options
context:
space:
mode:
Diffstat (limited to 'NeoRuntime')
-rw-r--r--NeoRuntime/Runtime/neo_runtime.py8
-rw-r--r--NeoRuntime/builtin/fade/script.py18
2 files changed, 16 insertions, 10 deletions
diff --git a/NeoRuntime/Runtime/neo_runtime.py b/NeoRuntime/Runtime/neo_runtime.py
index 3057f3c..caa367e 100644
--- a/NeoRuntime/Runtime/neo_runtime.py
+++ b/NeoRuntime/Runtime/neo_runtime.py
@@ -69,7 +69,7 @@ class NeoRuntime:
self.__module_th = exec_module(self.__module_loop)
# This will run in this thread.
- print("> Starting to listen on stdin")
+ print("> Starting IPC socket server")
self.__s = None
try:
self.__bind_socket()
@@ -81,6 +81,7 @@ class NeoRuntime:
finally:
self.__close_socket()
+
def __bind_socket(self):
if path.exists(self.__socket_file):
remove(self.__socket_file)
@@ -89,6 +90,7 @@ class NeoRuntime:
self.__s.bind(self.__socket_file)
self.__s.listen(1)
+
def __socket_listener(self):
self.__s_clients = []
last_send = time.perf_counter()
@@ -118,7 +120,7 @@ class NeoRuntime:
last_send = time.perf_counter()
if self.__send_strip_buffer:
- time.sleep(0.001)
+ time.sleep(0.05)
buffer = [2]
for p in self.__strip.COLORSTATE:
buffer.append((p & 0x00FF0000) >> 16)
@@ -153,6 +155,7 @@ class NeoRuntime:
except Exception as e:
traceback.print_exc()
+
def __close_socket(self):
if (self.__s is None): return
r, w, e = select.select([self.__s, *self.__s_clients], self.__s_clients, [], 0)
@@ -166,7 +169,6 @@ class NeoRuntime:
self.__s.close()
-
def __execute_command(self, command):
"""
command should be of type bytes
diff --git a/NeoRuntime/builtin/fade/script.py b/NeoRuntime/builtin/fade/script.py
index 8fe902a..e7e7481 100644
--- a/NeoRuntime/builtin/fade/script.py
+++ b/NeoRuntime/builtin/fade/script.py
@@ -1,4 +1,5 @@
-from luxcena_neo import NeoBehaviour, IntegerVariable
+from luxcena_neo import NeoBehaviour, FloatVariable
+from time import perf_counter
def wheel(pos):
"""Generate rainbow colors across 0-255 positions."""
@@ -14,15 +15,18 @@ def wheel(pos):
class Main(NeoBehaviour):
def declare_variables(self):
- self.declare(IntegerVariable("speed", 2, min_val=1, max_val=50))
+ self.declare(FloatVariable("speed", 1, min_val=1, max_val=6, step=0.1))
def on_start(self):
""" Execute when mode is selected. """
self.i = 0
+ self.last_inst = perf_counter()
def each_tick(self):
- self.i += self.var.speed
- if self.i > 255: self.i = 0
- for i in range(strip.num_pixels()):
- strip.set_pixel_color(i, wheel(self.i))
- strip.show()
+ if (perf_counter() - self.last_inst) > (6-self.var.speed):
+ self.i += 1
+ if self.i > 255: self.i = 0
+ for i in range(strip.num_pixels()):
+ strip.set_pixel_color(i, wheel(self.i))
+ strip.show()
+ self.last_inst = perf_counter()