Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 28, 2024
1 parent 287c0e4 commit c4530ea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function Master(options, adapter) {
showDebug && adapter.log.debug(`[DevID_${regs.deviceId}/${regType}] Poll address ${regBlock.start} DONE`);
if (response.payload && response.payload.length) {

// first process all the scalefactor values inside the block
// first process all the scale factor values inside the block
for (let n = regBlock.startIndex; n < regBlock.endIndex; n++) {
if (regs.config[n].isScale) {
const prefixAddr = `DevID_${device.coils.deviceId}/${regType}/${regs.config[n]._address}`;
Expand All @@ -235,11 +235,10 @@ function Master(options, adapter) {
} catch (e) {
adapter.log.warn(`[${prefixAddr}] Calculation: eval(${regs.config[n].formula}) not possible: ${e}`);
}
} else { // no formula used, so just scale with factor and offset
if (typeof val === 'number') {
val = val * regs.config[n].factor + regs.config[n].offset;
val = Math.round(val * options.config.round) / options.config.round;
}
} else if (typeof val === 'number') {
// no formula used, so just scale with factor and offset
val = val * regs.config[n].factor + regs.config[n].offset;
val = Math.round(val * options.config.round) / options.config.round;
}
// store the finally calculated value as scaleFactor
scaleFactors[regs.deviceId][regs.config[n]._address] = val;
Expand Down Expand Up @@ -302,18 +301,16 @@ function Master(options, adapter) {
} catch (e) {
adapter.log.warn(`[DevID_${device.coils.deviceId}/${regType}/${regs.config[n]._address}] Calculation: eval(${regs.config[n].formula}) not possible: ${e}`);
}
} else {
if (typeof val === 'number') {
val = val * regs.config[n].factor + regs.config[n].offset;
val = Math.round(val * options.config.round) / options.config.round;
}
} else if (typeof val === 'number') {
val = val * regs.config[n].factor + regs.config[n].offset;
val = Math.round(val * options.config.round) / options.config.round;
}

if (val !== null &&
(options.config.alwaysUpdate || ackObjects[id] === undefined || ackObjects[id].val !== val)) {
ackObjects[id] = { val };
adapter.setState(id, val, true, err =>
// analyse if the state could be set (because of permissions)
// analyze if the state could be set (because of permissions)
err && adapter.log.error(`Can not set state ${id}: ${err}`));
}
} catch (err) {
Expand Down
8 changes: 4 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,18 +747,18 @@ function iterateAddresses(isBools, deviceId, result, regName, regType, localOpti
if (config.length) {
result.length = result.addressHigh - result.addressLow;
if (isBools && !localOptions.doNotRoundAddressToWord) {
let oldstart = result.addressLow;
const oldStart = result.addressLow;
result.addressLow = (result.addressLow >> 4) << 4;
result.length += (oldstart - result.addressLow);
result.length += oldStart - result.addressLow;

if (result.length % 16) {
result.length = ((result.length >> 4) + 1) << 4;
}
if (result.blocks) {
for (let b = 0; b < result.blocks.length; b++) {
let oldstart = result.blocks[b].start;
const _oldStart = result.blocks[b].start;
result.blocks[b].start = (result.blocks[b].start >> 4) << 4;
result.blocks[b].count += (oldstart - result.blocks[b].count);
result.blocks[b].count += _oldStart - result.blocks[b].count;

if (result.blocks[b].count % 16) {
result.blocks[b].count = ((result.blocks[b].count >> 4) + 1) << 4;
Expand Down

0 comments on commit c4530ea

Please sign in to comment.