use of org.simplify4u.jfatek.FatekReadMixDataCmd in project openhab1-addons by openhab.
the class FatekColorItem method valueForIncreaseDecrease.
private HSBType valueForIncreaseDecrease(FatekPLC fatekPLC, Command command) throws CommandException {
HSBType val = null;
try {
// first read current state
Map<Reg, RegValue> regVal = new FatekReadMixDataCmd(fatekPLC, reg1, reg2, reg3).send();
HSBType currentVal = reg2HSB(regVal.get(reg1), regVal.get(reg1), regVal.get(reg3));
int b = currentVal.getBrightness().intValue();
if (IncreaseDecreaseType.INCREASE.equals(command)) {
b = Math.min(b + step, 100);
} else if (IncreaseDecreaseType.DECREASE.equals(command)) {
b = Math.max(b - step, 0);
} else {
throw new CommandException(this, command, "Unknown IncreaseDecrease type");
}
if (b != currentVal.getBrightness().intValue()) {
val = new HSBType(currentVal.getHue(), currentVal.getSaturation(), new PercentType(b));
}
} catch (FatekIOException | FatekException e) {
throw new CommandException(this, command, e);
}
return val;
}
use of org.simplify4u.jfatek.FatekReadMixDataCmd in project openhab1-addons by openhab.
the class FatekDimmerItem method valueForIncreaseDecrease.
private int valueForIncreaseDecrease(FatekPLC fatekPLC, Command command) throws FatekIOException, FatekException {
// read current value from PLC
Map<Reg, RegValue> currentPlcValues = new FatekReadMixDataCmd(fatekPLC, reg1).send();
RegValue currRegValue = currentPlcValues.get(reg1);
long plcVal = currRegValue.longValueUnsigned();
if (factor != null) {
plcVal = new BigDecimal(plcVal).multiply(factor).longValue();
}
if (IncreaseDecreaseType.INCREASE.equals(command)) {
plcVal += step;
}
if (IncreaseDecreaseType.DECREASE.equals(command)) {
plcVal -= step;
}
plcVal = Math.max(plcVal, 0);
plcVal = Math.min(plcVal, 100);
RegValue val = RegValue.getForReg(reg1, plcVal);
if (currRegValue.equals(val)) {
return -1;
}
return (int) plcVal;
}
use of org.simplify4u.jfatek.FatekReadMixDataCmd in project openhab1-addons by openhab.
the class FatekPLCSlave method updateItems.
/**
* Read current data from Fatek PLC and publish new state on OpenHab bus.
*
* @param items items to updates
* @throws FatekIOException
* @throws FatekException
*/
public void updateItems(List<FatekPLCItem> items) throws FatekIOException, FatekException {
// collect unique register to read from PLC
Set<Reg> regsToUpdate = new HashSet<>();
for (FatekPLCItem item : items) {
regsToUpdate.addAll(item.getRegs());
}
Map<Reg, RegValue> response;
synchronized (fatekPLC) {
// read register
response = new FatekReadMixDataCmd(fatekPLC, regsToUpdate).send();
}
// distribute read data
for (FatekPLCItem fatekItem : items) {
State newState = fatekItem.getState(response);
if (stateCache.isStateChange(fatekItem, newState)) {
eventPublisher.postUpdate(fatekItem.getItemName(), newState);
}
}
}
Aggregations