diff --git a/hal-core/src/se/hal/struct/devicedata/ColorEventData.java b/hal-core/src/se/hal/struct/devicedata/ColorEventData.java index f6e54b04..9a072658 100644 --- a/hal-core/src/se/hal/struct/devicedata/ColorEventData.java +++ b/hal-core/src/se/hal/struct/devicedata/ColorEventData.java @@ -24,9 +24,7 @@ package se.hal.struct.devicedata; import se.hal.intf.HalEventData; import zutil.ColorUtil; -import zutil.converter.Converter; -import java.awt.*; import java.awt.color.ColorSpace; /** @@ -96,10 +94,6 @@ public class ColorEventData extends HalEventData { return ColorUtil.getLightness(red, green, blue); } - public float[] getCieXYZ() { - return cieXYZ.fromRGB(new float[]{red, green, blue}); - } - public String getHex() { return ColorUtil.getHexString(red, green, blue); } diff --git a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeColorConfig.java b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeColorConfig.java index 5293feca..7db0fe60 100644 --- a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeColorConfig.java +++ b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeColorConfig.java @@ -6,9 +6,11 @@ import com.zsmartsystems.zigbee.zcl.ZclCluster; import com.zsmartsystems.zigbee.zcl.ZclCommand; import com.zsmartsystems.zigbee.zcl.clusters.ZclColorControlCluster; import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToColorCommand; +import com.zsmartsystems.zigbee.zcl.clusters.colorcontrol.MoveToHueAndSaturationCommand; import se.hal.intf.HalDeviceData; import se.hal.intf.HalEventConfig; import se.hal.intf.HalEventData; +import se.hal.plugin.zigbee.util.Cie; import se.hal.struct.devicedata.ColorEventData; import zutil.log.LogUtil; @@ -32,9 +34,11 @@ public class ZigbeeColorConfig extends ZigbeeHalEventDeviceConfig implements Hal try { ZclAttribute attribute = cluster.getAttribute(ZclColorControlCluster.ATTR_CURRENTHUE); + //attribute.setReporting(1, 900).get(); attribute.readValue(60); attribute = cluster.getAttribute(ZclColorControlCluster.ATTR_CURRENTSATURATION); + //attribute.setReporting(1, 900).get(); attribute.readValue(60); } catch (Exception e) { logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e); @@ -67,8 +71,23 @@ public class ZigbeeColorConfig extends ZigbeeHalEventDeviceConfig implements Hal if (! (data instanceof ColorEventData)) return null; - float[] cieXYZ = ((ColorEventData) data).getCieXYZ(); - return new MoveToColorCommand((int) (cieXYZ[0] * 65536), (int) (cieXYZ[2] * 65536), 1); + //float[] cie = ((ColorEventData) data).getCieXYZ(); + //int x = (int) (cie[0] * 65536); + //int y = (int) (cie[1] * 65536); + Cie cie = Cie.rgb2cie(((ColorEventData) data).getRed(), ((ColorEventData) data).getGreen(), ((ColorEventData) data).getBlue()); + int x = (int) (cie.x * 65536); + int y = (int) (cie.y * 65536); + + if (x > 65279) + x = 65279; + if (y > 65279) + y = 65279; + + return new MoveToColorCommand(x, y, 10); + + //double hue = ((ColorEventData) data).getHue() * 254.0f / 360.0f + 0.5f; + //double saturation = ((ColorEventData) data).getSaturation() * 256; + //return new MoveToHueAndSaturationCommand((int) hue, (int) saturation, 1); } // -------------------------- diff --git a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeLevelConfig.java b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeLevelConfig.java index a63e0152..7ac657ba 100644 --- a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeLevelConfig.java +++ b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeLevelConfig.java @@ -32,7 +32,7 @@ public class ZigbeeLevelConfig extends ZigbeeHalEventDeviceConfig implements Hal try { ZclAttribute attribute = cluster.getAttribute(ZclLevelControlCluster.ATTR_CURRENTLEVEL); - attribute.setReporting(1, 900).get(); + //attribute.setReporting(1, 900).get(); attribute.readValue(60); } catch (Exception e) { logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e); diff --git a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOccupancyConfig.java b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOccupancyConfig.java index c1b8bc1d..ba7af243 100644 --- a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOccupancyConfig.java +++ b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOccupancyConfig.java @@ -30,7 +30,7 @@ public class ZigbeeOccupancyConfig extends ZigbeeHalEventDeviceConfig implements try { ZclAttribute attribute = cluster.getAttribute(ZclOccupancySensingCluster.ATTR_OCCUPANCY); - attribute.setReporting(1, 900).get(); + //attribute.setReporting(1, 900).get(); attribute.readValue(60); } catch (Exception e) { logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e); diff --git a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOnOffConfig.java b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOnOffConfig.java index 2b06717c..13a8006a 100644 --- a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOnOffConfig.java +++ b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/device/ZigbeeOnOffConfig.java @@ -33,7 +33,7 @@ public class ZigbeeOnOffConfig extends ZigbeeHalEventDeviceConfig implements Hal try { ZclAttribute attribute = cluster.getAttribute(ZclOnOffCluster.ATTR_ONOFF); - attribute.setReporting(1, 900).get(); + //attribute.setReporting(1, 900).get(); attribute.readValue(60); } catch (Exception e) { logger.log(Level.WARNING, "Was unable to initialize cluster reporting rate.", e); diff --git a/plugins/hal-zigbee/src/se/hal/plugin/zigbee/util/Cie.java b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/util/Cie.java new file mode 100644 index 00000000..2ed46995 --- /dev/null +++ b/plugins/hal-zigbee/src/se/hal/plugin/zigbee/util/Cie.java @@ -0,0 +1,1950 @@ +/** + * Copyright (c) 2016-2023 by the respective copyright holders. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package se.hal.plugin.zigbee.util; + +/** + * Provides methods to convert colours from RGB to CIE colour space. + *

+ * The CIE XYZ color space encompasses all color sensations that an average + * person can experience. It serves as a standard reference against which many + * other color spaces are defined. + */ +public class Cie { + public double x; + public double y; + + public static Cie rgb2cie(double r, double g, double b) { + double X; + double Y; + double Z; + + if (r <= 0.04045) { + r = r / 12; + } else { + r = (float) Math.pow((r + 0.055) / 1.055, 2.4); + } + + if (g <= 0.04045) { + g = g / 12; + } else { + g = (float) Math.pow((g + 0.055) / 1.055, 2.4); + } + + if (b <= 0.04045) { + b = b / 12; + } else { + b = (float) Math.pow((b + 0.055) / 1.055, 2.4); + } + + X = 0.436052025f * r + 0.385081593f * g + 0.143087414f * b; + Y = 0.222491598f * r + 0.71688606f * g + 0.060621486f * b; + Z = 0.013929122f * r + 0.097097002f * g + 0.71418547f * b; + + double x; + double y; + + double sum = X + Y + Z; + if (sum != 0) { + x = X / sum; + y = Y / sum; + } else { + float Xr = 0.964221f; // reference white + float Yr = 1.0f; + float Zr = 0.825211f; + + x = Xr / (Xr + Yr + Zr); + y = Yr / (Xr + Yr + Zr); + } + Cie cie = new Cie(); + cie.x = x; + cie.y = y; + return cie; + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +