[nanoleaf] Use new core class ColorUtil for RGB conversion (#14773)
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
b07dd3c48f
commit
2c8f639060
@ -14,8 +14,6 @@ package org.openhab.binding.nanoleaf.internal.handler;
|
||||
|
||||
import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -48,6 +46,7 @@ import org.openhab.core.thing.binding.BridgeHandler;
|
||||
import org.openhab.core.thing.binding.ThingHandler;
|
||||
import org.openhab.core.types.Command;
|
||||
import org.openhab.core.types.RefreshType;
|
||||
import org.openhab.core.util.ColorUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -220,15 +219,8 @@ public class NanoleafPanelHandler extends BaseThingHandler implements NanoleafPa
|
||||
logger.trace("Setting new color {} to panel {}", newPanelColor, getPanelID());
|
||||
setPanelColor(newPanelColor);
|
||||
// transform to RGB
|
||||
PercentType[] rgbPercent = newPanelColor.toRGB();
|
||||
logger.trace("Setting new rgbpercent {} {} {}", rgbPercent[0], rgbPercent[1], rgbPercent[2]);
|
||||
int red = rgbPercent[0].toBigDecimal().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal(255)).intValue();
|
||||
int green = rgbPercent[1].toBigDecimal().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal(255)).intValue();
|
||||
int blue = rgbPercent[2].toBigDecimal().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal(255)).intValue();
|
||||
logger.trace("Setting new rgb {} {} {}", red, green, blue);
|
||||
int[] rgb = ColorUtil.hsbToRgb(newPanelColor);
|
||||
logger.trace("Setting new rgb {} {} {}", rgb[0], rgb[1], rgb[2]);
|
||||
Bridge bridge = getBridge();
|
||||
if (bridge != null) {
|
||||
Effects effects = new Effects();
|
||||
@ -243,14 +235,14 @@ public class NanoleafPanelHandler extends BaseThingHandler implements NanoleafPa
|
||||
// Light Panels and Canvas use different stream commands
|
||||
if (config.deviceType.equals(CONFIG_DEVICE_TYPE_LIGHTPANELS)
|
||||
|| config.deviceType.equals(CONFIG_DEVICE_TYPE_CANVAS)) {
|
||||
logger.trace("Anim Data rgb {} {} {} {}", panelID, red, green, blue);
|
||||
write.setAnimData(String.format("1 %s 1 %d %d %d 0 10", panelID, red, green, blue));
|
||||
logger.trace("Anim Data rgb {} {} {} {}", panelID, rgb[0], rgb[1], rgb[2]);
|
||||
write.setAnimData(String.format("1 %s 1 %d %d %d 0 10", panelID, rgb[0], rgb[1], rgb[2]));
|
||||
} else {
|
||||
// this is only used in special streaming situations with canvas which is not yet supported
|
||||
int quotient = Integer.divideUnsigned(panelID, 256);
|
||||
int remainder = Integer.remainderUnsigned(panelID, 256);
|
||||
write.setAnimData(
|
||||
String.format("0 1 %d %d %d %d %d 0 0 10", quotient, remainder, red, green, blue));
|
||||
String.format("0 1 %d %d %d %d %d 0 0 10", quotient, remainder, rgb[0], rgb[1], rgb[2]));
|
||||
}
|
||||
write.setLoop(false);
|
||||
effects.setWrite(write);
|
||||
|
||||
@ -27,6 +27,7 @@ import org.openhab.binding.nanoleaf.internal.layout.Point2D;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
|
||||
import org.openhab.binding.nanoleaf.internal.model.PositionDatum;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.util.ColorUtil;
|
||||
|
||||
/**
|
||||
* A hexagon shape.
|
||||
@ -132,7 +133,7 @@ public class HexagonCorners extends Panel {
|
||||
|
||||
private static Color getColor(int panelId, PanelState state) {
|
||||
HSBType color = state.getHSBForPanel(panelId);
|
||||
return new Color(color.getRGB());
|
||||
return new Color(ColorUtil.hsbTosRgb(color));
|
||||
}
|
||||
|
||||
private Color getAverageColor(PanelState state) {
|
||||
|
||||
@ -24,6 +24,7 @@ import org.openhab.binding.nanoleaf.internal.layout.PanelState;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.Point2D;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.util.ColorUtil;
|
||||
|
||||
/**
|
||||
* A shape without any area.
|
||||
@ -55,7 +56,7 @@ public class Point extends Panel {
|
||||
|
||||
if (settings.shouldFillWithColor()) {
|
||||
HSBType color = state.getHSBForPanel(panelId);
|
||||
graphics.setColor(new Color(color.getRGB()));
|
||||
graphics.setColor(new Color(ColorUtil.hsbTosRgb(color)));
|
||||
graphics.fillOval(pos.getX(), pos.getY(), POINT_DIAMETER, POINT_DIAMETER);
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ import org.openhab.binding.nanoleaf.internal.layout.PanelState;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.Point2D;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.util.ColorUtil;
|
||||
|
||||
/**
|
||||
* Draws shapes, which are panels with a single LED.
|
||||
@ -77,7 +78,7 @@ public abstract class Shape extends Panel {
|
||||
}
|
||||
|
||||
HSBType color = state.getHSBForPanel(getPanelId());
|
||||
graphics.setColor(new Color(color.getRGB()));
|
||||
graphics.setColor(new Color(ColorUtil.hsbTosRgb(color)));
|
||||
if (settings.shouldFillWithColor()) {
|
||||
graphics.fillPolygon(p);
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ import org.openhab.binding.nanoleaf.internal.layout.Point2D;
|
||||
import org.openhab.binding.nanoleaf.internal.layout.ShapeType;
|
||||
import org.openhab.binding.nanoleaf.internal.model.PositionDatum;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
import org.openhab.core.util.ColorUtil;
|
||||
|
||||
/**
|
||||
* A single line.
|
||||
@ -123,6 +124,6 @@ public class SingleLine extends Panel {
|
||||
|
||||
private static Color getColor(int panelId, PanelState state) {
|
||||
HSBType color = state.getHSBForPanel(panelId);
|
||||
return new Color(color.getRGB());
|
||||
return new Color(ColorUtil.hsbTosRgb(color));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user