improved simulation: GPIO added and dofile adapted

This commit is contained in:
ollo 2019-05-08 21:45:58 +02:00
parent a36dc8d033
commit 22afc1e4c4
5 changed files with 61 additions and 9 deletions

View File

@ -1,7 +1,5 @@
-- Main Module
displayword = {}
function startSetupMode()
tmr.stop(0)
tmr.stop(1)
@ -56,12 +54,12 @@ function displayTime()
else
words.briPercent=nil
end
dofile("displayword.lc")
if (displayword ~= nil) then
ledBuf = displayword.generateLEDs(words, color, color1, color2, color3, color4)
dp = dofile("displayword.lc")
if (dp ~= nil) then
ledBuf = dp.generateLEDs(words, color, color1, color2, color3, color4)
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. " char: " .. tostring(displayword.data.drawnCharacters))
end
displayword = nil
dp = nil
if (ledBuf ~= nil) then
--if lines 4 to 6 are inverted due to hardware-fuckup, unfuck it here
if ((inv46 ~= nil) and (inv46 == "on")) then

View File

@ -12,3 +12,4 @@ color4=string.char(tonumber(green2*0.2), 0, 0)
colorBg=string.char(0,0,0) -- black is the default background color
sntpserverhostname="ptbtime1.ptb.de"
timezoneoffset=1
dim="on"

View File

@ -13,6 +13,7 @@ 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.ESP8266GPIO;
import de.c3ma.ollo.mockup.ESP8266Net;
import de.c3ma.ollo.mockup.ESP8266Node;
import de.c3ma.ollo.mockup.ESP8266Time;
@ -46,11 +47,13 @@ public class WS2812Simulation implements LuaSimulation {
globals.load(espTmr);
globals.load(espFile);
globals.load(espNode);
globals.load(new ESP8266GPIO());
globals.load(adc);
globals.load(new ESP8266Wifi());
globals.load(new ESP8266Net());
globals.load(new ESP8266Time());
globals.set("dofile", doFile);
adc.setADC(50);
try {
File tempFile = File.createTempFile("NodemcuSimuFile", "");

View File

@ -26,14 +26,13 @@ public class DoFileFunction extends OneArgFunction {
public LuaValue call(LuaValue luaFilename) {
String filename = luaFilename.checkjstring();
System.out.println("[Nodemcu] dofile " + filename);
//System.out.println("[Nodemcu] dofile " + filename);
File f = new File(workingDir.getAbsolutePath() + File.separator + filename);
if (f.exists()) {
LuaValue chunk = this.globals.loadfile(f.getAbsolutePath());
chunk.call();
return LuaValue.valueOf(true);
return chunk.call();
} else {
return LuaValue.valueOf(false);
}

View File

@ -0,0 +1,51 @@
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 08.05.2019 - 21:33:04<br />
* creator: ollo<br />
* project: ESP8266GPIO Emulation<br />
* $Id: $<br />
* @author ollo<br />
*/
public class ESP8266GPIO extends TwoArgFunction {
@Override
public LuaValue call(LuaValue modname, LuaValue env) {
env.checkglobals();
final LuaTable gpio = new LuaTable();
gpio.set("mode", new Mode());
gpio.set("read", new Read(this));
env.set("gpio", gpio);
env.get("package").get("loaded").set("gpio", gpio);
return gpio;
}
private class Read extends VarArgFunction {
private ESP8266GPIO mGpio = null;
Read(ESP8266GPIO gpio) {
this.mGpio = gpio;
}
public Varargs invoke(Varargs varargs) {
int pin = varargs.toint(0);
//FIXME add here something to simulate a pin pressing
return LuaValue.valueOf((int)1);
}
}
private class Mode extends VarArgFunction {
public Varargs invoke(Varargs varargs) {
System.out.println("[GPIO] mode GPIO" + varargs.toint(0) + "=" + varargs.toint(1));
return LuaValue.valueOf(true);
}
}
}