Search in sources :

Example 61 with TimeoutException

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

the class MBrickletLEDStripImpl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    logger.trace("enabling");
    int chipType = BrickletLEDStrip.CHIP_TYPE_WS2801;
    int frameDuration = 100;
    Long clockFrequency = null;
    tinkerforgeDevice = new BrickletLEDStrip(getUid(), getIpConnection());
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("chiptype"))) {
            String chipTypeString = tfConfig.getChiptype();
            if (chipTypeString.equalsIgnoreCase("ws2801")) {
                chipType = BrickletLEDStrip.CHIP_TYPE_WS2801;
            } else if (chipTypeString.equalsIgnoreCase("ws2811")) {
                chipType = BrickletLEDStrip.CHIP_TYPE_WS2811;
            } else if (chipTypeString.equalsIgnoreCase("ws2812")) {
                chipType = BrickletLEDStrip.CHIP_TYPE_WS2812;
            } else {
                logger.error("Unknown ChipType {}", chipTypeString);
            // TODO raise configuration error
            }
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("frameduration"))) {
            frameDuration = tfConfig.getFrameduration();
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("clockfrequency"))) {
            clockFrequency = tfConfig.getClockfrequency();
        }
        // subdevices because subdevices use the ColorMapping
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature(ModelPackage.LED_STRIP_CONFIGURATION__COLOR_MAPPING))) {
            colorMapping = tfConfig.getColorMapping();
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature(ModelPackage.LED_STRIP_CONFIGURATION__SUB_DEVICES))) {
            String[] subdevices = tfConfig.getSubDevices().trim().split("\\s+");
            for (String subId : subdevices) {
                addSubdevice(subId);
            }
        }
    }
    logger.debug("chipType is {}", chipType);
    logger.debug("frameDuration is {}", frameDuration);
    logger.debug("colorMapping is {}", colorMapping);
    try {
        tinkerforgeDevice.setChipType(chipType);
        tinkerforgeDevice.setFrameDuration(frameDuration);
        if (clockFrequency != null) {
            logger.debug("clockFrequency is {}", clockFrequency);
            tinkerforgeDevice.setClockFrequency(clockFrequency);
        } else {
            logger.debug("clockFrequency is not set");
        }
    } 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 : MBrickletLEDStrip(org.openhab.binding.tinkerforge.internal.model.MBrickletLEDStrip) BrickletLEDStrip(com.tinkerforge.BrickletLEDStrip) NotConnectedException(com.tinkerforge.NotConnectedException) TimeoutException(com.tinkerforge.TimeoutException)

Example 62 with TimeoutException

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

the class MBrickletHallEffectImpl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    logger.trace("enabling");
    setCallbackPeriod(1);
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
            logger.trace("got callback period {}", tfConfig.getCallbackPeriod());
            setCallbackPeriod(tfConfig.getCallbackPeriod());
        }
    }
    try {
        tinkerforgeDevice = new BrickletHallEffect(getUid(), getIpConnection());
        tinkerforgeDevice.setEdgeCountCallbackPeriod(getCallbackPeriod());
        listener = new EdgeCountListener();
        logger.trace("adding listener");
        tinkerforgeDevice.addEdgeCountListener(listener);
        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 : NotConnectedException(com.tinkerforge.NotConnectedException) BrickletHallEffect(com.tinkerforge.BrickletHallEffect) MBrickletHallEffect(org.openhab.binding.tinkerforge.internal.model.MBrickletHallEffect) TimeoutException(com.tinkerforge.TimeoutException)

Example 63 with TimeoutException

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

the class MBrickletLCD20x4Impl method write.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void write(String newText) {
    String oldText = text;
    text = newText;
    // TODO check if there are changes
    logger.debug("setText: {}", newText);
    try {
        if (text == null || text.equals("")) {
            tinkerforgeDevice.clearDisplay();
        } else if (text.startsWith(positionPrefix)) {
            int indexOfSuffix = text.indexOf(positonSuffix);
            if (indexOfSuffix == -1 || indexOfSuffix > positionPrefix.length() + 3) {
                logger.error("no valid suffix found");
                displayError("no valid suffix");
            } else {
                try {
                    short lineNum = (short) Integer.parseInt(text.substring(positionPrefix.length(), positionPrefix.length() + 1));
                    short inLinePostition = (short) Integer.parseInt(text.substring(positionPrefix.length() + 1, indexOfSuffix));
                    if (lineNum < 0 || lineNum > 3) {
                        logger.error("line number must have a value from 0 - 3");
                        displayError("faulty line number");
                    } else if (inLinePostition < 0 || inLinePostition > 19) {
                        logger.error("position must have a value from 0 - 19");
                        displayError("faulty position number");
                    } else {
                        String text2show = text.substring(indexOfSuffix + 1);
                        if (text2show.length() == 0) {
                            // TODO
                            text2show = "                    ";
                        }
                        // clear
                        // line
                        tinkerforgeDevice.writeLine(lineNum, inLinePostition, text2show);
                    }
                } catch (NumberFormatException e) {
                    logger.error("found erroneous line numbers: ", e);
                    displayError("faulty numbers");
                }
            }
        } else {
            tinkerforgeDevice.clearDisplay();
            int lineSize = 19;
            int lineNum = 0;
            for (int i = 0; i < text.length(); i += lineSize) {
                if (lineNum > 3) {
                    break;
                }
                tinkerforgeDevice.writeLine((short) lineNum, (short) 0, text.substring(i, Math.min(text.length(), i + lineSize)));
                lineNum++;
            }
        }
        if (eNotificationRequired()) {
            eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MBRICKLET_LCD2_0X4__TEXT, oldText, text));
        }
    } 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) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) TimeoutException(com.tinkerforge.TimeoutException)

Example 64 with TimeoutException

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

the class MBrickletHumidityImpl method fetchSensorValue.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void fetchSensorValue() {
    try {
        int humidity = tinkerforgeDevice.getHumidity();
        DecimalValue value = Tools.calculate10(humidity);
        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) TimeoutException(com.tinkerforge.TimeoutException)

Example 65 with TimeoutException

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

the class MBrickletIO16Impl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    tinkerforgeDevice = new BrickletIO16(getUid(), getIpConnection());
    if (tfConfig != null) {
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("debouncePeriod"))) {
            setDebouncePeriod(tfConfig.getDebouncePeriod());
        }
    }
    // enable interrupts for all pins
    try {
        tinkerforgeDevice.setResponseExpectedAll(true);
        logger.debug("{} BrickletIO16 setting debouncePeriod to {}", LoggerConstants.TFINIT, getDebouncePeriod());
        tinkerforgeDevice.setDebouncePeriod(getDebouncePeriod());
        tinkerforgeDevice.setPortInterrupt('a', (short) 255);
        tinkerforgeDevice.setPortInterrupt('b', (short) 255);
    } 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) BrickletIO16(com.tinkerforge.BrickletIO16) NotConnectedException(com.tinkerforge.NotConnectedException) 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