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.

80 lines (73 loc) 3.56 kB
/* * Copyright (c) 2025 Parallax AV Design Inc. * All rights reserved. * * This software is licensed, not sold. You may not copy, modify, merge, * publish, distribute, sublicense, or sell copies of this file or substantial * portions of it except as expressly permitted by the LICENSE file included * with this package. Use is restricted to building manifests for the * Parallax Control Node-RED nodes. See LICENSE for details. */ module.exports = function (RED) { function SetFeedbackNode(config) { RED.nodes.createNode(this, config); var node = this; this.joinID = config.JoinID; this.sigType = config.SigType; node.on('input', function (msg) { var errorFlag = false; var sig; //set-feedback v2 switch (node.sigType) { case "digital": { if (typeof msg.payload.Value === "boolean") { sig = "DIGITAL"; node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID }); } else { node.status({ fill: "red", shape: "ring", text: "msg.payload of type Boolean expected, received: " + msg.payload + " check input or select correct SigType." }); errorFlag = true; } break; } case "analog": { if (typeof msg.payload.Value === "number") { sig = "ANALOG"; node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID }); } else { node.status({ fill: "red", shape: "ring", text: "msg.payload of type Number expected, received: " + msg.payload + " check input or select correct SigType." }); errorFlag = true; } break; } case "serial": { if (typeof msg.payload.Value === "string") { sig = "SERIAL"; node.status({ fill: "blue", shape: "dot", text: "SigType: " + sig + ", JoinID: " + node.joinID }); } else { node.status({ fill: "red", shape: "ring", text: "msg.payload of type String expected, received: " + msg.payload + " of type: " + typeof (msg.payload) + ", check input or select correct SigType." }); errorFlag = true; } break; } } if (errorFlag) { node.warn("Warning in Node: " + node.id + ", check node status for more information."); } else { // Check if the environment variables are defined if (node.joinID !== undefined && node.sigType !== undefined) { // Use the environment variable values in your function logic var message = { "Type": sig, "JoinID": node.joinID, "Value": msg.payload.Value }; node.send({payload : message}); } else { var errorMsg = { payload: "One or both of the environment variables (JoinID) are not defined." }; node.send(errorMsg); } } }); } RED.nodes.registerType("set-feedback", SetFeedbackNode); };