diff --git a/simulation/src/de/c3ma/ollo/LuaSimulation.java b/simulation/src/de/c3ma/ollo/LuaSimulation.java index 5d3023d..7c1223d 100644 --- a/simulation/src/de/c3ma/ollo/LuaSimulation.java +++ b/simulation/src/de/c3ma/ollo/LuaSimulation.java @@ -11,5 +11,7 @@ public interface LuaSimulation { public void rebootTriggered(); - public void setSimulationTime(long timeInMillis); + public void setSimulationTime(long timeInMillis); + + public void setADC(int value); } diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index e88976c..388d3f0 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -11,6 +11,7 @@ import org.luaj.vm2.LuaValue; import org.luaj.vm2.lib.jse.JsePlatform; import de.c3ma.ollo.mockup.DoFileFunction; +import de.c3ma.ollo.mockup.ESP8266Adc; import de.c3ma.ollo.mockup.ESP8266File; import de.c3ma.ollo.mockup.ESP8266Net; import de.c3ma.ollo.mockup.ESP8266Node; @@ -36,6 +37,7 @@ public class WS2812Simulation implements LuaSimulation { private ESP8266Node espNode = new ESP8266Node(this); private DoFileFunction doFile = new DoFileFunction(globals); private ESP8266Ws2812 ws2812 = new ESP8266Ws2812(); + private ESP8266Adc adc = new ESP8266Adc(); private String scriptName; public WS2812Simulation(File sourceFolder) { @@ -44,6 +46,7 @@ public class WS2812Simulation implements LuaSimulation { globals.load(espTmr); globals.load(espFile); globals.load(espNode); + globals.load(adc); globals.load(new ESP8266Wifi()); globals.load(new ESP8266Net()); globals.load(new ESP8266Time()); @@ -177,4 +180,9 @@ public class WS2812Simulation implements LuaSimulation { public void setSimulationTime(long timeInMillis) { ESP8266Time.setOverwrittenTime(timeInMillis); } + + @Override + public void setADC(int value) { + adc.setADC(value); + } } diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java new file mode 100644 index 0000000..4e8b45f --- /dev/null +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java @@ -0,0 +1,47 @@ +package de.c3ma.ollo.mockup; + +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.TwoArgFunction; +import org.luaj.vm2.lib.VarArgFunction; + +/** + * created at 24.04.2019 - 21:12:03
+ * creator: ollo
+ * project: WS2812Emulation
+ * $Id: $
+ * @author ollo
+ */ +public class ESP8266Adc extends TwoArgFunction { + + private int mAdc = 0; + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + env.checkglobals(); + final LuaTable adc = new LuaTable(); + adc.set("read", new Read(this)); + env.set("adc", adc); + env.get("package").get("loaded").set("adc", adc); + return adc; + } + + private class Read extends VarArgFunction { + + private ESP8266Adc adc; + + public Read(ESP8266Adc a) { + this.adc = a; + } + + public Varargs invoke(Varargs varargs) { + return LuaValue.valueOf(this.adc.mAdc); + } + } + + public void setADC(int newValue) { + this.mAdc = newValue; + System.out.println("[ADC] updated to " + this.mAdc); + } +} diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java index f836c66..f59fa4b 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java +++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java @@ -122,8 +122,7 @@ public class WS2812Layout extends JFrame { @Override public void stateChanged(ChangeEvent e) { - // TODO Auto-generated method stub - + nodemcuSimu.setADC(adc.getValue()); } });