From 93504e3d9612c3b14d1358456f45942105288844 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sat, 20 Mar 2021 16:19:28 +0100 Subject: [PATCH] Fix reading color from buffer --- simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java | 6 +++--- simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java index e386ef2..394f1c2 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java @@ -196,11 +196,11 @@ public class ESP8266Ws2812 extends TwoArgFunction { } } - private class bufferRead extends OneArgFunction { + private class bufferRead extends VarArgFunction { @Override - public LuaValue call(LuaValue arg) { - final int offset = arg.toint(); + public Varargs invoke(Varargs varargs) { + final int offset = varargs.arg(2).toint(); if (ESP8266Ws2812.layout != null) { Element e = ESP8266Ws2812.layout.getLED(offset - 1); diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java index c43fd4c..d99e3b9 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java +++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java @@ -331,6 +331,11 @@ public class WS2812Layout extends JFrame { if (i % 2 == 1) { j = (mColumn-1) - j; } + if (i < 0 || j < 0) { + System.err.println("LED index" + index + " results in " + i + "x" + j + " coordinate"); + return null; + } + if ((i < mElements.length) && (j < mElements[i].length) && (mElements[i][j] != null)) { return mElements[i][j]; } else {