diff --git a/main.lua b/main.lua index 29fc813..2c0f00c 100644 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/simulation/config.lua b/simulation/config.lua index 7c38a41..bb7c61c 100644 --- a/simulation/config.lua +++ b/simulation/config.lua @@ -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" diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index 1c4cff9..147a20e 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -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", ""); diff --git a/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java b/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java index c9e6250..a7b5660 100644 --- a/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java +++ b/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java @@ -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); } diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266GPIO.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266GPIO.java new file mode 100644 index 0000000..5212d00 --- /dev/null +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266GPIO.java @@ -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
+ * creator: ollo
+ * project: ESP8266GPIO Emulation
+ * $Id: $
+ * @author ollo
+ */ +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); + } + } +}