From ca47018a32e1959191880d0455257f3ab2ebea8c Mon Sep 17 00:00:00 2001 From: ollo Date: Sat, 3 Feb 2018 16:51:00 +0100 Subject: [PATCH] The time can be set within the GUI --- .../src/de/c3ma/ollo/LuaSimulation.java | 2 ++ .../src/de/c3ma/ollo/WS2812Simulation.java | 5 +++++ .../src/de/c3ma/ollo/mockup/ESP8266Time.java | 19 +++++++++++++++---- .../de/c3ma/ollo/mockup/ui/WS2812Layout.java | 17 ++++++++++++----- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/simulation/src/de/c3ma/ollo/LuaSimulation.java b/simulation/src/de/c3ma/ollo/LuaSimulation.java index 35d7fb0..5d3023d 100644 --- a/simulation/src/de/c3ma/ollo/LuaSimulation.java +++ b/simulation/src/de/c3ma/ollo/LuaSimulation.java @@ -10,4 +10,6 @@ package de.c3ma.ollo; public interface LuaSimulation { public void rebootTriggered(); + + public void setSimulationTime(long timeInMillis); } diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index 148e20f..08b80a2 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -165,4 +165,9 @@ public class WS2812Simulation implements LuaSimulation { throw new RuntimeException("Copy into temporary folder failed; script not available"); } } + + @Override + public void setSimulationTime(long timeInMillis) { + ESP8266Time.setOverwrittenTime(timeInMillis); + } } diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java index 16e442c..a8f48df 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Time.java @@ -23,6 +23,8 @@ public class ESP8266Time extends TwoArgFunction { private static long gSimulationStartTime = 0; + private static long gOverwrittenTime = 0; + @Override public LuaValue call(LuaValue modname, LuaValue env) { env.checkglobals(); @@ -48,11 +50,16 @@ public class ESP8266Time extends TwoArgFunction { gSimulationStartTime = System.currentTimeMillis(); } - long time = System.currentTimeMillis(); - if (ESP8266Tmr.gTimingFactor > 1) { - time = gSimulationStartTime + ((time - gSimulationStartTime) * ESP8266Tmr.gTimingFactor); + if (gOverwrittenTime == 0) { + /* Time simulation is disabled -> calculate something according to the speedup factor */ + long time = System.currentTimeMillis(); + if (ESP8266Tmr.gTimingFactor > 1) { + time = gSimulationStartTime + ((time - gSimulationStartTime) * ESP8266Tmr.gTimingFactor); + } + return time; + } else { + return gOverwrittenTime; } - return time; } private class SyncFunction extends ThreeArgFunction { @@ -87,5 +94,9 @@ public class ESP8266Time extends TwoArgFunction { } } + + public static void setOverwrittenTime(long timeInMillis) { + gOverwrittenTime = timeInMillis; + } } diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java index 2200d60..a68c4b9 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java +++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java @@ -2,7 +2,6 @@ package de.c3ma.ollo.mockup.ui; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Event; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; @@ -11,8 +10,8 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.time.LocalDate; import java.util.ArrayList; +import java.util.GregorianCalendar; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,7 +25,6 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import de.c3ma.ollo.LuaSimulation; -import javafx.scene.control.DatePicker; /** * created at 02.01.2018 - 12:57:02
@@ -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 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)) { dateTime.setForeground(Color.RED); @@ -161,7 +165,10 @@ public class WS2812Layout extends JFrame { 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()); } } });