The time can be set within the GUI
This commit is contained in:
parent
28b7bbe04a
commit
ca47018a32
@ -10,4 +10,6 @@ package de.c3ma.ollo;
|
|||||||
public interface LuaSimulation {
|
public interface LuaSimulation {
|
||||||
|
|
||||||
public void rebootTriggered();
|
public void rebootTriggered();
|
||||||
|
|
||||||
|
public void setSimulationTime(long timeInMillis);
|
||||||
}
|
}
|
||||||
|
@ -165,4 +165,9 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
throw new RuntimeException("Copy into temporary folder failed; script not available");
|
throw new RuntimeException("Copy into temporary folder failed; script not available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSimulationTime(long timeInMillis) {
|
||||||
|
ESP8266Time.setOverwrittenTime(timeInMillis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
|
|
||||||
private static long gSimulationStartTime = 0;
|
private static long gSimulationStartTime = 0;
|
||||||
|
|
||||||
|
private static long gOverwrittenTime = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LuaValue call(LuaValue modname, LuaValue env) {
|
public LuaValue call(LuaValue modname, LuaValue env) {
|
||||||
env.checkglobals();
|
env.checkglobals();
|
||||||
@ -48,11 +50,16 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
gSimulationStartTime = System.currentTimeMillis();
|
gSimulationStartTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gOverwrittenTime == 0) {
|
||||||
|
/* Time simulation is disabled -> calculate something according to the speedup factor */
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (ESP8266Tmr.gTimingFactor > 1) {
|
if (ESP8266Tmr.gTimingFactor > 1) {
|
||||||
time = gSimulationStartTime + ((time - gSimulationStartTime) * ESP8266Tmr.gTimingFactor);
|
time = gSimulationStartTime + ((time - gSimulationStartTime) * ESP8266Tmr.gTimingFactor);
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
|
} else {
|
||||||
|
return gOverwrittenTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SyncFunction extends ThreeArgFunction {
|
private class SyncFunction extends ThreeArgFunction {
|
||||||
@ -88,4 +95,8 @@ public class ESP8266Time extends TwoArgFunction {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setOverwrittenTime(long timeInMillis) {
|
||||||
|
gOverwrittenTime = timeInMillis;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package de.c3ma.ollo.mockup.ui;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Event;
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -11,8 +10,8 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -26,7 +25,6 @@ import javax.swing.event.DocumentEvent;
|
|||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import de.c3ma.ollo.LuaSimulation;
|
import de.c3ma.ollo.LuaSimulation;
|
||||||
import javafx.scene.control.DatePicker;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* created at 02.01.2018 - 12:57:02<br />
|
* created at 02.01.2018 - 12:57:02<br />
|
||||||
@ -124,7 +122,13 @@ public class WS2812Layout extends JFrame {
|
|||||||
final String pattern = "(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})";
|
final String pattern = "(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})";
|
||||||
final String current = dateTime.getText();
|
final String current = dateTime.getText();
|
||||||
|
|
||||||
|
if (current.length() <=0) {
|
||||||
|
/* color "nothing" green */
|
||||||
|
dateTime.setForeground(Color.GREEN);
|
||||||
|
/* disable the time simulation */
|
||||||
|
nodemcuSimu.setSimulationTime(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!current.matches(pattern)) {
|
if (!current.matches(pattern)) {
|
||||||
dateTime.setForeground(Color.RED);
|
dateTime.setForeground(Color.RED);
|
||||||
@ -161,7 +165,10 @@ public class WS2812Layout extends JFrame {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Set time to: " + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
|
System.out.println("[GUI] Set time to: " + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
|
||||||
|
GregorianCalendar gc = new GregorianCalendar(year, month, day, hour, minute, second);
|
||||||
|
|
||||||
|
nodemcuSimu.setSimulationTime(gc.getTimeInMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user