diff --git a/simulation/src/de/c3ma/ollo/WS2812Simulation.java b/simulation/src/de/c3ma/ollo/WS2812Simulation.java
index b7c6ede..766fb31 100644
--- a/simulation/src/de/c3ma/ollo/WS2812Simulation.java
+++ b/simulation/src/de/c3ma/ollo/WS2812Simulation.java
@@ -23,6 +23,8 @@ import de.c3ma.ollo.mockup.ESP8266Tmr;
import de.c3ma.ollo.mockup.ESP8266Uart;
import de.c3ma.ollo.mockup.ESP8266Wifi;
import de.c3ma.ollo.mockup.ESP8266Ws2812;
+import de.c3ma.ollo.mockup.PrintFunction;
+import de.c3ma.ollo.mockup.ui.WS2812Layout;
/**
* created at 28.12.2017 - 13:19:32
@@ -43,6 +45,7 @@ public class WS2812Simulation implements LuaSimulation {
private ESP8266Gpio gpio = new ESP8266Gpio();
private ESP8266Mqtt mqtt = new ESP8266Mqtt();
private ESP8266Adc adc = new ESP8266Adc();
+ private PrintFunction print = new PrintFunction();
private String scriptName;
public WS2812Simulation(File sourceFolder) {
@@ -59,6 +62,7 @@ public class WS2812Simulation implements LuaSimulation {
globals.load(new ESP8266Net());
globals.load(new ESP8266Time());
globals.set("dofile", doFile);
+ globals.set("print", print);
adc.setADC(50);
try {
@@ -146,7 +150,8 @@ public class WS2812Simulation implements LuaSimulation {
private void setWS2812Layout(File file) {
if (file.exists()) {
- ws2812.setLayout(file, this);
+ WS2812Layout ledLayout = ws2812.setLayout(file, this);
+ print.setPrinter(ledLayout);
} else {
throw new RuntimeException("WS2812 Layout: " + file.getAbsolutePath() + " does not exists");
}
diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java
index 38da090..fcaca9f 100644
--- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java
+++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java
@@ -89,10 +89,11 @@ public class ESP8266Ws2812 extends TwoArgFunction {
}
}
- public void setLayout(File file, LuaSimulation nodemcuSimu) {
+ public WS2812Layout setLayout(File file, LuaSimulation nodemcuSimu) {
if (ESP8266Ws2812.layout == null) {
ESP8266Ws2812.layout = WS2812Layout.parse(file, nodemcuSimu);
}
+ return ESP8266Ws2812.layout;
}
private class newBuffer extends VarArgFunction {
diff --git a/simulation/src/de/c3ma/ollo/mockup/PrintFunction.java b/simulation/src/de/c3ma/ollo/mockup/PrintFunction.java
new file mode 100644
index 0000000..9315476
--- /dev/null
+++ b/simulation/src/de/c3ma/ollo/mockup/PrintFunction.java
@@ -0,0 +1,32 @@
+package de.c3ma.ollo.mockup;
+
+import java.io.File;
+
+import org.luaj.vm2.Globals;
+import org.luaj.vm2.LuaValue;
+import org.luaj.vm2.lib.OneArgFunction;
+
+/**
+ *
+ * @author ollo
+ *
+ */
+public class PrintFunction extends OneArgFunction {
+
+ private Printable mPrinter;
+
+ public void setPrinter(Printable printer) {
+ this.mPrinter = printer;
+ }
+
+ @Override
+ public LuaValue call(LuaValue message) {
+ String msg = message.checkjstring();
+ if (mPrinter != null) {
+ mPrinter.printConsole(msg);
+ return LuaValue.valueOf(true);
+ } else {
+ return LuaValue.valueOf(false);
+ }
+ }
+}
diff --git a/simulation/src/de/c3ma/ollo/mockup/Printable.java b/simulation/src/de/c3ma/ollo/mockup/Printable.java
new file mode 100644
index 0000000..3398146
--- /dev/null
+++ b/simulation/src/de/c3ma/ollo/mockup/Printable.java
@@ -0,0 +1,5 @@
+package de.c3ma.ollo.mockup;
+
+public interface Printable {
+ public void printConsole(String line);
+}
diff --git a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
index d99e3b9..35e1867 100644
--- a/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
+++ b/simulation/src/de/c3ma/ollo/mockup/ui/WS2812Layout.java
@@ -2,6 +2,7 @@ package de.c3ma.ollo.mockup.ui;
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
@@ -17,18 +18,23 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import javax.swing.JScrollPane;
import javax.swing.JSlider;
+import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
+import javax.swing.text.DefaultCaret;
import de.c3ma.ollo.LuaSimulation;
+import de.c3ma.ollo.mockup.Printable;
/**
* created at 02.01.2018 - 12:57:02
@@ -38,7 +44,7 @@ import de.c3ma.ollo.LuaSimulation;
*
* @author ollo
*/
-public class WS2812Layout extends JFrame {
+public class WS2812Layout extends JFrame implements Printable {
/**
*
@@ -56,6 +62,7 @@ public class WS2812Layout extends JFrame {
private int mColumn = 0;
private int mRow = 0;
private Element[][] mElements;
+ private JTextArea mConsole = null;
private LuaSimulation nodemcuSimu;
@@ -128,6 +135,8 @@ public class WS2812Layout extends JFrame {
contentPane.add(adc, BorderLayout.EAST);
+ JPanel bottomShell = new JPanel();
+ bottomShell.setLayout(new javax.swing.BoxLayout(bottomShell, BoxLayout.Y_AXIS));
JPanel bottomPanel = new JPanel();
final JTextField dateTime = new JTextField("yyyy-mm-dd HH:MM:SS");
@@ -225,9 +234,20 @@ public class WS2812Layout extends JFrame {
}
});
bottomPanel.add(btnReboot);
-
- contentPane.add(bottomPanel, BorderLayout.SOUTH);
+ bottomShell.add(bottomPanel);
+ mConsole = new JTextArea("Test");
+ mConsole.setEditable(false);
+ mConsole.setMinimumSize(new Dimension(200, 220));
+ mConsole.setMaximumSize(new Dimension(800, 200));
+ mConsole.setDoubleBuffered(true);
+ JScrollPane scrollPane = new JScrollPane(mConsole);
+ //scrollPane.setSize(100, 200);
+ scrollPane.setMinimumSize(new Dimension(800, 200));
+ bottomShell.add(scrollPane);
+
+ contentPane.add(bottomShell, BorderLayout.SOUTH);
+
setContentPane(contentPane);
pack();
setLocationByPlatform(true);
@@ -358,5 +378,13 @@ public class WS2812Layout extends JFrame {
}
}
}
+
+ public void printConsole(String line) {
+ if (mConsole != null) {
+ mConsole.append(line);
+ mConsole.append("\r\n");
+ mConsole.getCaret().setDot( Integer.MAX_VALUE );
+ }
+ }
}