Search in sources :

Example 1 with BrickDC

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

the class MBrickDCImpl method setTinkerforgeDevice.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated
     */
@Override
public void setTinkerforgeDevice(BrickDC newTinkerforgeDevice) {
    BrickDC oldTinkerforgeDevice = tinkerforgeDevice;
    tinkerforgeDevice = newTinkerforgeDevice;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MBRICK_DC__TINKERFORGE_DEVICE, oldTinkerforgeDevice, tinkerforgeDevice));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) MBrickDC(org.openhab.binding.tinkerforge.internal.model.MBrickDC) BrickDC(com.tinkerforge.BrickDC)

Example 2 with BrickDC

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

the class MBrickDCImpl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    tinkerforgeDevice = new BrickDC(uid, ipConnection);
    if (tfConfig != null) {
        logger.debug("found tfConfig");
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("acceleration"))) {
            setAcceleration(tfConfig.getAcceleration());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("pwmFrequency"))) {
            setPwmFrequency(tfConfig.getPwmFrequency());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("driveMode"))) {
            setDriveMode(DCDriveMode.get(tfConfig.getDriveMode()));
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("threshold"))) {
            setThreshold(tfConfig.getThreshold());
        }
        if (tfConfig.eIsSet(tfConfig.eClass().getEStructuralFeature("callbackPeriod"))) {
            setCallbackPeriod(tfConfig.getCallbackPeriod());
        }
    }
    try {
        tinkerforgeDevice.setPWMFrequency(pwmFrequency);
        if (driveMode == DCDriveMode.BRAKE) {
            tinkerforgeDevice.setDriveMode(BrickDC.DRIVE_MODE_DRIVE_BRAKE);
        } else if (driveMode == DCDriveMode.COAST) {
            tinkerforgeDevice.setDriveMode(BrickDC.DRIVE_MODE_DRIVE_COAST);
        }
        tinkerforgeDevice.setCurrentVelocityPeriod((int) callbackPeriod);
        listener = new VelocityListener();
        tinkerforgeDevice.addCurrentVelocityListener(listener);
        tinkerforgeDevice.enable();
        handleVelocity(tinkerforgeDevice.getVelocity(), false);
    } 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) MBrickDC(org.openhab.binding.tinkerforge.internal.model.MBrickDC) BrickDC(com.tinkerforge.BrickDC) TimeoutException(com.tinkerforge.TimeoutException)

Aggregations

BrickDC (com.tinkerforge.BrickDC)2 MBrickDC (org.openhab.binding.tinkerforge.internal.model.MBrickDC)2 NotConnectedException (com.tinkerforge.NotConnectedException)1 TimeoutException (com.tinkerforge.TimeoutException)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1