The time is also manipulated with the speedfactor
This commit is contained in:
parent
4522e40d52
commit
fc81ac63f7
@ -1,18 +1,12 @@
|
|||||||
package de.c3ma.ollo.mockup;
|
package de.c3ma.ollo.mockup;
|
||||||
|
|
||||||
import org.luaj.vm2.Globals;
|
|
||||||
import org.luaj.vm2.LuaFunction;
|
import org.luaj.vm2.LuaFunction;
|
||||||
import org.luaj.vm2.LuaTable;
|
import org.luaj.vm2.LuaTable;
|
||||||
import org.luaj.vm2.LuaValue;
|
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.ThreeArgFunction;
|
||||||
import org.luaj.vm2.lib.TwoArgFunction;
|
import org.luaj.vm2.lib.TwoArgFunction;
|
||||||
import org.luaj.vm2.lib.VarArgFunction;
|
|
||||||
import org.luaj.vm2.lib.ZeroArgFunction;
|
import org.luaj.vm2.lib.ZeroArgFunction;
|
||||||
|
|
||||||
import de.c3ma.ollo.LuaThreadTmr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* created at 29.12.2017 - 00:07:22<br />
|
* created at 29.12.2017 - 00:07:22<br />
|
||||||
* creator: ollo<br />
|
* creator: ollo<br />
|
||||||
@ -27,6 +21,8 @@ import de.c3ma.ollo.LuaThreadTmr;
|
|||||||
*/
|
*/
|
||||||
public class ESP8266Time extends TwoArgFunction {
|
public class ESP8266Time extends TwoArgFunction {
|
||||||
|
|
||||||
|
private static long gSimulationStartTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LuaValue call(LuaValue modname, LuaValue env) {
|
public LuaValue call(LuaValue modname, LuaValue env) {
|
||||||
env.checkglobals();
|
env.checkglobals();
|
||||||
@ -42,6 +38,23 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
return sntp;
|
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 {
|
private class SyncFunction extends ThreeArgFunction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,12 +62,11 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
String serverName = server.checkjstring();
|
String serverName = server.checkjstring();
|
||||||
LuaFunction cb = callbackSuccess.checkfunction();
|
LuaFunction cb = callbackSuccess.checkfunction();
|
||||||
System.out.println("[SNTP] sync " + serverName);
|
System.out.println("[SNTP] sync " + serverName);
|
||||||
|
|
||||||
/*FIXME also make it possible to simulate the time */
|
/*FIXME also make it possible to simulate the time */
|
||||||
int seconds = (int) (System.currentTimeMillis() / 1000);
|
long time = generateCurrenttime();
|
||||||
int useconds = (int) (System.currentTimeMillis() % 1000);
|
int seconds = (int) (time / 1000);
|
||||||
|
int useconds = (int) (time % 1000);
|
||||||
cb.call(LuaValue.valueOf(seconds), LuaValue.valueOf(useconds), LuaValue.valueOf(serverName));
|
cb.call(LuaValue.valueOf(seconds), LuaValue.valueOf(useconds), LuaValue.valueOf(serverName));
|
||||||
|
|
||||||
return LuaValue.valueOf(true);
|
return LuaValue.valueOf(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +76,11 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LuaValue call() {
|
public LuaValue call() {
|
||||||
LuaValue[] v = new LuaValue[2];
|
LuaValue[] v = new LuaValue[2];
|
||||||
/*FIXME also make it possible to simulate the time */
|
/*FIXME also make it possible to simulate the time */
|
||||||
int seconds = (int) (System.currentTimeMillis() / 1000);
|
long time = generateCurrenttime();
|
||||||
int useconds = (int) (System.currentTimeMillis() % 1000);
|
int seconds = (int) (time / 1000);
|
||||||
|
int useconds = (int) (time % 1000);
|
||||||
v[0] = LuaValue.valueOf(seconds);
|
v[0] = LuaValue.valueOf(seconds);
|
||||||
v[1] = LuaValue.valueOf(useconds);
|
v[1] = LuaValue.valueOf(useconds);
|
||||||
return LuaValue.varargsOf(v).arg1();
|
return LuaValue.varargsOf(v).arg1();
|
||||||
|
@ -82,6 +82,7 @@ public class WS2812Layout extends JFrame {
|
|||||||
contentPane.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 2));
|
contentPane.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 2));
|
||||||
|
|
||||||
JPanel ledPanel = new JPanel();
|
JPanel ledPanel = new JPanel();
|
||||||
|
ledPanel.setBackground(Color.BLACK);
|
||||||
ledPanel.setLayout(new GridLayout(this.mRow, this.mColumn, 10, 10));
|
ledPanel.setLayout(new GridLayout(this.mRow, this.mColumn, 10, 10));
|
||||||
for (int i = 0; i < this.mRow; i++) {
|
for (int i = 0; i < this.mRow; i++) {
|
||||||
for (int j = 0; j < this.mColumn; j++) {
|
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) {
|
public void setColor(int red, int green, int blue) {
|
||||||
this.setForeground(new Color(red, green, blue));
|
this.setForeground(new Color(red, green, blue));
|
||||||
// FIXME changing the color is not working
|
|
||||||
this.repaint();
|
this.repaint();
|
||||||
System.out.println(this.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user