diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java
index e8f5446..16e442c 100644
--- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java
+++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java
@@ -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
* creator: ollo
@@ -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();
diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
index de630b4..bcf22c3 100644
--- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
+++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
@@ -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