From db22d50c2640761686a70c89c45d8ae9d482d6ea Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 19 Mar 2021 18:45:07 +0100 Subject: [PATCH] Adapted multithreadding --- .../de/c3ma/ollo/mockup/ESP8266Ws2812.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java index 50b55ec..a8f4110 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Ws2812.java @@ -131,11 +131,16 @@ public class ESP8266Ws2812 extends TwoArgFunction { final LuaString color = varargs.arg(2).checkstring(); final int length = color.rawlen(); if (length == 3) { - final byte[] array = color.m_bytes; - int r = array[0]+(Byte.MIN_VALUE*-1); - int b = array[1]+(Byte.MIN_VALUE*-1); - int g = array[2]+(Byte.MIN_VALUE*-1); - ESP8266Ws2812.layout.fillLEDs(r, g, b); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final byte[] array = color.m_bytes; + int r = array[0]+(Byte.MIN_VALUE*-1); + int b = array[1]+(Byte.MIN_VALUE*-1); + int g = array[2]+(Byte.MIN_VALUE*-1); + ESP8266Ws2812.layout.fillLEDs(r, g, b); + } + }); } return LuaValue.valueOf(true); } else { @@ -153,11 +158,16 @@ public class ESP8266Ws2812 extends TwoArgFunction { final LuaString color = varargs.arg(2).checkstring(); final int length = color.rawlen(); if (length == 3) { - final byte[] array = color.m_bytes; - int r = array[0]+(Byte.MIN_VALUE*-1); - int b = array[1]+(Byte.MIN_VALUE*-1); - int g = array[2]+(Byte.MIN_VALUE*-1); - ESP8266Ws2812.layout.updateLED(index, r, g, b); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + final byte[] array = color.m_bytes; + int r = array[0]+(Byte.MIN_VALUE*-1); + int b = array[1]+(Byte.MIN_VALUE*-1); + int g = array[2]+(Byte.MIN_VALUE*-1); + ESP8266Ws2812.layout.updateLED(index, r, g, b); + } + }); } return LuaValue.valueOf(true);