@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.
43 lines (39 loc) • 1.72 kB
JavaScript
module.exports = function(RED) {
function SetResetLatchNode(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function(msg) {
//set-reset-latch v2
switch(msg.payload.Input)
{
case 1:
{
this.context().set("state", true);
node.status({ fill: "green", shape: "dot", text: "SET" });
var message0 = { Value : this.context().get("state")};
var message1 = { Value : !(this.context().get("state"))};
node.send([[{payload : message0}],[{payload : message1}]]);
break;
}
case 2:
{
this.context().set("state",false);
node.status({ fill: "red", shape: "dot", text: "RESET" });
var message0 = { Value : this.context().get("state")};
var message1 = { Value : !(this.context().get("state"))};
node.send([[{payload : message0}],[{payload : message1}]]);
break;
}
default:
{
// Handle invalid input
node.warn("Warning in Node: " + node.id + ", check node status for more information.");
node.status({ fill: "red", shape: "ring", text:"Invalid input: Expected 1-based index (1 for Set, 2 for Reset)"});
node.send([[null],[null]]);
break;
}
}
});
}
RED.nodes.registerType("set-reset-latch", SetResetLatchNode);
}