From: Madeorsk Date: Sat, 14 Sep 2024 19:26:51 +0000 (+0200) Subject: Fix level write mode for LEDs which don't support white and color update at once... X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=cae65393d41b4abae692d79c452883f06663ccbd;p=openhab-addons.git Fix level write mode for LEDs which don't support white and color update at once. (#15846) Signed-off-by: Madeorsk --- diff --git a/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/AbstractWiFiLEDDriver.java b/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/AbstractWiFiLEDDriver.java index 885b33e933..24eb146a90 100644 --- a/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/AbstractWiFiLEDDriver.java +++ b/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/AbstractWiFiLEDDriver.java @@ -46,6 +46,18 @@ public abstract class AbstractWiFiLEDDriver { FADING } + public enum LevelWriteMode { + ALL((byte) 0x00), + COLORS((byte) 0xF0), + WHITES((byte) 0x0F); + + public final byte byteValue; + + private LevelWriteMode(byte byteValue) { + this.byteValue = byteValue; + } + } + public static final Integer DEFAULT_PORT = 5577; protected static final int DEFAULT_SOCKET_TIMEOUT = 5000; @@ -199,11 +211,15 @@ public abstract class AbstractWiFiLEDDriver { } protected byte[] getBytesForColor(byte r, byte g, byte b, byte w, byte w2) { + return getBytesForColor(r, g, b, w, w2, LevelWriteMode.ALL); + } + + protected byte[] getBytesForColor(byte r, byte g, byte b, byte w, byte w2, LevelWriteMode writeMode) { byte[] bytes; if (protocol == Protocol.LD382 || protocol == Protocol.LD382A) { - bytes = new byte[] { 0x31, r, g, b, w, 0x00 }; + bytes = new byte[] { 0x31, r, g, b, w, writeMode.byteValue }; } else if (protocol == Protocol.LD686) { - bytes = new byte[] { 0x31, r, g, b, w, w2, 0x00 }; + bytes = new byte[] { 0x31, r, g, b, w, w2, writeMode.byteValue }; } else { throw new UnsupportedOperationException("Protocol " + protocol + " not yet implemented"); } diff --git a/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/ClassicWiFiLEDDriver.java b/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/ClassicWiFiLEDDriver.java index 9da4bbb27a..8f2b7a3eb7 100644 --- a/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/ClassicWiFiLEDDriver.java +++ b/bundles/org.openhab.binding.wifiled/src/main/java/org/openhab/binding/wifiled/internal/handler/ClassicWiFiLEDDriver.java @@ -70,7 +70,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Setting color to {}", color); LEDStateDTO ledState = getLEDStateDTO().withColor(color).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.COLORS); } @Override @@ -78,7 +78,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Setting brightness to {}", brightness); LEDStateDTO ledState = getLEDStateDTO().withBrightness(brightness).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.COLORS); } @Override @@ -86,7 +86,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Changing brightness by {}", step); LEDStateDTO ledState = getLEDStateDTO().withIncrementedBrightness(step).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.COLORS); } @Override @@ -94,7 +94,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Setting (warm) white LED to {}", white); LEDStateDTO ledState = getLEDStateDTO().withWhite(white).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.WHITES); } @Override @@ -102,7 +102,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Changing white by {}", step); LEDStateDTO ledState = getLEDStateDTO().withIncrementedWhite(step).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.WHITES); } @Override @@ -110,7 +110,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Setting (warm) white 2 LED to {}", white2); LEDStateDTO ledState = getLEDStateDTO().withWhite2(white2).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.WHITES); } @Override @@ -118,7 +118,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { logger.debug("Changing white by {}", step); LEDStateDTO ledState = getLEDStateDTO().withIncrementedWhite2(step).withoutProgram(); - sendLEDData(ledState); + sendLEDData(ledState, LevelWriteMode.WHITES); } @Override @@ -156,6 +156,10 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { } private synchronized void sendLEDData(final LEDStateDTO ledState) { + this.sendLEDData(ledState, LevelWriteMode.ALL); + } + + private synchronized void sendLEDData(final LEDStateDTO ledState, LevelWriteMode writeMode) { cachedLedStatus = ledState; if (!ledUpdateFuture.isDone()) { ledUpdateFuture.cancel(true); @@ -171,7 +175,7 @@ public class ClassicWiFiLEDDriver extends AbstractWiFiLEDDriver { byte w = (byte) (((int) (ledState.getWhite().doubleValue() * 255 / 100)) & 0xFF); byte w2 = (byte) (((int) (ledState.getWhite2().doubleValue() * 255 / 100)) & 0xFF); - bytes = getBytesForColor(r, g, b, w, w2); + bytes = getBytesForColor(r, g, b, w, w2, writeMode); } else { // program selected byte p = (byte) (program & 0xFF);