Search in sources :

Example 6 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class ColorColorImpl method fetchSensorValue.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    try {
        com.tinkerforge.BrickletColor.Color color = tinkerforgeDevice.getColor();
        setSensorValue(new HSBValue(new HSBType(new Color(getRGBValue(color.r), getRGBValue(color.g), getRGBValue(color.b)))));
    } catch (TimeoutException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
    } catch (NotConnectedException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
    }
}
Also used : NotConnectedException(com.tinkerforge.NotConnectedException) MBrickletColor(org.openhab.binding.tinkerforge.internal.model.MBrickletColor) BrickletColor(com.tinkerforge.BrickletColor) Color(java.awt.Color) ColorColor(org.openhab.binding.tinkerforge.internal.model.ColorColor) MBrickletColor(org.openhab.binding.tinkerforge.internal.model.MBrickletColor) BrickletColor(com.tinkerforge.BrickletColor) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue) HSBType(org.openhab.core.library.types.HSBType) TimeoutException(com.tinkerforge.TimeoutException)

Example 7 with HSBValue

use of org.openhab.binding.tinkerforge.internal.types.HSBValue in project openhab1-addons by openhab.

the class MBrickletLEDStripImpl method setSelectedColor.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void setSelectedColor(HSBType color, DeviceOptions opts) {
    logger.debug("setSelectedColor called");
    // ColorMapping may be overridden by itemConfiguration
    char[] colorMapping = getColorMapping().toCharArray();
    String leds = null;
    // handle options
    if (opts != null) {
        if (opts.containsKey(COLOR_MAPPING)) {
            logger.debug("custom color mapping {} ", opts.getOption(COLOR_MAPPING));
            colorMapping = opts.getOption(COLOR_MAPPING).toCharArray();
        }
        if (opts.containsKey(LEDS)) {
            leds = opts.getOption(LEDS).trim();
            logger.debug("leds: {}", leds);
        }
    }
    if (leds == null || leds.length() == 0) {
        logger.error("\"leds\" option missing or empty, items configuration has to be fixed!");
        return;
    }
    // get the rgb values from HSBType
    Color rgbColor = color.toColor();
    short red = (short) rgbColor.getRed();
    short green = (short) rgbColor.getGreen();
    short blue = (short) rgbColor.getBlue();
    logger.debug("rgb is: {}:{}:{}", red, green, blue);
    // construct the values for the setRGBValues call
    HashMap<Character, short[]> colorMap = new HashMap<Character, short[]>(3);
    short[] reds = { red, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red };
    short[] greens = { green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green };
    short[] blues = { blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue };
    colorMap.put('r', reds);
    colorMap.put('g', greens);
    colorMap.put('b', blues);
    LedList ledList = Tools.parseLedString(leds);
    try {
        if (ledList.hasLedRanges()) {
            Map<Integer, Short> ledRanges = ledList.getLedRanges();
            for (Integer led : ledRanges.keySet()) {
                tinkerforgeDevice.setRGBValues(led, ledRanges.get(led), colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
            }
        }
        if (ledList.hasLeds()) {
            for (Integer led : ledList.getLedNumbers()) {
                tinkerforgeDevice.setRGBValues(led, (short) 1, colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2]));
            }
        }
        setColor(new HSBValue(color));
    } catch (TimeoutException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
    } catch (NotConnectedException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
    }
}
Also used : NotConnectedException(com.tinkerforge.NotConnectedException) HashMap(java.util.HashMap) Color(java.awt.Color) LedList(org.openhab.binding.tinkerforge.internal.tools.LedList) HSBValue(org.openhab.binding.tinkerforge.internal.types.HSBValue) TimeoutException(com.tinkerforge.TimeoutException)

Aggregations

HSBValue (org.openhab.binding.tinkerforge.internal.types.HSBValue)7 NotConnectedException (com.tinkerforge.NotConnectedException)3 TimeoutException (com.tinkerforge.TimeoutException)3 Color (java.awt.Color)3 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)3 HashMap (java.util.HashMap)2 BrickletColor (com.tinkerforge.BrickletColor)1 TinkerforgeBindingProvider (org.openhab.binding.tinkerforge.TinkerforgeBindingProvider)1 ColorColor (org.openhab.binding.tinkerforge.internal.model.ColorColor)1 MBrickletColor (org.openhab.binding.tinkerforge.internal.model.MBrickletColor)1 LedList (org.openhab.binding.tinkerforge.internal.tools.LedList)1 DecimalValue (org.openhab.binding.tinkerforge.internal.types.DecimalValue)1 DirectionValue (org.openhab.binding.tinkerforge.internal.types.DirectionValue)1 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)1 OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)1 PercentValue (org.openhab.binding.tinkerforge.internal.types.PercentValue)1 ColorItem (org.openhab.core.library.items.ColorItem)1 ContactItem (org.openhab.core.library.items.ContactItem)1 DimmerItem (org.openhab.core.library.items.DimmerItem)1 NumberItem (org.openhab.core.library.items.NumberItem)1