Search in sources :

Example 1 with BrickServo

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

the class MBrickServoImpl method setTinkerforgeDevice.

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

Example 2 with BrickServo

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

the class MServoImpl method setPoint.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public boolean setPoint(Short newPosition, int newVelocity, int newAccelleration) {
    Short max = getMaxPosition();
    Short min = getMinPosition();
    if (newPosition > max) {
        if (this.targetPosition < newPosition) {
            logger.debug("setting value to max speed {}, which is lower than target speed {}", max, newPosition);
            newPosition = max;
        } else {
            logger.debug("max value already reached {}", max);
            return true;
        }
    } else if (newPosition < min) {
        if (this.targetPosition > newPosition) {
            logger.debug("setting velocity to min speed {}, which is higher than target speed {}", min, newPosition);
            newPosition = min;
        } else {
            logger.debug("min value already reached {}", min);
            return true;
        }
    }
    try {
        BrickServo tinkerBrickServo = getMbrick().getTinkerforgeDevice();
        tinkerBrickServo.setVelocity(servoNum, newVelocity);
        tinkerBrickServo.setAcceleration(servoNum, newAccelleration);
        tinkerBrickServo.setPosition(servoNum, newPosition);
        setTargetPosition(newPosition);
        return true;
    } catch (TimeoutException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e);
    } catch (NotConnectedException e) {
        TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e);
    }
    return false;
}
Also used : NotConnectedException(com.tinkerforge.NotConnectedException) MBrickServo(org.openhab.binding.tinkerforge.internal.model.MBrickServo) BrickServo(com.tinkerforge.BrickServo) TimeoutException(com.tinkerforge.TimeoutException)

Example 3 with BrickServo

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

the class MBrickServoImpl method enable.

/**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * 
     * @generated NOT
     */
@Override
public void enable() {
    logger.debug("enable called on MBrickServoImpl");
    tinkerforgeDevice = new BrickServo(getUid(), getIpConnection());
}
Also used : BrickServo(com.tinkerforge.BrickServo) MBrickServo(org.openhab.binding.tinkerforge.internal.model.MBrickServo)

Example 4 with BrickServo

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

the class MServoImpl method enable.

/**
     * <!-- begin-user-doc --> <!-- end-user-doc -->
     *
     * @generated NOT
     */
@Override
public void enable() {
    MBrickServo brick = getMbrick();
    if (brick == null) {
        logger.error("No servo brick configured for servo: " + uid);
    } else {
        if (tfConfig != null) {
            logger.debug("found tfConfig");
            if (tfConfig.getVelocity() != 0) {
                // TODO check for
                setVelocity(tfConfig.getVelocity());
            }
            // state
            if (tfConfig.getAcceleration() != 0) {
                setAcceleration(tfConfig.getAcceleration());
            }
            if (tfConfig.getPeriod() != 0) {
                setPeriod(tfConfig.getPeriod());
            }
            if (tfConfig.getPulseWidthMax() != 0 && tfConfig.getPulseWidthMin() != 0) {
                setPulseWidthMax(tfConfig.getPulseWidthMax());
                setPulseWidthMin(tfConfig.getPulseWidthMin());
            }
            if (tfConfig.getOutputVoltage() != 0) {
                setOutputVoltage(tfConfig.getOutputVoltage());
            }
        }
        BrickServo tinkerBrickServo = brick.getTinkerforgeDevice();
        try {
            servoNum = Short.parseShort(String.valueOf(subId.charAt(subId.length() - 1)));
            // tinkerBrickServo.setVelocity(servoNum, velocity);
            // tinkerBrickServo.setAcceleration(servoNum, acceleration);
            tinkerBrickServo.setPulseWidth(servoNum, pulseWidthMin, pulseWidthMax);
            tinkerBrickServo.setPeriod(servoNum, period);
            tinkerBrickServo.setOutputVoltage(outputVoltage);
            // initialize target postion with
            setTargetPosition(tinkerBrickServo.getPosition(servoNum));
            // current position value
            listener = new PositionReachedListener();
            tinkerBrickServo.addPositionReachedListener(listener);
            tinkerBrickServo.enablePositionReachedCallback();
            tinkerBrickServo.enable(servoNum);
            fetchSwitchState();
        } catch (NumberFormatException e) {
            TinkerforgeErrorHandler.handleError(this, "can not determine servoNum", e);
        } 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) MBrickServo(org.openhab.binding.tinkerforge.internal.model.MBrickServo) MBrickServo(org.openhab.binding.tinkerforge.internal.model.MBrickServo) BrickServo(com.tinkerforge.BrickServo) TimeoutException(com.tinkerforge.TimeoutException)

Aggregations

BrickServo (com.tinkerforge.BrickServo)4 MBrickServo (org.openhab.binding.tinkerforge.internal.model.MBrickServo)4 NotConnectedException (com.tinkerforge.NotConnectedException)2 TimeoutException (com.tinkerforge.TimeoutException)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1