Added ADC stimulation into the simulation

This commit is contained in:
ollo 2019-04-24 21:21:19 +02:00
parent 417c93583d
commit aeb5dab9fd
4 changed files with 59 additions and 3 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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<br />
* creator: ollo<br />
* project: WS2812Emulation<br />
* $Id: $<br />
* @author ollo<br />
*/
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);
}
}

View File

@ -122,8 +122,7 @@ public class WS2812Layout extends JFrame {
@Override
public void stateChanged(ChangeEvent e) {
// TODO Auto-generated method stub
nodemcuSimu.setADC(adc.getValue());
}
});