Adapted multithreadding

This commit is contained in:
Ollo 2021-03-19 18:45:07 +01:00
parent 639ce7ea72
commit db22d50c26

View File

@ -131,12 +131,17 @@ public class ESP8266Ws2812 extends TwoArgFunction {
final LuaString color = varargs.arg(2).checkstring(); final LuaString color = varargs.arg(2).checkstring();
final int length = color.rawlen(); final int length = color.rawlen();
if (length == 3) { if (length == 3) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final byte[] array = color.m_bytes; final byte[] array = color.m_bytes;
int r = array[0]+(Byte.MIN_VALUE*-1); int r = array[0]+(Byte.MIN_VALUE*-1);
int b = array[1]+(Byte.MIN_VALUE*-1); int b = array[1]+(Byte.MIN_VALUE*-1);
int g = array[2]+(Byte.MIN_VALUE*-1); int g = array[2]+(Byte.MIN_VALUE*-1);
ESP8266Ws2812.layout.fillLEDs(r, g, b); ESP8266Ws2812.layout.fillLEDs(r, g, b);
} }
});
}
return LuaValue.valueOf(true); return LuaValue.valueOf(true);
} else { } else {
System.err.println("[WS2812] fill with " + varargs.narg() + " arguments undefined."); System.err.println("[WS2812] fill with " + varargs.narg() + " arguments undefined.");
@ -153,12 +158,17 @@ public class ESP8266Ws2812 extends TwoArgFunction {
final LuaString color = varargs.arg(2).checkstring(); final LuaString color = varargs.arg(2).checkstring();
final int length = color.rawlen(); final int length = color.rawlen();
if (length == 3) { if (length == 3) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final byte[] array = color.m_bytes; final byte[] array = color.m_bytes;
int r = array[0]+(Byte.MIN_VALUE*-1); int r = array[0]+(Byte.MIN_VALUE*-1);
int b = array[1]+(Byte.MIN_VALUE*-1); int b = array[1]+(Byte.MIN_VALUE*-1);
int g = array[2]+(Byte.MIN_VALUE*-1); int g = array[2]+(Byte.MIN_VALUE*-1);
ESP8266Ws2812.layout.updateLED(index, r, g, b); ESP8266Ws2812.layout.updateLED(index, r, g, b);
} }
});
}
return LuaValue.valueOf(true); return LuaValue.valueOf(true);
} else { } else {