forked from RnD/measurement
Compare commits
6 Commits
be7c929600
...
496c5688bc
| Author | SHA1 | Date | |
|---|---|---|---|
| 496c5688bc | |||
|
|
5a0c46cb67 | ||
|
|
b1ba23212d | ||
|
|
f6da9a6fc5 | ||
|
|
94da1a36e4 | ||
| 9a7b5a93ed |
@@ -81,10 +81,13 @@ class nodeClass {
|
|||||||
enabled: uiConfig.simulator
|
enabled: uiConfig.simulator
|
||||||
},
|
},
|
||||||
functionality: {
|
functionality: {
|
||||||
positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
|
positionVsParent: uiConfig.positionVsParent,// Default to 'atEquipment' if not specified
|
||||||
|
distance: uiConfig.hasDistance ? uiConfig.distance : undefined
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(`position vs child for ${this.name} is ${this.config.functionality.positionVsParent} the distance is ${this.config.functionality.distance}`);
|
||||||
|
|
||||||
// Utility for formatting outputs
|
// Utility for formatting outputs
|
||||||
this._output = new outputUtils();
|
this._output = new outputUtils();
|
||||||
}
|
}
|
||||||
@@ -101,9 +104,11 @@ class nodeClass {
|
|||||||
* Bind Measurement events to Node-RED status updates. Using internal emitter. --> REMOVE LATER WE NEED ONLY COMPLETE CHILDS AND THEN CHECK FOR UPDATES
|
* Bind Measurement events to Node-RED status updates. Using internal emitter. --> REMOVE LATER WE NEED ONLY COMPLETE CHILDS AND THEN CHECK FOR UPDATES
|
||||||
*/
|
*/
|
||||||
_bindEvents() {
|
_bindEvents() {
|
||||||
|
|
||||||
this.source.emitter.on('mAbs', (val) => {
|
this.source.emitter.on('mAbs', (val) => {
|
||||||
this.node.status({ fill: 'green', shape: 'dot', text: `${val} ${this.config.general.unit}` });
|
this.node.status({ fill: 'green', shape: 'dot', text: `${val} ${this.config.general.unit}` });
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,7 +120,7 @@ class nodeClass {
|
|||||||
this.node.send([
|
this.node.send([
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ topic: 'registerChild', payload: this.node.id , positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
|
{ topic: 'registerChild', payload: this.node.id , positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' , distance: this.config?.functionality?.distance || null},
|
||||||
]);
|
]);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,8 +497,18 @@ class Measurement {
|
|||||||
|
|
||||||
updateOutputAbs(val) {
|
updateOutputAbs(val) {
|
||||||
|
|
||||||
|
// Constrain first, then check for changes
|
||||||
|
let constrainedVal = val;
|
||||||
|
|
||||||
|
if (val < this.config.scaling.absMin || val > this.config.scaling.absMax) {
|
||||||
|
this.logger.warn(`Output value=${val} is outside of ABS range. Constraining.`);
|
||||||
|
constrainedVal = this.constrain(val, this.config.scaling.absMin, this.config.scaling.absMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
const roundedVal = Math.round(constrainedVal * 100) / 100;
|
||||||
|
|
||||||
//only update on change
|
//only update on change
|
||||||
if(val != this.outputAbs){
|
if (roundedVal != this.outputAbs) {
|
||||||
|
|
||||||
// Constrain value within process range
|
// Constrain value within process range
|
||||||
if (val < this.config.scaling.absMin || val > this.config.scaling.absMax) {
|
if (val < this.config.scaling.absMin || val > this.config.scaling.absMax) {
|
||||||
@@ -511,9 +521,8 @@ class Measurement {
|
|||||||
|
|
||||||
this.emitter.emit('mAbs', this.outputAbs);// DEPRECATED: Use measurements container instead
|
this.emitter.emit('mAbs', this.outputAbs);// DEPRECATED: Use measurements container instead
|
||||||
|
|
||||||
// In the new method just update the measurement container and let the parent subscribe to it
|
|
||||||
this.logger.debug(`Updating type: ${this.config.asset.type}, variant: ${"measured"}, postition : ${this.config.functionality.positionVsParent} container with new value: ${this.outputAbs}`);
|
this.logger.debug(`Updating type: ${this.config.asset.type}, variant: ${"measured"}, postition : ${this.config.functionality.positionVsParent} container with new value: ${this.outputAbs}`);
|
||||||
this.measurements.type(this.config.asset.type).variant("measured").position(this.config.functionality.positionVsParent).value(this.outputAbs, Date.now(),this.config.asset.unit ); // New method
|
this.measurements.type(this.config.asset.type).variant("measured").position(this.config.functionality.positionVsParent).distance(this.config.functionality.distance).value(this.outputAbs, Date.now(),this.config.asset.unit );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user