UNPKG

@parallaxcontrol/node-red-control

Version:

A comprehensive package of Node-RED nodes designed to seamlessly integrate with the Parallax Control Engine, offering enhanced control capabilities for AV Automation.

40 lines (33 loc) 1.43 kB
module.exports = function(RED) { function OrGateNode(config) { RED.nodes.createNode(this, config); var node = this; var numInputs = config.numInputs || 2; var inputs = {}; // Initialize inputs for (let i = 1; i <= numInputs; i++) { inputs[i] = false; } node.on('input', function(msg) { //or-gate v2 if (typeof msg.payload.Input === 'number' && typeof msg.payload.Value === 'boolean') { //Key = Input Selection, Value = Boolean inputs[msg.payload.Input] = msg.payload.Value; var output = Object.values(inputs).some(val => val === true); var message = { Value : output }; node.send({payload:message}); // Set status based on output if(output) { node.status({fill: "green", shape: "dot", text: "true"}); } else { node.status({fill: "red", shape: "dot", text: "false"}); } } else { // Set error status and log error if the expected structure is not found node.status({fill: "red", shape: "ring", text: "Invalid input"}); node.error("Invalid input: Expected JSON Object, i.e.: {\"Input\":1,\"Value\":true}"); } }); } RED.nodes.registerType("or-gate", OrGateNode); }