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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations