From 41179c4afdc9cab849b9b434d2a6a31eccaffad7 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 26 Mar 2021 21:54:42 +0100 Subject: [PATCH] set buffer with red, green and blue --- .../src/de/c3ma/ollo/mockup/ESP8266Mqtt.java | 15 ++++++++++ .../de/c3ma/ollo/mockup/ESP8266Ws2812.java | 28 +++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java index 65149cb..758ab76 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java @@ -53,6 +53,11 @@ public class ESP8266Mqtt extends TwoArgFunction { final LuaTable onMqtt = new LuaTable(); if (varargs.narg() == 2) { System.out.println("[MQTT] On " + this.client); + } else { + for(int i=0; i <= varargs.narg(); i++) { + System.err.println("[MQTT] On ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); + } + return LuaValue.NIL; } return onMqtt; } @@ -64,6 +69,11 @@ public class ESP8266Mqtt extends TwoArgFunction { final LuaTable onMqtt = new LuaTable(); if (varargs.narg() == 2) { System.out.println("[MQTT] publish "); + } else { + for(int i=0; i <= varargs.narg(); i++) { + System.err.println("[MQTT] publish ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); + } + return LuaValue.NIL; } return onMqtt; } @@ -75,6 +85,11 @@ public class ESP8266Mqtt extends TwoArgFunction { final LuaTable onMqtt = new LuaTable(); if (varargs.narg() == 2) { System.out.println("[MQTT] subscribe "); + } else { + for(int i=0; i <= varargs.narg(); i++) { + System.err.println("[MQTT] subscribe ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); + } + return LuaValue.NIL; } return onMqtt; } diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java index 86a811b..69a4d75 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import javax.swing.SwingUtilities; -import org.luaj.vm2.LuaNil; import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; @@ -17,9 +16,7 @@ import org.luaj.vm2.lib.VarArgFunction; import org.luaj.vm2.lib.ZeroArgFunction; import de.c3ma.ollo.LuaSimulation; -import de.c3ma.ollo.LuaThreadTmr; import de.c3ma.ollo.mockup.ui.WS2812Layout; -import de.c3ma.ollo.mockup.ui.WS2812Layout.Element; /** * created at 28.12.2017 - 23:34:04
@@ -210,15 +207,30 @@ public class ESP8266Ws2812 extends TwoArgFunction { } }); return LuaValue.valueOf(true); - } else { -// for(int i=0; i <= varargs.narg(); i++) { -// System.err.println("[WS2812] write ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); -// } - + } else { System.err.println("[WS2812] set with " + varargs.narg() + " arguments at index="+ index + " and "+ length + " charactes not matching"); return LuaValue.NIL; } + } else if (varargs.narg() == 5) { + final int index = varargs.arg(2).toint(); + final int green = varargs.arg(3).toint(); + final int red = varargs.arg(4).toint(); + final int blue = varargs.arg(5).toint(); + // update buffer + ledList.set(index - 1, new Color(red, green, blue)); + + // update GUI + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + ESP8266Ws2812.layout.updateLED(index - 1, red, green, blue); + } + }); + return LuaValue.valueOf(true); } else { + for(int i=0; i <= varargs.narg(); i++) { + System.err.println("[WS2812] write ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); + } System.err.println("[WS2812] set with " + varargs.narg() + " arguments undefined."); return LuaValue.NIL; }