当前位置: 首页>>代码示例>>Java>>正文


Java HSBType类代码示例

本文整理汇总了Java中org.eclipse.smarthome.core.library.types.HSBType的典型用法代码示例。如果您正苦于以下问题:Java HSBType类的具体用法?Java HSBType怎么用?Java HSBType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HSBType类属于org.eclipse.smarthome.core.library.types包,在下文中一共展示了HSBType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromXY

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
/**
 * Returns a HSBType object representing the provided xy color values in CIE XY color model.
 * Conversion from CIE XY color model to sRGB using D65 reference white
 * Returned color is set to full brightness
 *
 * @param x, y color information 0.0 - 1.0
 *
 * @return new HSBType object representing the given CIE XY color, full brightness
 */
public static HSBType fromXY(float x, float y) {
    float Yo = 1.0f;
    float X = (Yo / y) * x;
    float Z = (Yo / y) * (1.0f - x - y);

    float r = X * Xy2Rgb[0][0] + Yo * Xy2Rgb[0][1] + Z * Xy2Rgb[0][2];
    float g = X * Xy2Rgb[1][0] + Yo * Xy2Rgb[1][1] + Z * Xy2Rgb[1][2];
    float b = X * Xy2Rgb[2][0] + Yo * Xy2Rgb[2][1] + Z * Xy2Rgb[2][2];

    float max = r > g ? r : g;
    if (b > max) {
        max = b;
    }

    r = gammaCompress(r / max);
    g = gammaCompress(g / max);
    b = gammaCompress(b / max);

    return HSBType.fromRGB((int) (r * 255.0f + 0.5f), (int) (g * 255.0f + 0.5f), (int) (b * 255.0f + 0.5f));
}
 
开发者ID:openhab,项目名称:org.openhab.binding.zigbee,代码行数:30,代码来源:ColorHelper.java

示例2: toXY

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
/**
 * 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 static PercentType[] toXY(HSBType HSB) {
    // This makes sure we keep color information even if brightness is zero
    PercentType sRGB[] = new HSBType(HSB.getHue(), HSB.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 * HSB.getBrightness().floatValue()).toString()) };
}
 
开发者ID:openhab,项目名称:org.openhab.binding.zigbee,代码行数:29,代码来源:ColorHelper.java

示例3: handleUpdate

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public void handleUpdate(ChannelUID channelUID, State newState) {
    logger.debug("Update {} for channel {} received", newState, channelUID);
    switch (channelUID.getId()) {
        case CHANNEL_BRIGHTNESS:
            if (newState instanceof PercentType) {
                lastBrigthness = ((PercentType) newState).intValue();
            }
            break;
        case CHANNEL_COLOR:
            if (newState instanceof HSBType) {
                lastColor = ((HSBType) newState).getRGB();
            }
            break;
        case CHANNEL_GATEWAY_VOLUME:
            if (newState instanceof DecimalType) {
                updateLastVolume((DecimalType) newState);
            }
            break;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:22,代码来源:XiaomiActorGatewayHandler.java

示例4: handleCommand

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public boolean handleCommand(String channelID, Connection connection, Command command,
        TPLinkSmartHomeConfiguration configuration) throws IOException {
    int transitionPeriod = configuration.transitionPeriod;
    HasErrorResponse response;

    if (command instanceof OnOffType) {
        response = handleOnOffType(channelID, connection, (OnOffType) command, transitionPeriod);
    } else if (command instanceof HSBType) {
        response = handleHSBType(channelID, connection, (HSBType) command, transitionPeriod);
    } else if (command instanceof DecimalType) {
        response = handleDecimalType(channelID, connection, (DecimalType) command, transitionPeriod);
    } else {
        return false;
    }
    checkErrors(response);
    return response != null;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:19,代码来源:BulbDevice.java

示例5: handleCommand

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    try {
        if (command instanceof OnOffType) {
            handleOnOff((OnOffType) command);
        } else if (command instanceof HSBType) {
            handleColor(channelUID, (HSBType) command);
        } else if (command instanceof PercentType) {
            handlePercentage(channelUID, (PercentType) command);
        } else if (command instanceof StringType) {
            handleString(channelUID, (StringType) command);
        }
    } catch (IOException e) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, e.getMessage());
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:FeicanHandler.java

示例6: setHue

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setHue(Double value) throws Exception {
    if (value == null) {
        value = 0.0;
    }
    State state = getItem().getStateAs(HSBType.class);
    if (state instanceof HSBType) {
        HSBType hsb = (HSBType) state;
        HSBType newState = new HSBType(new DecimalType(value), hsb.getSaturation(), hsb.getBrightness());
        ((ColorItem) getItem()).send(newState);
        return CompletableFuture.completedFuture(null);
    } else {
        // state is undefined (light is not connected)
        return CompletableFuture.completedFuture(null);
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:HomekitColorfulLightbulbImpl.java

示例7: setSaturation

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setSaturation(Double value) throws Exception {
    if (value == null) {
        value = 0.0;
    }
    State state = getItem().getStateAs(HSBType.class);
    if (state instanceof HSBType) {
        HSBType hsb = (HSBType) state;
        HSBType newState = new HSBType(hsb.getHue(), new PercentType(value.intValue()), hsb.getBrightness());
        ((ColorItem) getItem()).send(newState);
        return CompletableFuture.completedFuture(null);
    } else {
        // state is undefined (light is not connected)
        return CompletableFuture.completedFuture(null);
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:HomekitColorfulLightbulbImpl.java

示例8: setBrightness

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public CompletableFuture<Void> setBrightness(Integer value) throws Exception {
    if (value == null) {
        value = 0;
    }
    State state = getItem().getStateAs(HSBType.class);
    if (state instanceof HSBType) {
        HSBType hsb = (HSBType) state;
        HSBType newState = new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(value));
        ((ColorItem) getItem()).send(newState);
        return CompletableFuture.completedFuture(null);
    } else {
        // state is undefined (light is not connected)
        return CompletableFuture.completedFuture(null);
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:17,代码来源:HomekitColorfulLightbulbImpl.java

示例9: perform

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public void perform(AbstractDevice device, Item item, String value) {
    if (value == null || value.length() != 8) {
        logger.error("Invalid parameter: '{}'. Format must be 'aarrggbb'.", value);
        return;
    }

    int r = Integer.parseInt(value.substring(2, 4), 16);
    int g = Integer.parseInt(value.substring(4, 6), 16);
    int b = Integer.parseInt(value.substring(6, 8), 16);

    ItemCommandEvent event;
    if (r == 0 && g == 0 && b == 0) {
        event = ItemEventFactory.createCommandEvent(item.getName(), OnOffType.OFF, COMMAND_SOURCE);
    } else {
        HSBType hsbValue = HSBType.fromRGB(r, g, b);
        event = ItemEventFactory.createCommandEvent(item.getName(), hsbValue, COMMAND_SOURCE);
    }

    eventPublisher.post(event);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:22,代码来源:SetColorAction.java

示例10: handleCommand

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
public void handleCommand(final Command command) {
    try {
        if (command instanceof HSBType) {
            HSBType current = currentHSB;
            HSBType color = (HSBType) command;
            PercentType brightness = color.getBrightness();

            boolean changeColor = true;
            if (delayedColorChange) {
                // Color conversion (HUE -> XY -> HUE) makes this necessary due to rounding & precision
                int changeSensitivity = supportsHue ? 0 : 1;
                changeColor = Math.abs(current.getHue().intValue() - color.getHue().intValue()) > changeSensitivity
                        || Math.abs(current.getSaturation().intValue()
                                - color.getSaturation().intValue()) > changeSensitivity;
            }

            if (brightness.intValue() != currentHSB.getBrightness().intValue()) {
                changeBrightness(brightness);
                if (changeColor && delayedColorChange) {
                    Thread.sleep(1100);
                }
            }

            if (changeColor) {
                if (supportsHue) {
                    changeColorHueSaturation(color);
                } else {
                    changeColorXY(color);
                }
            }
        } else if (command instanceof PercentType) {
            changeBrightness((PercentType) command);
        } else if (command instanceof OnOffType) {
            changeOnOff((OnOffType) command);
        }
    } catch (InterruptedException | ExecutionException e) {
        logger.warn("{}: Exception processing command", endpoint.getIeeeAddress(), e);
    }
}
 
开发者ID:openhab,项目名称:org.openhab.binding.zigbee,代码行数:41,代码来源:ZigBeeConverterColorColor.java

示例11: updateBrightness

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
private void updateBrightness(PercentType brightness) {
    // Extra temp variable to avoid thread sync concurrency issues on currentUSB
    HSBType oldHSB = currentHSB;
    HSBType newHSB = new HSBType(oldHSB.getHue(), oldHSB.getSaturation(), brightness);
    currentHSB = newHSB;
    lastBrightness = brightness;
    updateChannelState(newHSB);
}
 
开发者ID:openhab,项目名称:org.openhab.binding.zigbee,代码行数:9,代码来源:ZigBeeConverterColorColor.java

示例12: updateColorHSB

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
private void updateColorHSB(DecimalType hue, PercentType saturation) {
    // Extra temp variable to avoid thread sync concurrency issues on currentUSB
    HSBType oldHSB = currentHSB;
    HSBType newHSB = new HSBType(hue, saturation, oldHSB.getBrightness());
    currentHSB = newHSB;
    updateChannelState(newHSB);
}
 
开发者ID:openhab,项目名称:org.openhab.binding.zigbee,代码行数:8,代码来源:ZigBeeConverterColorColor.java

示例13: fromHSBType

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
/**
 * Construct from {@link HSBType}.
 *
 * @param hsbType
 *            {@link HSBType}
 * @return {@link TradfriColor} object with converted color spaces
 */
public static TradfriColor fromHSBType(final HSBType hsbType) {

	// hsbType gives 0 to 100, we need 0.0 to 255.0
	final double red = hsbType.getRed().intValue() * 2.55;
	final double green = hsbType.getGreen().intValue() * 2.55;
	final double blue = hsbType.getBlue().intValue() * 2.55;

	final int brightness = (int) (hsbType.getBrightness().intValue() * 2.54);
	return fromRGBValues(red, green, blue, brightness);
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:18,代码来源:TradfriColor.java

示例14: fromRGBValues

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
public static TradfriColor fromRGBValues(final double red, final double green, final double blue,
		final int brightness) {
	// saved for later use in constructor call
	final int rgbR = (int) red;
	final int rgbG = (int) green;
	final int rgbB = (int) blue;

	// gamma correction - disabled for now - needs tweaking
	// red = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red /
	// 12.92);
	// green = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) :
	// (green / 12.92);
	// blue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) :
	// (blue / 12.92);

	// Wide RGB D65 conversion
	// math inspiration:
	// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
	final double X = (red * 0.664511) + (green * 0.154324) + (blue * 0.162028);
	final double Y = (red * 0.283881) + (green * 0.668433) + (blue * 0.047685);
	final double Z = (red * 0.000088) + (green * 0.072310) + (blue * 0.986039);

	// calculate the xy values from XYZ
	final double x = (X / (X + Y + Z));
	final double y = (Y / (X + Y + Z));

	final int xyX = normalize(x);
	final int xyY = normalize(y);

	// construct new hsbType with the calculated concrete values
	final HSBType hsbTypeConcreteValues = constructHsbTypeFromRgbWithBrightnessPercent(rgbR, rgbG, rgbB,
			brightness);

	return new TradfriColor(rgbR, rgbG, rgbB, xyX, xyY, brightness, hsbTypeConcreteValues);
}
 
开发者ID:comdata,项目名称:HomeAutomation,代码行数:36,代码来源:TradfriColor.java

示例15: parseDefault

import org.eclipse.smarthome.core.library.types.HSBType; //导入依赖的package包/类
@Override
void parseDefault(JsonObject data) {
    if (data.has(RGB)) {
        long rgb = data.get(RGB).getAsLong();
        updateState(CHANNEL_BRIGHTNESS, new PercentType((int) (((rgb >> 24) & 0xff))));
        updateState(CHANNEL_COLOR,
                HSBType.fromRGB((int) (rgb >> 16) & 0xff, (int) (rgb >> 8) & 0xff, (int) rgb & 0xff));
    }
    if (data.has(ILLUMINATION)) {
        int illu = data.get(ILLUMINATION).getAsInt();
        updateState(CHANNEL_ILLUMINATION, new DecimalType(illu));
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:14,代码来源:XiaomiActorGatewayHandler.java


注:本文中的org.eclipse.smarthome.core.library.types.HSBType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。