Kai did magic
This commit is contained in:
parent
a83600281d
commit
78a9027ad7
@ -4,6 +4,5 @@
|
|||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="lib" path="libs/luaj-jme-3.0.1.jar" sourcepath="libs/luaj-3.0.1/src"/>
|
<classpathentry kind="lib" path="libs/luaj-jme-3.0.1.jar" sourcepath="libs/luaj-3.0.1/src"/>
|
||||||
<classpathentry kind="lib" path="libs/luaj-jse-3.0.1.jar"/>
|
<classpathentry kind="lib" path="libs/luaj-jse-3.0.1.jar"/>
|
||||||
<classpathentry kind="lib" path="libs/luaj-sources-3.0.1.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -9,5 +9,5 @@ package de.c3ma.ollo;
|
|||||||
*/
|
*/
|
||||||
public interface LuaSimulation {
|
public interface LuaSimulation {
|
||||||
|
|
||||||
public void reboottriggered();
|
public void rebootTriggered();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import javax.management.RuntimeErrorException;
|
import javax.management.RuntimeErrorException;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import org.luaj.vm2.Globals;
|
import org.luaj.vm2.Globals;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
@ -54,7 +55,6 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
File tempDir = new File(tempFile.getParent() + File.separator + "Nodemcu" + System.currentTimeMillis());
|
File tempDir = new File(tempFile.getParent() + File.separator + "Nodemcu" + System.currentTimeMillis());
|
||||||
tempDir.mkdir();
|
tempDir.mkdir();
|
||||||
|
|
||||||
|
|
||||||
System.out.println("[Nodemcu] Directory is " + tempDir.getAbsolutePath());
|
System.out.println("[Nodemcu] Directory is " + tempDir.getAbsolutePath());
|
||||||
|
|
||||||
// Copy all files into the temporary folder
|
// Copy all files into the temporary folder
|
||||||
@ -73,7 +73,9 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
printUsage();
|
printUsage();
|
||||||
return;
|
return;
|
||||||
@ -93,8 +95,8 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
File additionalFile = new File(args[2]);
|
File additionalFile = new File(args[2]);
|
||||||
if (additionalFile.exists() && (simu.doFile != null)) {
|
if (additionalFile.exists() && (simu.doFile != null)) {
|
||||||
|
|
||||||
Files.copy(additionalFile.toPath(),
|
Files.copy(additionalFile.toPath(), new File(simu.doFile.getWorkingDirectory()
|
||||||
new File(simu.doFile.getWorkingDirectory() + File.separator + additionalFile.getName()).toPath());
|
+ File.separator + additionalFile.getName()).toPath());
|
||||||
System.out.println("Integrate " + additionalFile.getName() + " into simulation");
|
System.out.println("Integrate " + additionalFile.getName() + " into simulation");
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Script " + args[2] + " cannot be found");
|
System.err.println("Script " + args[2] + " cannot be found");
|
||||||
@ -112,6 +114,8 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void setWS2812Layout(File file) {
|
private void setWS2812Layout(File file) {
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -128,7 +132,7 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reboottriggered() {
|
public void rebootTriggered() {
|
||||||
System.out.println("=================== Reboot in Simulation -> call it again =================");
|
System.out.println("=================== Reboot in Simulation -> call it again =================");
|
||||||
this.espTmr.stopAllTimer();
|
this.espTmr.stopAllTimer();
|
||||||
try {
|
try {
|
||||||
@ -144,7 +148,7 @@ public class WS2812Simulation implements LuaSimulation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void callScript(String filename) {
|
private void callScript(String filename) {
|
||||||
this.scriptName=filename;
|
this.scriptName = filename;
|
||||||
|
|
||||||
if ((espFile != null) && (espFile.getFileInWorkingDir(filename) != null)) {
|
if ((espFile != null) && (espFile.getFileInWorkingDir(filename) != null)) {
|
||||||
LuaValue chunk = globals.loadfile(espFile.getFileInWorkingDir(filename).getAbsolutePath());
|
LuaValue chunk = globals.loadfile(espFile.getFileInWorkingDir(filename).getAbsolutePath());
|
||||||
|
@ -67,7 +67,7 @@ public class ESP8266Node extends TwoArgFunction {
|
|||||||
@Override
|
@Override
|
||||||
public LuaValue call() {
|
public LuaValue call() {
|
||||||
System.out.println("[Node] Restart");
|
System.out.println("[Node] Restart");
|
||||||
nodemcuSimu.reboottriggered();
|
nodemcuSimu.rebootTriggered();
|
||||||
return LuaValue.valueOf(false);
|
return LuaValue.valueOf(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ package de.c3ma.ollo.mockup;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import org.luaj.vm2.LuaString;
|
||||||
import org.luaj.vm2.LuaTable;
|
import org.luaj.vm2.LuaTable;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
import org.luaj.vm2.lib.OneArgFunction;
|
import org.luaj.vm2.lib.OneArgFunction;
|
||||||
@ -15,6 +18,7 @@ import de.c3ma.ollo.mockup.ui.WS2812Layout;
|
|||||||
* creator: ollo<br />
|
* creator: ollo<br />
|
||||||
* project: WS2812Emulation<br />
|
* project: WS2812Emulation<br />
|
||||||
* $Id: $<br />
|
* $Id: $<br />
|
||||||
|
*
|
||||||
* @author ollo<br />
|
* @author ollo<br />
|
||||||
*/
|
*/
|
||||||
public class ESP8266Ws2812 extends TwoArgFunction {
|
public class ESP8266Ws2812 extends TwoArgFunction {
|
||||||
@ -47,21 +51,28 @@ public class ESP8266Ws2812 extends TwoArgFunction {
|
|||||||
@Override
|
@Override
|
||||||
public LuaValue call(LuaValue arg) {
|
public LuaValue call(LuaValue arg) {
|
||||||
if (arg.isstring()) {
|
if (arg.isstring()) {
|
||||||
int length = arg.checkstring().rawlen();
|
LuaString jstring = arg.checkstring();
|
||||||
|
int length = jstring.rawlen();
|
||||||
if ((length % 3) == 0) {
|
if ((length % 3) == 0) {
|
||||||
byte[] array = arg.toString().getBytes();
|
byte[] array = jstring.m_bytes;
|
||||||
for (int i = 0; i < length; i+=3) {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (int i = 0; i < length; i += 3) {
|
||||||
if (ESP8266Ws2812.layout != null) {
|
if (ESP8266Ws2812.layout != null) {
|
||||||
ESP8266Ws2812.layout.updateLED(i/3, array[i+0], array[i+1], array[i+2]);
|
int r = array[i + 0]+(Byte.MIN_VALUE*-1);
|
||||||
|
int g = array[i + 1]+(Byte.MIN_VALUE*-1);
|
||||||
|
int b = array[i + 2]+(Byte.MIN_VALUE*-1);
|
||||||
|
ESP8266Ws2812.layout.updateLED(i / 3, r, g, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (ESP8266Ws2812.layout == null) {
|
if (ESP8266Ws2812.layout == null) {
|
||||||
System.out.println("[WS2812] write length:" + length);
|
System.out.println("[WS2812] write length:" + length);
|
||||||
} else {
|
} else {
|
||||||
/*ESP8266Ws2812.layout.update(ESP8266Ws2812.layout.getGraphics());*/
|
|
||||||
ESP8266Ws2812.layout.repaint();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LuaValue.valueOf(true);
|
return LuaValue.valueOf(true);
|
||||||
|
@ -10,6 +10,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
@ -17,12 +18,14 @@ 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.SwingUtilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* created at 02.01.2018 - 12:57:02<br />
|
* created at 02.01.2018 - 12:57:02<br />
|
||||||
* creator: ollo<br />
|
* creator: ollo<br />
|
||||||
* project: WS2812Emulation<br />
|
* project: WS2812Emulation<br />
|
||||||
* $Id: $<br />
|
* $Id: $<br />
|
||||||
|
*
|
||||||
* @author ollo<br />
|
* @author ollo<br />
|
||||||
*/
|
*/
|
||||||
public class WS2812Layout extends JFrame {
|
public class WS2812Layout extends JFrame {
|
||||||
@ -80,10 +83,8 @@ public class WS2812Layout extends JFrame {
|
|||||||
|
|
||||||
JPanel ledPanel = new JPanel();
|
JPanel ledPanel = new JPanel();
|
||||||
ledPanel.setLayout(new GridLayout(this.mRow, this.mColumn, 10, 10));
|
ledPanel.setLayout(new GridLayout(this.mRow, this.mColumn, 10, 10));
|
||||||
for (int i = 0; i < this.mRow; i++)
|
for (int i = 0; i < this.mRow; i++) {
|
||||||
{
|
for (int j = 0; j < this.mColumn; j++) {
|
||||||
for (int j = 0; j < this.mColumn; j++)
|
|
||||||
{
|
|
||||||
if (this.mElements[i][j] != null) {
|
if (this.mElements[i][j] != null) {
|
||||||
ledPanel.add(this.mElements[i][j]);
|
ledPanel.add(this.mElements[i][j]);
|
||||||
}
|
}
|
||||||
@ -92,17 +93,14 @@ public class WS2812Layout extends JFrame {
|
|||||||
contentPane.add(ledPanel, BorderLayout.CENTER);
|
contentPane.add(ledPanel, BorderLayout.CENTER);
|
||||||
JButton button = new JButton("Do something");
|
JButton button = new JButton("Do something");
|
||||||
button.setActionCommand("Do something");
|
button.setActionCommand("Do something");
|
||||||
button.addActionListener(new ActionListener()
|
button.addActionListener(new ActionListener() {
|
||||||
{
|
public void actionPerformed(ActionEvent ae) {
|
||||||
public void actionPerformed(ActionEvent ae)
|
|
||||||
{
|
|
||||||
JButton but = (JButton) ae.getSource();
|
JButton but = (JButton) ae.getSource();
|
||||||
//FIXME some clever logic
|
// FIXME some clever logic
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
contentPane.add(button, BorderLayout.SOUTH);
|
contentPane.add(button, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
pack();
|
pack();
|
||||||
setLocationByPlatform(true);
|
setLocationByPlatform(true);
|
||||||
@ -111,13 +109,12 @@ public class WS2812Layout extends JFrame {
|
|||||||
|
|
||||||
private void parse() {
|
private void parse() {
|
||||||
this.mElements = new Element[this.mRow][this.mColumn];
|
this.mElements = new Element[this.mRow][this.mColumn];
|
||||||
int row=0;
|
int row = 0;
|
||||||
for (String line : this.mLines) {
|
for (String line : this.mLines) {
|
||||||
for (int i = 0; i < line.length(); i++) {
|
for (int i = 0; i < line.length(); i++) {
|
||||||
char c = line.charAt(i);
|
char c = line.charAt(i);
|
||||||
if ((('A' <= c) && (c <= 'Z')) ||
|
if ((('A' <= c) && (c <= 'Z')) || (('0' <= c) && (c <= '9')) || (c == 'Ä') || (c == 'Ö')
|
||||||
(('0' <= c) && (c <= '9')) ||
|
|| (c == 'Ü')) {
|
||||||
(c == 'Ä') || (c == 'Ö') || (c == 'Ü')) {
|
|
||||||
this.mElements[row][i] = new Element(c);
|
this.mElements[row][i] = new Element(c);
|
||||||
} else {
|
} else {
|
||||||
this.mElements[row][i] = new Element();
|
this.mElements[row][i] = new Element();
|
||||||
@ -135,7 +132,7 @@ public class WS2812Layout extends JFrame {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -3933903441113933637L;
|
private static final long serialVersionUID = -3933903441113933637L;
|
||||||
|
|
||||||
private boolean noText=false;
|
private boolean noText = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a simple rect
|
* Draw a simple rect
|
||||||
@ -148,21 +145,23 @@ public class WS2812Layout extends JFrame {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw a character
|
* Draw a character
|
||||||
* @param character to show
|
*
|
||||||
|
* @param character
|
||||||
|
* to show
|
||||||
*/
|
*/
|
||||||
public Element(char character) {
|
public Element(char character) {
|
||||||
super(""+character);
|
super("" + character);
|
||||||
setFont(new Font("Dialog", Font.BOLD, 24));
|
setFont(new Font("Dialog", Font.BOLD, 24));
|
||||||
setHorizontalAlignment(CENTER);
|
setHorizontalAlignment(CENTER);
|
||||||
//FIXME: Background color is not updated:
|
// FIXME: Background color is not updated:
|
||||||
this.setBackground(Color.BLACK);
|
this.setBackground(Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(int red, int green, int blue) {
|
public void setColor(int red, int green, int blue) {
|
||||||
this.setForeground(new Color(red, green, blue));
|
this.setForeground(new Color(red, green, blue));
|
||||||
//FIXME changing the color is not working
|
// FIXME changing the color is not working
|
||||||
this.repaint();
|
this.repaint();
|
||||||
System.out.println( this.toString());
|
System.out.println(this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -173,22 +172,21 @@ public class WS2812Layout extends JFrame {
|
|||||||
} else {
|
} else {
|
||||||
sb.append("" + this.getText());
|
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().getGreen()) + " "
|
||||||
" " + Integer.toHexString(this.getForeground().getBlue()));
|
+ Integer.toHexString(this.getForeground().getBlue()));
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLED(int index, byte red, byte green, byte blue) {
|
public void updateLED(int index, int r, int g, int b) {
|
||||||
if (this.mElements != null) {
|
if (mElements != null) {
|
||||||
int i = (index / this.mColumn);
|
int i = (index / mColumn);
|
||||||
int j = (index % this.mColumn);
|
int j = (index % mColumn);
|
||||||
if ((i < this.mElements.length) &&
|
if ((i < mElements.length) && (j < mElements[i].length) && (mElements[i][j] != null)) {
|
||||||
(j < this.mElements[i].length) &&
|
Element curlbl = mElements[i][j];
|
||||||
(this.mElements[i][j] != null)) {
|
curlbl.setColor(r, g, b);
|
||||||
this.mElements[i][j].setColor(red, green, blue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user