UNPKG

node-red-contrib-minelert-universal-io

Version:

Node-RED nodes for Universal IO Gateway and I/O Modules

40 lines (27 loc) 1.16 kB
const { EventBus, logInfo, Utils } = require('@minelert-smartlink/common'); module.exports = function(RED) { function LevelToMaNode(config) { RED.nodes.createNode(this, config); const node = this; node.mode = config.mode || 'distance'; // 'distance' or 'level' node.unit = config.unit || 'm'; node.min = parseFloat(config.min) || 0; node.max = parseFloat(config.max) || 1; node.on('input', (msg, send, done) => { const tankHeight = RED.util.evaluateNodeProperty(config.tankHeight, config.tankHeightType || "str", this, msg); const height = parseFloat(tankHeight); const result = Utils.convertLevelToMilliAmps(msg.payload, node.unit, node.mode, node.min, node.max, height) if ('error' in result) { node.error(result.error) return } node.status({ fill: "green", shape: "dot", text: `${result.mA} mA` }); send({payload: result}); if (done) done(); }); node.on('close', () => { // Optionally perform cleanup }); } RED.nodes.registerType("level-to-ma", LevelToMaNode); };