From 4522e40d52a8e54d9237879e6eb2f160defcf5bc Mon Sep 17 00:00:00 2001 From: ollo Date: Wed, 17 Jan 2018 21:11:42 +0100 Subject: [PATCH] Simulation speedup factor added --- simulation/config.lua | 3 ++- simulation/src/de/c3ma/ollo/WS2812Simulation.java | 13 +++++++++++-- simulation/src/de/c3ma/ollo/mockup/ESP8266Tmr.java | 7 +++++-- .../src/de/c3ma/ollo/mockup/ESP8266Ws2812.java | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/simulation/config.lua b/simulation/config.lua index 48e04ba..07b77c9 100644 --- a/simulation/config.lua +++ b/simulation/config.lua @@ -10,4 +10,5 @@ color4=string.char(green, red, blue) colorBg=string.char(0,0,0) -- black is the default background color sntpserverhostname="ptbtime1.ptb.de" -timezoneoffset=1 \ No newline at end of file +timezoneoffset=1 + diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index 02a8557..073942d 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -72,7 +72,7 @@ public class WS2812Simulation implements LuaSimulation { } } - public static void main(String[] args) { + public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -100,9 +100,18 @@ public class WS2812Simulation implements LuaSimulation { System.out.println("Integrate " + additionalFile.getName() + " into simulation"); } else { System.err.println("Script " + args[2] + " cannot be found"); + printUsage(); System.exit(1); } } + if (args.length >= 4) { + try { + ESP8266Tmr.gTimingFactor = Integer.parseInt(args[3]); + } catch (NumberFormatException nfe) { + System.err.println("Timing factor not parsable: " + nfe.getMessage()); + printUsage(); + } + } simu.callScript(f.getName()); } catch (IOException e) { @@ -128,7 +137,7 @@ public class WS2812Simulation implements LuaSimulation { private static void printUsage() { System.out.println("Usage:"); System.out.println("one argument required: file to execute."); - System.out.println(".e.g: init.lua"); + System.out.println(".e.g: init.lua (ws2812 layout configuration) (additional LUA script) (timing speedup factor)"); } @Override diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Tmr.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Tmr.java index 2b01e83..4c1782a 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Tmr.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Tmr.java @@ -21,6 +21,8 @@ public class ESP8266Tmr extends TwoArgFunction { private static final int MAXTHREADS = 7; private static LuaThreadTmr[] allThreads = new LuaThreadTmr[MAXTHREADS]; + + public static int gTimingFactor = 1; @Override public LuaValue call(LuaValue modname, LuaValue env) { @@ -77,13 +79,14 @@ public class ESP8266Tmr extends TwoArgFunction { System.err.println("[TMR] Timer" + timerNumer + " stopped"); } - allThreads[timerNumer] = new LuaThreadTmr(timerNumer, code, (endlessloop == 1), delay); + /* The cycletime is at least 1 ms */ + allThreads[timerNumer] = new LuaThreadTmr(timerNumer, code, (endlessloop == 1), Math.max(delay / gTimingFactor, 1)); allThreads[timerNumer].start(); } return LuaValue.valueOf(true); } } - + public void stopAllTimer() { for (int i = 0; i < allThreads.length; i++) { stopTmr(i); diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java index 3cdbde1..a6fc6c3 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java @@ -52,9 +52,9 @@ public class ESP8266Ws2812 extends TwoArgFunction { public LuaValue call(LuaValue arg) { if (arg.isstring()) { LuaString jstring = arg.checkstring(); - int length = jstring.rawlen(); + final int length = jstring.rawlen(); if ((length % 3) == 0) { - byte[] array = jstring.m_bytes; + final byte[] array = jstring.m_bytes; SwingUtilities.invokeLater(new Runnable() { @Override public void run() {