@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.
74 lines (64 loc) • 2.83 kB
JavaScript
module.exports = function (RED) {
function RecallSignalStateNode(config) {
RED.nodes.createNode(this, config); // Properly initialize the node
var node = this; // Reference to this node
this.dataType = config.dataType; // Get dataType from node configuration
// Respond to input events
node.on('input', function (msg) {
var input = msg.input; // Assuming msg.input is set somewhere in your flow
// Define your data type constants
var digital = "DIGITAL";
var analog = "ANALOG";
var serial = "SERIAL";
var digital_dictionary = "DIGITAL_DICTIONARY";
var analog_dictionary = "ANALOG_DICTIONARY";
var serial_dictionary = "SERIAL_DICTIONARY";
//var globalContext = this.context().global.get("test");
// Recall values based on dataType
switch (node.dataType) {
case digital:
recallValue(digital);
break;
case analog:
recallValue(analog);
break;
case serial:
recallValue(serial);
break;
case digital_dictionary:
recallValue(digital_dictionary);
break;
case analog_dictionary:
recallValue(analog_dictionary);
break;
case serial_dictionary:
recallValue(serial_dictionary);
break;
}
function recallValue(type) {
node.status({ fill: "blue", shape: "dot", text: "Recalling: " + type });
var val = node.context().global.get(type);
printDictionaryContents(val);
}
// Define a reusable function to print the contents of a dictionary
function printDictionaryContents(dictionary) {
if (dictionary) {
for (var entry in dictionary) {
if (dictionary.hasOwnProperty(entry)) {
var value = dictionary[entry];
var message = {
Type: node.dataType, // Use the provided dataType
JoinID: entry,
Value: value
}
}
// Send the message to the next node
node.send({payload : message});
}
}
}
});
}
// Register the node by its name in the palette
RED.nodes.registerType("recall-signal-state", RecallSignalStateNode);
};