diff --git a/init.lua b/init.lua index 64fe3bb..fd5de8d 100644 --- a/init.lua +++ b/init.lua @@ -11,7 +11,7 @@ bootledtimer:register(75, tmr.ALARM_AUTO, function (timer) spaceLeds = math.max(MAXLEDS - (counter1*2), 0) ws2812.write(string.char(16,0,0):rep(counter1) .. string.char(0,0,0):rep(spaceLeds) .. string.char(0,0,8):rep(counter1)) if ((counter1*2) > 114) then - timer:unregister() + bootledtimer:unregister() end end) bootledtimer:start() diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266File.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266File.java index 27ad122..057a729 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266File.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266File.java @@ -1,7 +1,8 @@ package de.c3ma.ollo.mockup; import java.io.File; -import java.util.ArrayList; +import java.io.IOException; +import java.nio.file.Files; import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; @@ -21,6 +22,8 @@ public class ESP8266File extends TwoArgFunction { private File openedFile = null; + private String SHRINKED_FILE_POSTFIX = "_diet"; + @Override public LuaValue call(LuaValue modname, LuaValue env) { env.checkglobals(); @@ -59,9 +62,25 @@ public class ESP8266File extends TwoArgFunction { final String codeFileName = fileName.checkjstring(); final File f = new File( workingDir.getAbsolutePath() + File.separator + codeFileName); - //System.out.println("[FILE] Loading " + codeFileName); + // Check if the file exists as it if (f.exists()) { ESP8266File.this.openedFile = f; + } else { + if (codeFileName.contains(SHRINKED_FILE_POSTFIX)) { + File fShrinked = new File( workingDir.getAbsolutePath() + File.separator + codeFileName.replace(SHRINKED_FILE_POSTFIX, "")); + File fShrinkedLC = new File(fShrinked.getAbsolutePath().replace(".lua", ".lc")); + if (!fShrinkedLC.exists()) { + try { + System.out.println("[FILE] Generate " + codeFileName); + Files.copy(fShrinked.toPath(), f.toPath()); + } catch (IOException e) { + System.err.println("[FILE] Generate " + codeFileName + " failed: " + e.getMessage()); + } + } else { + System.out.println("[FILE] Already found " + fShrinkedLC.getName()); + return LuaValue.valueOf(true); + } + } } return LuaValue.valueOf((f.exists()));