@Override public SortedMap<String, PrimitiveType> getConstituents() { TreeMap<String, PrimitiveType> map = new TreeMap<>(); map.put(KEY_HUE, getHue()); map.put(KEY_SATURATION, getSaturation()); map.put(KEY_BRIGHTNESS, getBrightness()); return map; }
@Override public String toFullString() { return getHue() + "," + getSaturation() + "," + getBrightness(); }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof HSBType)) { return false; } HSBType other = (HSBType) obj; if (!getHue().equals(other.getHue()) || !getSaturation().equals(other.getSaturation()) || !getBrightness().equals(other.getBrightness())) { return false; } return true; }
@Override public int hashCode() { int tmp = 10000 * getHue().hashCode(); tmp += 100 * getSaturation().hashCode(); tmp += getBrightness().hashCode(); return tmp; }
/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }
DecimalType hue = ((HSBType) currentState).getHue(); PercentType saturation = ((HSBType) currentState).getSaturation();
@Override public SortedMap<String, PrimitiveType> getConstituents() { TreeMap<String, PrimitiveType> map = new TreeMap<>(); map.put(KEY_HUE, getHue()); map.put(KEY_SATURATION, getSaturation()); map.put(KEY_BRIGHTNESS, getBrightness()); return map; }
@Override public String toFullString() { return getHue() + "," + getSaturation() + "," + getBrightness(); }
private void updateBrightness(PercentType brightness) { // Extra temp variable to avoid thread sync concurrency issues on currentHSB HSBType oldHSB = currentHSB; HSBType newHSB = new HSBType(oldHSB.getHue(), oldHSB.getSaturation(), brightness); currentHSB = newHSB; lastBrightness = brightness; if (currentState.get() && lastColorMode != ColorModeEnum.COLORTEMPERATURE) { updateChannelState(newHSB); } }
private void changeColorHueSaturation(HSBType color) throws InterruptedException, ExecutionException { HSBType oldHSB = currentHSB; currentHSB = new HSBType(color.getHue(), color.getSaturation(), oldHSB.getBrightness()); int hue = (int) (color.getHue().floatValue() * 254.0f / 360.0f + 0.5f); int saturation = percentToLevel(color.getSaturation()); clusterColorControl .moveToHueAndSaturationCommand(hue, saturation, configLevelControl.getDefaultTransitionTime()).get(); }
@Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof HSBType)) { return false; } HSBType other = (HSBType) obj; if (!getHue().equals(other.getHue()) || !getSaturation().equals(other.getSaturation()) || !getBrightness().equals(other.getBrightness())) { return false; } return true; }
private void changeColorXY(HSBType color) throws InterruptedException, ExecutionException { PercentType xy[] = color.toXY(); HSBType oldHSB = currentHSB; currentHSB = new HSBType(color.getHue(), color.getSaturation(), oldHSB.getBrightness()); logger.debug("{}: Change Color HSV ({}, {}, {}) -> XY ({}, {})", endpoint.getIeeeAddress(), color.getHue(), color.getSaturation(), oldHSB.getBrightness(), xy[0], xy[1]); int x = (int) (xy[0].floatValue() / 100.0f * 65536.0f + 0.5f); // up to 65279 int y = (int) (xy[1].floatValue() / 100.0f * 65536.0f + 0.5f); // up to 65279 clusterColorControl.moveToColorCommand(x, y, configLevelControl.getDefaultTransitionTime()).get(); }
private void changeOnOff(OnOffType onoff) throws InterruptedException, ExecutionException { boolean on = onoff == OnOffType.ON; PercentType brightness = on ? PercentType.HUNDRED : PercentType.ZERO; if (clusterLevelControl != null) { changeBrightness(brightness); return; } if (clusterOnOff == null) { logger.warn("{}: ignoring on/off command", endpoint.getIeeeAddress()); return; } HSBType oldHSB = currentHSB; currentHSB = new HSBType(oldHSB.getHue(), oldHSB.getSaturation(), brightness); lastBrightness = brightness; if (on) { clusterOnOff.onCommand().get(); } else { clusterOnOff.offCommand().get(); } }
private void updateColorXY(PercentType x, PercentType y) { HSBType color = HSBType.fromXY(x.floatValue() / 100.0f, y.floatValue() / 100.0f); logger.debug("{}: Update Color XY ({}, {}) -> HSV ({}, {}, {})", endpoint.getIeeeAddress(), x.toString(), y.toString(), color.getHue(), color.getSaturation(), currentHSB.getBrightness()); updateColorHSB(color.getHue(), color.getSaturation()); }
@Override public int hashCode() { int tmp = 10000 * getHue().hashCode(); tmp += 100 * getSaturation().hashCode(); tmp += getBrightness().hashCode(); return tmp; }
/** * Returns the xyY values representing this object's color in CIE XY color model. * Conversion from sRGB to CIE XY using D65 reference white * xy pair contains color information * Y represents relative luminance * * @param HSBType color object * @return PercentType[x, y, Y] values in the CIE XY color model */ public PercentType[] toXY() { // This makes sure we keep color information even if brightness is zero PercentType sRGB[] = new HSBType(getHue(), getSaturation(), PercentType.HUNDRED).toRGB(); float r = gammaDecompress(sRGB[0].floatValue() / 100.0f); float g = gammaDecompress(sRGB[1].floatValue() / 100.0f); float b = gammaDecompress(sRGB[2].floatValue() / 100.0f); float X = r * Rgb2Xy[0][0] + g * Rgb2Xy[0][1] + b * Rgb2Xy[0][2]; float Y = r * Rgb2Xy[1][0] + g * Rgb2Xy[1][1] + b * Rgb2Xy[1][2]; float Z = r * Rgb2Xy[2][0] + g * Rgb2Xy[2][1] + b * Rgb2Xy[2][2]; float x = X / (X + Y + Z); float y = Y / (X + Y + Z); return new PercentType[] { new PercentType(Float.valueOf(x * 100.0f).toString()), new PercentType(Float.valueOf(y * 100.0f).toString()), new PercentType(Float.valueOf(Y * getBrightness().floatValue()).toString()) }; }
private void changeBrightness(PercentType brightness) throws InterruptedException, ExecutionException { if (clusterLevelControl == null) { if (clusterOnOff != null) { changeOnOff(brightness.intValue() == 0 ? OnOffType.OFF : OnOffType.ON); } else { logger.warn("{}: ignoring brightness command", endpoint.getIeeeAddress()); } return; } HSBType oldHSB = currentHSB; currentHSB = new HSBType(oldHSB.getHue(), oldHSB.getSaturation(), brightness); lastBrightness = brightness; int level = percentToLevel(brightness); if (clusterOnOff != null) { if (brightness.equals(PercentType.ZERO)) { clusterOnOff.offCommand(); } else { clusterLevelControl.moveToLevelWithOnOffCommand(level, configLevelControl.getDefaultTransitionTime()) .get(); } } else { clusterLevelControl.moveToLevelCommand(level, configLevelControl.getDefaultTransitionTime()).get(); } }
DecimalType hue = ((HSBType) currentState).getHue(); PercentType saturation = ((HSBType) currentState).getSaturation();