Search in sources :

Example 56 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class JoystickXPositionImpl method fetchSensorValue.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    try {
        Position position = tinkerforgeDevice.getPosition();
        DecimalValue value = Tools.calculate(position.x);
        setSensorValue(value);
    } 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 : DecimalValue(org.openhab.binding.tinkerforge.internal.types.DecimalValue) NotConnectedException(com.tinkerforge.NotConnectedException) Position(com.tinkerforge.BrickletJoystick.Position) JoystickXPosition(org.openhab.binding.tinkerforge.internal.model.JoystickXPosition) TimeoutException(com.tinkerforge.TimeoutException)

Example 57 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class LEDGroupImpl method fetchSwitchState.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void fetchSwitchState() {
    if (ledList.getTrackingled() != null) {
        try {
            RGBValues rgbValues = tinkerforgeDevice.getRGBValues(ledList.getTrackingled(), (short) 1);
            short[] r = rgbValues.r;
            short[] g = rgbValues.g;
            short[] b = rgbValues.b;
            if (r[0] == 0 && g[0] == 0 && b[0] == 0) {
                setSwitchState(OnOffValue.OFF);
            } else {
                setSwitchState(OnOffValue.ON);
            }
        } catch (TimeoutException e) {
            TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
        } catch (NotConnectedException e) {
            TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
        }
    } else {
        setSwitchState(OnOffValue.UNDEF);
    }
}
Also used : NotConnectedException(com.tinkerforge.NotConnectedException) RGBValues(com.tinkerforge.BrickletLEDStrip.RGBValues) TimeoutException(com.tinkerforge.TimeoutException)

Example 58 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class DigitalSensorIO4Impl method fetchSensorValue.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    HighLowValue value = HighLowValue.UNDEF;
    try {
        value = extractValue(getMbrick().getTinkerforgeDevice().getValue());
        setSensorValue(value);
    } 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) HighLowValue(org.openhab.binding.tinkerforge.internal.types.HighLowValue) TimeoutException(com.tinkerforge.TimeoutException)

Example 59 with NotConnectedException

use of com.tinkerforge.NotConnectedException in project openhab1-addons by openhab.

the class DigitalSensorImpl method enable.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    setSensorValue(HighLowValue.UNDEF);
    if (tfConfig != null) {
        logger.debug("{} found config for DigitalSensor", LoggerConstants.TFINIT);
        setPullUpResistorEnabled(tfConfig.isPullUpResistorEnabled());
        logger.debug("{} pull-up resistor state is {}", LoggerConstants.TFINIT, isPullUpResistorEnabled());
    }
    MBrickletIO16 bricklet = getMbrick();
    if (bricklet == null) {
        logger.error("{} No bricklet found for DigitalSensor: {} ", LoggerConstants.TFINIT, subId);
    } else {
        BrickletIO16 brickletIO16 = bricklet.getTinkerforgeDevice();
        try {
            logger.debug("{} setting InterruptListener for DigitalSensor: {} ", LoggerConstants.TFINIT, subId);
            interruptListener = new InterruptListener();
            brickletIO16.addInterruptListener(interruptListener);
            brickletIO16.setPortConfiguration(getPort(), (short) mask, BrickletIO16.DIRECTION_IN, isPullUpResistorEnabled());
            fetchSensorValue();
        } 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 : MBrickletIO16(org.openhab.binding.tinkerforge.internal.model.MBrickletIO16) MBrickletIO16(org.openhab.binding.tinkerforge.internal.model.MBrickletIO16) BrickletIO16(com.tinkerforge.BrickletIO16) NotConnectedException(com.tinkerforge.NotConnectedException) TimeoutException(com.tinkerforge.TimeoutException)

Example 60 with NotConnectedException

use of com.tinkerforge.NotConnectedException 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

NotConnectedException (com.tinkerforge.NotConnectedException)107 TimeoutException (com.tinkerforge.TimeoutException)107 DecimalValue (org.openhab.binding.tinkerforge.internal.types.DecimalValue)36 HighLowValue (org.openhab.binding.tinkerforge.internal.types.HighLowValue)14 OnOffValue (org.openhab.binding.tinkerforge.internal.types.OnOffValue)8 BigDecimal (java.math.BigDecimal)4 Color (java.awt.Color)3 BrickServo (com.tinkerforge.BrickServo)2 BrickletColor (com.tinkerforge.BrickletColor)2 LEDState (com.tinkerforge.BrickletDualButton.LEDState)2 BrickletIO16 (com.tinkerforge.BrickletIO16)2 BrickletIO4 (com.tinkerforge.BrickletIO4)2 Position (com.tinkerforge.BrickletJoystick.Position)2 BrickletMultiTouch (com.tinkerforge.BrickletMultiTouch)2 BrickletTemperatureIR (com.tinkerforge.BrickletTemperatureIR)2 HashMap (java.util.HashMap)2 ConfigurationException (org.openhab.binding.tinkerforge.internal.config.ConfigurationException)2 MBrickletIO16 (org.openhab.binding.tinkerforge.internal.model.MBrickletIO16)2 MBrickletIO4 (org.openhab.binding.tinkerforge.internal.model.MBrickletIO4)2 LinePositionText (org.openhab.binding.tinkerforge.internal.tools.LinePositionText)2