Add console output in simulation window

This commit is contained in:
Ollo 2022-01-21 22:37:22 +01:00
parent b9300048da
commit 800003f245
5 changed files with 76 additions and 5 deletions

View File

@ -23,6 +23,8 @@ import de.c3ma.ollo.mockup.ESP8266Tmr;
import de.c3ma.ollo.mockup.ESP8266Uart; import de.c3ma.ollo.mockup.ESP8266Uart;
import de.c3ma.ollo.mockup.ESP8266Wifi; import de.c3ma.ollo.mockup.ESP8266Wifi;
import de.c3ma.ollo.mockup.ESP8266Ws2812; 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<br /> * created at 28.12.2017 - 13:19:32<br />
@ -43,6 +45,7 @@ public class WS2812Simulation implements LuaSimulation {
private ESP8266Gpio gpio = new ESP8266Gpio(); private ESP8266Gpio gpio = new ESP8266Gpio();
private ESP8266Mqtt mqtt = new ESP8266Mqtt(); private ESP8266Mqtt mqtt = new ESP8266Mqtt();
private ESP8266Adc adc = new ESP8266Adc(); private ESP8266Adc adc = new ESP8266Adc();
private PrintFunction print = new PrintFunction();
private String scriptName; private String scriptName;
public WS2812Simulation(File sourceFolder) { public WS2812Simulation(File sourceFolder) {
@ -59,6 +62,7 @@ public class WS2812Simulation implements LuaSimulation {
globals.load(new ESP8266Net()); globals.load(new ESP8266Net());
globals.load(new ESP8266Time()); globals.load(new ESP8266Time());
globals.set("dofile", doFile); globals.set("dofile", doFile);
globals.set("print", print);
adc.setADC(50); adc.setADC(50);
try { try {
@ -146,7 +150,8 @@ public class WS2812Simulation implements LuaSimulation {
private void setWS2812Layout(File file) { private void setWS2812Layout(File file) {
if (file.exists()) { if (file.exists()) {
ws2812.setLayout(file, this); WS2812Layout ledLayout = ws2812.setLayout(file, this);
print.setPrinter(ledLayout);
} else { } else {
throw new RuntimeException("WS2812 Layout: " + file.getAbsolutePath() + " does not exists"); throw new RuntimeException("WS2812 Layout: " + file.getAbsolutePath() + " does not exists");
} }

View File

@ -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) { if (ESP8266Ws2812.layout == null) {
ESP8266Ws2812.layout = WS2812Layout.parse(file, nodemcuSimu); ESP8266Ws2812.layout = WS2812Layout.parse(file, nodemcuSimu);
} }
return ESP8266Ws2812.layout;
} }
private class newBuffer extends VarArgFunction { private class newBuffer extends VarArgFunction {

View File

@ -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);
}
}
}

View File

@ -0,0 +1,5 @@
package de.c3ma.ollo.mockup;
public interface Printable {
public void printConsole(String line);
}

View File

@ -2,6 +2,7 @@ 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.Dimension;
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;
@ -17,18 +18,23 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultCaret;
import de.c3ma.ollo.LuaSimulation; import de.c3ma.ollo.LuaSimulation;
import de.c3ma.ollo.mockup.Printable;
/** /**
* created at 02.01.2018 - 12:57:02<br /> * created at 02.01.2018 - 12:57:02<br />
@ -38,7 +44,7 @@ import de.c3ma.ollo.LuaSimulation;
* *
* @author ollo<br /> * @author ollo<br />
*/ */
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 mColumn = 0;
private int mRow = 0; private int mRow = 0;
private Element[][] mElements; private Element[][] mElements;
private JTextArea mConsole = null;
private LuaSimulation nodemcuSimu; private LuaSimulation nodemcuSimu;
@ -128,6 +135,8 @@ public class WS2812Layout extends JFrame {
contentPane.add(adc, BorderLayout.EAST); contentPane.add(adc, BorderLayout.EAST);
JPanel bottomShell = new JPanel();
bottomShell.setLayout(new javax.swing.BoxLayout(bottomShell, BoxLayout.Y_AXIS));
JPanel bottomPanel = new JPanel(); JPanel bottomPanel = new JPanel();
final JTextField dateTime = new JTextField("yyyy-mm-dd HH:MM:SS"); final JTextField dateTime = new JTextField("yyyy-mm-dd HH:MM:SS");
@ -225,9 +234,20 @@ public class WS2812Layout extends JFrame {
} }
}); });
bottomPanel.add(btnReboot); bottomPanel.add(btnReboot);
bottomShell.add(bottomPanel);
contentPane.add(bottomPanel, BorderLayout.SOUTH);
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); setContentPane(contentPane);
pack(); pack();
setLocationByPlatform(true); 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 );
}
}
} }