From 6e53fd0dfd830d6d96206419c530c71fa4b3f4e6 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Thu, 21 Oct 2021 19:28:20 +0200 Subject: :sparkles: Add attempt at the "simulation" --- NeoRuntime/Runtime/luxcena_neo/strip.py | 2 ++ NeoRuntime/Runtime/neo_runtime.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'NeoRuntime') diff --git a/NeoRuntime/Runtime/luxcena_neo/strip.py b/NeoRuntime/Runtime/luxcena_neo/strip.py index bc2e2be..9a12969 100644 --- a/NeoRuntime/Runtime/luxcena_neo/strip.py +++ b/NeoRuntime/Runtime/luxcena_neo/strip.py @@ -119,6 +119,7 @@ class Strip: def set_pixel_color(self, n, *color): """Set LED at position n to the provided 24-bit color value (in RGB order). """ + if n >= self.LED_COUNT: return c = detect_format_convert_color(*color) self.TMPCOLORSTATE[n] = c self.strip.setPixelColor(n, c) @@ -132,6 +133,7 @@ class Strip: """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).""" + if segment >= len(self.SEGMENTS): return for n in get_segment_range(self.SEGMENTS, segment): self.set_pixel_color(n, *color) diff --git a/NeoRuntime/Runtime/neo_runtime.py b/NeoRuntime/Runtime/neo_runtime.py index b028530..3057f3c 100644 --- a/NeoRuntime/Runtime/neo_runtime.py +++ b/NeoRuntime/Runtime/neo_runtime.py @@ -116,11 +116,32 @@ class NeoRuntime: ws.close() last_send = time.perf_counter() + + if self.__send_strip_buffer: + time.sleep(0.001) + buffer = [2] + for p in self.__strip.COLORSTATE: + buffer.append((p & 0x00FF0000) >> 16) + buffer.append((p & 0x0000FF00) >> 8) + buffer.append((p & 0x000000FF)) + buffer = bytes(buffer) + for ws in w: + try: + ws.send(buffer) + except BrokenPipeError: + self.__s_clients.remove(ws) + ws.close() + time.sleep(0.001) for rs in r: if rs is self.__s: c, a = self.__s.accept() self.__s_clients.append(c) + try: + buf = bytes([3]) + bytes(json.dumps(self.__strip.pixelMatrix.matrix), "ascii") + c.send(buf) + except Exception as e: + print(e) else: data = rs.recv(128) if not data: -- cgit v1.2.3