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.

91 lines (85 loc) 4.62 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 BoolToggleNode(config) { RED.nodes.createNode(this, config); var node = this; node.on('input', function(msg) { //bool-toggle v2 if(msg.payload.Value === true){ switch(msg.payload.Input) { case 1: { node.status({ fill: "green", shape: "dot", text: "SET [Out1: True, Out2: False]" }); this.context().set("state", true);//main output(top) var message0 = { Value : this.context().get("state")}; var message1 = { Value : !(this.context().get("state"))}; node.send([[{payload: message0}], [{payload: message1}]]); break; } case 2: { node.status({ fill: "red", shape: "dot", text: "RESET [Out1: False, Out2: True]" }); this.context().set("state", false);//main output(top) var message0 = { Value : this.context().get("state")}; var message1 = { Value : !(this.context().get("state"))}; node.send([[{payload: message0}], [{payload: message1}]]); break; } case 3: { let state = this.context().get("state"); if (typeof state === 'undefined') { //first run node.status({ fill: "blue", shape: "dot", text: "TOGGLE [Out1: True, Out2: False] d1" }); //flip the state this.context().set("state", true);//save new value var message0 = { Value : this.context().get("state")}; var message1 = { Value : !(this.context().get("state"))}; node.send([[{payload: message0}], [{payload: message1}]]); } else{ //has a value, run by value. var val = this.context().get("state"); if (val) { node.status({ fill: "blue", shape: "dot", text: "TOGGLE [Out1: False, Out2: True] d2" }); //flip the state this.context().set("state", false);//save new value var message0 = { Value : this.context().get("state")}; var message1 = { Value : !(this.context().get("state"))}; node.send([[{payload: message0}], [{payload: message1}]]); } else { node.status({ fill: "blue", shape: "dot", text: "TOGGLE [Out1: True, Out2: False] d3" }); //flip the state this.context().set("state", true);//save new value 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, 3 for Toggle)."}); node.send [[null],[null]]; break; } } } }); } RED.nodes.registerType("bool-toggle", BoolToggleNode); }