The time is also manipulated with the speedfactor

This commit is contained in:
ollo 2018-01-17 21:42:02 +01:00
parent 4522e40d52
commit fc81ac63f7
2 changed files with 27 additions and 15 deletions

View File

@ -1,18 +1,12 @@
package de.c3ma.ollo.mockup;
import org.luaj.vm2.Globals;
import org.luaj.vm2.LuaFunction;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.OneArgFunction;
import org.luaj.vm2.lib.ThreeArgFunction;
import org.luaj.vm2.lib.TwoArgFunction;
import org.luaj.vm2.lib.VarArgFunction;
import org.luaj.vm2.lib.ZeroArgFunction;
import de.c3ma.ollo.LuaThreadTmr;
/**
* created at 29.12.2017 - 00:07:22<br />
* creator: ollo<br />
@ -27,6 +21,8 @@ import de.c3ma.ollo.LuaThreadTmr;
*/
public class ESP8266Time extends TwoArgFunction {
private static long gSimulationStartTime = 0;
@Override
public LuaValue call(LuaValue modname, LuaValue env) {
env.checkglobals();
@ -42,6 +38,23 @@ public class ESP8266Time extends TwoArgFunction {
return sntp;
}
/**
* Generate a time. If there is no speedup, it is simply the current system time.
* Otherwise the time is speedup by the given factor
* @return
*/
private long generateCurrenttime() {
if (gSimulationStartTime == 0) {
gSimulationStartTime = System.currentTimeMillis();
}
long time = System.currentTimeMillis();
if (ESP8266Tmr.gTimingFactor > 1) {
time = gSimulationStartTime + ((time - gSimulationStartTime) * ESP8266Tmr.gTimingFactor);
}
return time;
}
private class SyncFunction extends ThreeArgFunction {
@Override
@ -49,12 +62,11 @@ public class ESP8266Time extends TwoArgFunction {
String serverName = server.checkjstring();
LuaFunction cb = callbackSuccess.checkfunction();
System.out.println("[SNTP] sync " + serverName);
/*FIXME also make it possible to simulate the time */
int seconds = (int) (System.currentTimeMillis() / 1000);
int useconds = (int) (System.currentTimeMillis() % 1000);
long time = generateCurrenttime();
int seconds = (int) (time / 1000);
int useconds = (int) (time % 1000);
cb.call(LuaValue.valueOf(seconds), LuaValue.valueOf(useconds), LuaValue.valueOf(serverName));
return LuaValue.valueOf(true);
}
@ -64,10 +76,11 @@ public class ESP8266Time extends TwoArgFunction {
@Override
public LuaValue call() {
LuaValue[] v = new LuaValue[2];
LuaValue[] v = new LuaValue[2];
/*FIXME also make it possible to simulate the time */
int seconds = (int) (System.currentTimeMillis() / 1000);
int useconds = (int) (System.currentTimeMillis() % 1000);
long time = generateCurrenttime();
int seconds = (int) (time / 1000);
int useconds = (int) (time % 1000);
v[0] = LuaValue.valueOf(seconds);
v[1] = LuaValue.valueOf(useconds);
return LuaValue.varargsOf(v).arg1();

View File

@ -82,6 +82,7 @@ public class WS2812Layout extends JFrame {
contentPane.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 2));
JPanel ledPanel = new JPanel();
ledPanel.setBackground(Color.BLACK);
ledPanel.setLayout(new GridLayout(this.mRow, this.mColumn, 10, 10));
for (int i = 0; i < this.mRow; i++) {
for (int j = 0; j < this.mColumn; j++) {
@ -159,9 +160,7 @@ public class WS2812Layout extends JFrame {
public void setColor(int red, int green, int blue) {
this.setForeground(new Color(red, green, blue));
// FIXME changing the color is not working
this.repaint();
System.out.println(this.toString());
}
@Override