From 225f4af842706273ad4bca38ce23ea03ec3c875c Mon Sep 17 00:00:00 2001 From: ollo Date: Tue, 2 Jan 2018 14:47:49 +0100 Subject: [PATCH] Special configuration file for the simulation can be set --- simulation/Readme.md | 5 +++++ simulation/config.lua | 13 ++++++++++++ .../src/de/c3ma/ollo/WS2812Simulation.java | 20 +++++++++++++++++-- .../de/c3ma/ollo/mockup/DoFileFunction.java | 8 ++++++++ .../de/c3ma/ollo/mockup/ui/WS2812Layout.java | 2 +- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 simulation/Readme.md create mode 100644 simulation/config.lua diff --git a/simulation/Readme.md b/simulation/Readme.md new file mode 100644 index 0000000..e897c86 --- /dev/null +++ b/simulation/Readme.md @@ -0,0 +1,5 @@ +# Simulation + +The simualation should be started with the following arguments at this position: + `../init.lua ws28128ClockLayout.txt config.lua` + diff --git a/simulation/config.lua b/simulation/config.lua new file mode 100644 index 0000000..b15e0a7 --- /dev/null +++ b/simulation/config.lua @@ -0,0 +1,13 @@ +green=0 +red=60 +blue=0 + +color=string.char(green, red, blue) +color1=string.char(green, red, blue) +color2=string.char(green, red, blue) +color3=string.char(green, red, blue) +color4=string.char(green, red, blue) + +colorBg=string.char(0,0,0) -- black is the default background color +sntpserverhostname="ptbtime1.ptb.de" + diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java index 9701eb3..c01d68c 100644 --- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java +++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java @@ -88,8 +88,24 @@ public class WS2812Simulation implements LuaSimulation { if (args.length >= 2) { simu.setWS2812Layout(new File(args[1])); } - - simu.callScript(f.getName()); + try { + if (args.length >= 3) { + File additionalFile = new File(args[2]); + if (additionalFile.exists() && (simu.doFile != null)) { + + Files.copy(additionalFile.toPath(), + new File(simu.doFile.getWorkingDirectory() + File.separator + additionalFile.getName()).toPath()); + System.out.println("Integrate " + additionalFile.getName() + " into simulation"); + } else { + System.err.println("Script " + args[2] + " cannot be found"); + System.exit(1); + } + } + + simu.callScript(f.getName()); + } catch (IOException e) { + System.err.println("[Nodemcu] " + e.getMessage()); + } } } else { printUsage(); diff --git a/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java b/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java index 56e5a63..c9e6250 100644 --- a/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java +++ b/simulation/src/de/c3ma/ollo/mockup/DoFileFunction.java @@ -43,4 +43,12 @@ public class DoFileFunction extends OneArgFunction { this.workingDir = workingDir; } + public String getWorkingDirectory() { + if (workingDir != null) { + return workingDir.getAbsolutePath(); + } else { + return null; + } + } + } diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java index 2d9f0bf..8737040 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java +++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java @@ -172,7 +172,7 @@ public class WS2812Layout extends JFrame { } else { sb.append("" + this.getText()); } - sb.append(Integer.toHexString(this.getForeground().getRed()) + + sb.append("|" + Integer.toHexString(this.getForeground().getRed()) + " " + Integer.toHexString(this.getForeground().getGreen()) + " " + Integer.toHexString(this.getForeground().getBlue()));