Added ADC stimulation into the simulation
This commit is contained in:
parent
417c93583d
commit
aeb5dab9fd
@ -12,4 +12,6 @@ public interface LuaSimulation {
|
|||||||
public void rebootTriggered();
|
public void rebootTriggered();
|
||||||
|
|
||||||
public void setSimulationTime(long timeInMillis);
|
public void setSimulationTime(long timeInMillis);
|
||||||
|
|
||||||
|
public void setADC(int value);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.luaj.vm2.LuaValue;
|
|||||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
import org.luaj.vm2.lib.jse.JsePlatform;
|
||||||
|
|
||||||
import de.c3ma.ollo.mockup.DoFileFunction;
|
import de.c3ma.ollo.mockup.DoFileFunction;
|
||||||
|
import de.c3ma.ollo.mockup.ESP8266Adc;
|
||||||
import de.c3ma.ollo.mockup.ESP8266File;
|
import de.c3ma.ollo.mockup.ESP8266File;
|
||||||
import de.c3ma.ollo.mockup.ESP8266Net;
|
import de.c3ma.ollo.mockup.ESP8266Net;
|
||||||
import de.c3ma.ollo.mockup.ESP8266Node;
|
import de.c3ma.ollo.mockup.ESP8266Node;
|
||||||
@ -36,6 +37,7 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
private ESP8266Node espNode = new ESP8266Node(this);
|
private ESP8266Node espNode = new ESP8266Node(this);
|
||||||
private DoFileFunction doFile = new DoFileFunction(globals);
|
private DoFileFunction doFile = new DoFileFunction(globals);
|
||||||
private ESP8266Ws2812 ws2812 = new ESP8266Ws2812();
|
private ESP8266Ws2812 ws2812 = new ESP8266Ws2812();
|
||||||
|
private ESP8266Adc adc = new ESP8266Adc();
|
||||||
private String scriptName;
|
private String scriptName;
|
||||||
|
|
||||||
public WS2812Simulation(File sourceFolder) {
|
public WS2812Simulation(File sourceFolder) {
|
||||||
@ -44,6 +46,7 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
globals.load(espTmr);
|
globals.load(espTmr);
|
||||||
globals.load(espFile);
|
globals.load(espFile);
|
||||||
globals.load(espNode);
|
globals.load(espNode);
|
||||||
|
globals.load(adc);
|
||||||
globals.load(new ESP8266Wifi());
|
globals.load(new ESP8266Wifi());
|
||||||
globals.load(new ESP8266Net());
|
globals.load(new ESP8266Net());
|
||||||
globals.load(new ESP8266Time());
|
globals.load(new ESP8266Time());
|
||||||
@ -177,4 +180,9 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
public void setSimulationTime(long timeInMillis) {
|
public void setSimulationTime(long timeInMillis) {
|
||||||
ESP8266Time.setOverwrittenTime(timeInMillis);
|
ESP8266Time.setOverwrittenTime(timeInMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setADC(int value) {
|
||||||
|
adc.setADC(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
47
simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java
Normal file
47
simulation/src/de/c3ma/ollo/mockup/ESP8266Adc.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -122,8 +122,7 @@ public class WS2812Layout extends JFrame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
// TODO Auto-generated method stub
|
nodemcuSimu.setADC(adc.getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user