Start simulation of _diet-files

This commit is contained in:
Ollo 2022-12-09 21:26:11 +01:00
parent bba21e562b
commit acda0ded1c
2 changed files with 22 additions and 3 deletions

View File

@ -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()

View File

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