use of org.openhab.binding.tinkerforge.internal.model.MBrickServo 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);
}
}
}
Aggregations