mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Debug & tidy up
Make the colours the same as the RPi equivalents. Remove ‘BBB’ from the node names. Further debug output
This commit is contained in:
parent
4f509931ba
commit
8bf813c9cd
@ -14,72 +14,59 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- First, the content of the edit dialog is defined. -->
|
<!-- Define the edit dialog -->
|
||||||
|
<script type="text/x-red" data-template-name="analog-in">
|
||||||
<script type="text/x-red" data-template-name="BBB-analog-in">
|
|
||||||
|
|
||||||
<!-- Each of the following divs creates a field in the edit dialog. -->
|
|
||||||
<!-- Generally, there should be an input for each property of the node. -->
|
|
||||||
<!-- The for and id attributes identify the corresponding property -->
|
|
||||||
<!-- (with the 'node-input-' prefix). -->
|
|
||||||
<!-- The available icon classes are defined in Twitter Bootstrap -->
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
||||||
<select type="text" id="node-input-pin" style="width: 150px;">
|
<select type="text" id="node-input-pin" style="width: 150px;">
|
||||||
<option value="">select pin</option>
|
<option value="">select pin</option>
|
||||||
<option value="P9_39">AIN0 (P9 pin 39)</option>
|
<option value="P9_39">AIN0 (P9 pin 39)</option>
|
||||||
<option value="P9_40">AIN1 (P9 pin 40)</option>
|
<option value="P9_40">AIN1 (P9 pin 40)</option>
|
||||||
<option value="P9_37">AIN2 (P9 pin 37)</option>
|
<option value="P9_37">AIN2 (P9 pin 37)</option>
|
||||||
<option value="P9_38">AIN3 (P9 pin 38)</option>
|
<option value="P9_38">AIN3 (P9 pin 38)</option>
|
||||||
<option value="P9_33">AIN4 (P9 pin 33)</option>
|
<option value="P9_33">AIN4 (P9 pin 33)</option>
|
||||||
<option value="P9_36">AIN5 (P9 pin 36)</option>
|
<option value="P9_36">AIN5 (P9 pin 36)</option>
|
||||||
<option value="P9_35">AIN6 (P9 pin 35)</option>
|
<option value="P9_35">AIN6 (P9 pin 35)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
||||||
<input type="text" id="node-input-topic" placeholder="Topic">
|
<input type="text" id="node-input-topic" placeholder="Topic">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- By convention, most nodes have a 'name' property. The following div -->
|
|
||||||
<!-- provides the necessary field. -->
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- Add help text -->
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
<script type="text/x-red" data-help-name="analog-in">
|
||||||
<script type="text/x-red" data-help-name="BBB-analog-in">
|
<p>
|
||||||
<!-- data-help-name identifies the node type this help is for -->
|
Analogue input for the Beaglebone Black. Reads an anlogue pin when triggered
|
||||||
<!-- This content appears in the Info sidebar when a node is selected -->
|
</p>
|
||||||
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
|
<p>The output message topic is the node topic: the output message value is the
|
||||||
<!-- node in the palette. -->
|
analogue input in the range [0-1), or NaN if an read error occurs (errors are logged)
|
||||||
<p>Analogue input for the Beaglebone Black. Reads an anlogue pin when triggered</p>
|
</p>
|
||||||
<p>The output message topic is the node topic: the output message value is the
|
|
||||||
analogue input in the range [0-1), or NaN if an read error occurs (errors are logged)</p>
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
<!-- Register the node -->
|
||||||
<!-- The example below shows a small subset of the properties that can be set-->
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('BBB-analog-in',{
|
RED.nodes.registerType('analog-in', {
|
||||||
category: 'advanced-input', // the palette category
|
category: 'advanced-input', // the palette category
|
||||||
color:"#c6abef",
|
color:"#c6dbef",
|
||||||
defaults: { // defines the editable properties of the node
|
defaults: { // defines the editable properties of the node
|
||||||
name: { value:"" }, // along with default values.
|
name: { value:"" }, // along with default values.
|
||||||
topic: { value:"", required:true },
|
topic: { value:"", required:true },
|
||||||
pin: { value:"", required:true },
|
pin: { value:"", required:true },
|
||||||
},
|
},
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
inputs:1, // set the number of inputs - only 0 or 1
|
||||||
outputs:1, // set the number of outputs - 0 to n
|
outputs:1, // set the number of outputs - 0 to n
|
||||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||||
label: function() { // sets the default label contents
|
label: function() { // sets the default label contents
|
||||||
return this.name || "analog-in: " + this.pin;
|
return this.name || "analog-in: " + this.pin;
|
||||||
},
|
},
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
labelStyle: function() { // sets the class to apply to the label
|
||||||
return this.name?"node_label_italic":"";
|
return this.name ? "node_label_italic" : "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -19,9 +19,9 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|||||||
|
|
||||||
// Require bonescript
|
// Require bonescript
|
||||||
try {
|
try {
|
||||||
var bs = require("bonescript");
|
var bonescript = require("bonescript");
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
require("util").log("[BBB-analog-in] Error: cannot find module 'bonescript'");
|
require("util").log("[144-analog-in] Error: cannot find module 'bonescript'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The main node definition - most things happen in here
|
// The main node definition - most things happen in here
|
||||||
@ -33,30 +33,28 @@ function AnalogInputNode(n) {
|
|||||||
this.topic = n.topic;
|
this.topic = n.topic;
|
||||||
this.pin = n.pin;
|
this.pin = n.pin;
|
||||||
|
|
||||||
// Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
|
// Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
|
||||||
// otherwise there is only one 'node' for all instances of AnalogInputNode!)
|
// otherwise there is only one global 'node' for all instances of AnalogInputNode!)
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
// A callback function variable seems to be more reliable than a lambda ?!
|
// A callback function variable seems to be more reliable than a lambda ?!
|
||||||
var cbFun = function (x) {
|
var readCallback = function (x) {
|
||||||
var msg = {};
|
var msg = {};
|
||||||
msg.topic = node.topic;
|
msg.topic = node.topic;
|
||||||
msg.payload = x.value;
|
msg.payload = x.value;
|
||||||
if (isNaN(x.value)) {
|
if (isNaN(x.value)) {
|
||||||
this.log(x.err);
|
node.log(x.err);
|
||||||
}
|
}
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If we have a valid pin, set the input event handler to Bonescript's analogRead
|
// If we have a valid pin, set the input event handler to Bonescript's analogRead
|
||||||
if (["P9_39", "P9_40", "P9_37", "P9_38", "P9_33", "P9_36", "P9_35"].indexOf(node.pin) >= 0) {
|
if (["P9_39", "P9_40", "P9_37", "P9_38", "P9_33", "P9_36", "P9_35"].indexOf(node.pin) >= 0) {
|
||||||
node.on("input", function (msg) { bs.analogRead(node.pin, cbFun) });
|
node.on("input", function (msg) { bonescript.analogRead(node.pin, readCallback) });
|
||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the node by name. This must be called before overriding any of the Node functions.
|
// Register the node by name. This must be called before overriding any of the Node functions.
|
||||||
RED.nodes.registerType("BBB-analog-in", AnalogInputNode);
|
RED.nodes.registerType("analog-in", AnalogInputNode);
|
||||||
|
|
||||||
// AnalogInputNode.prototype.close = function () { };
|
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- First, the content of the edit dialog is defined. -->
|
<!-- Define the edit dialog -->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="discrete-in">
|
<script type="text/x-red" data-template-name="discrete-in">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
||||||
@ -66,9 +65,6 @@
|
|||||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
||||||
<input type="text" id="node-input-topic" placeholder="Topic">
|
<input type="text" id="node-input-topic" placeholder="Topic">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- By convention, most nodes have a 'name' property. The following div -->
|
|
||||||
<!-- provides the necessary field. -->
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
@ -76,38 +72,42 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<!-- Next, some simple help text is provided for the node. -->
|
<!-- Add help text -->
|
||||||
<script type="text/x-red" data-help-name="discrete-in">
|
<script type="text/x-red" data-help-name="discrete-in">
|
||||||
<p>Discrete input for the Beaglebone Black. Sends a message on the first output
|
<p>
|
||||||
each time the pin changes state, and records the total time in the active state</p>
|
Discrete input for the Beaglebone Black. Sends a message on the first output
|
||||||
<p>A timer updates the total active time, sending a message on the second output
|
each time the pin changes state, and records the total time in the active state
|
||||||
at the chosen update interval.
|
</p>
|
||||||
Any input message will reset the total active time</p><p>The active
|
<p>
|
||||||
state may be set to be high or low: this only affects the active time, not the
|
A timer updates the total active time, sending a message on the second output
|
||||||
value read from the pin and sent on the first output</p>
|
at the chosen update interval. Any input message will reset the total active time
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The active state may be set to be high or low: this only affects the calculation
|
||||||
|
of the active time, not the pin state sent on the first output
|
||||||
|
</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Finally, the node type is registered along with all of its properties -->
|
<!-- Register the node -->
|
||||||
<!-- The example below shows a small subset of the properties that can be set-->
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('discrete-in',{
|
RED.nodes.registerType('discrete-in', {
|
||||||
category: 'advanced-input', // the palette category
|
category: 'advanced-input', // the palette category
|
||||||
color:"#c6baef",
|
color:"#c6dbef",
|
||||||
defaults: { // defines the editable properties of the node
|
defaults: { // defines the editable properties of the node
|
||||||
name: { value:"" }, // along with default values.
|
name: { value:"" }, // along with default values.
|
||||||
updateInterval: { value:30 },
|
updateInterval: { value:60 },
|
||||||
topic: { value:"", required:true },
|
topic: { value:"", required:true },
|
||||||
pin: { value:"", required:true },
|
pin: { value:"", required:true },
|
||||||
activeLow: { value:false, required:true}
|
activeLow: { value:false, required:true}
|
||||||
},
|
},
|
||||||
inputs:1, // set the number of inputs - only 0 or 1
|
inputs:1, // set the number of inputs - only 0 or 1
|
||||||
outputs:2, // set the number of outputs - 0 to n
|
outputs:2, // set the number of outputs - 0 to n
|
||||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||||
label: function() { // sets the default label contents
|
label: function() { // sets the default label contents
|
||||||
return this.name || "discrete-in: " + this.pin;
|
return this.name || "discrete-in: " + this.pin;
|
||||||
},
|
},
|
||||||
labelStyle: function() { // sets the class to apply to the label
|
labelStyle: function() { // sets the class to apply to the label
|
||||||
return this.name?"node_label_italic":"";
|
return this.name ? "node_label_italic" : "";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -19,7 +19,7 @@ var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
|||||||
|
|
||||||
// Require bonescript
|
// Require bonescript
|
||||||
try {
|
try {
|
||||||
var bs = require("bonescript");
|
var bonescript = require("bonescript");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
require("util").log("[145-digital-in] Error: cannot find module 'bonescript'");
|
require("util").log("[145-digital-in] Error: cannot find module 'bonescript'");
|
||||||
}
|
}
|
||||||
@ -119,31 +119,31 @@ function DiscreteInputNode(n) {
|
|||||||
"P9_15", "P9_16", "P9_17", "P9_18", "P9_21", "P9_22", "P9_23", "P9_24", "P9_26",
|
"P9_15", "P9_16", "P9_17", "P9_18", "P9_21", "P9_22", "P9_23", "P9_24", "P9_26",
|
||||||
"P9_27", "P9_30", "P9_41", "P9_42"].indexOf(node.pin) >= 0) {
|
"P9_27", "P9_30", "P9_41", "P9_42"].indexOf(node.pin) >= 0) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
bs.pinMode(node.pin, bs.INPUT);
|
bonescript.pinMode(node.pin, bonescript.INPUT);
|
||||||
bs.digitalRead(node.pin, function (x) {
|
bonescript.digitalRead(node.pin, function (x) {
|
||||||
// Initialise the currentState and lastActveTime variables based on the value read
|
// Initialise the currentState and lastActveTime variables based on the value read
|
||||||
node.log("digitalRead: x.value = " + x.value);
|
node.log("digitalRead: x.value = " + x.value);
|
||||||
node.log("digitalRead: node.currentState = " + node.currentState);
|
node.log("digitalRead: node.currentState = " + node.currentState);
|
||||||
node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
|
node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
|
||||||
node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
|
node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
|
||||||
node.currentState = x.value - 0;
|
node.currentState = x.value - 0;
|
||||||
node.log("First read - currentState: " + node.currentState);
|
node.log("First read - currentState: " + node.currentState);
|
||||||
if (node.currentState === node.activeState) {
|
if (node.currentState === node.activeState) {
|
||||||
node.lastActiveTime = Date.now();
|
node.lastActiveTime = Date.now();
|
||||||
}
|
}
|
||||||
// Attempt to attach a change-of-state interrupt handler to the pin. If we succeed,
|
// Attempt to attach a change-of-state interrupt handler to the pin. If we succeed,
|
||||||
// set the input event and interval handlers, then send an initial message with the
|
// set the input event and interval handlers, then send an initial message with the
|
||||||
// pin state on the first output
|
// pin state on the first output
|
||||||
if (bs.attachInterrupt(node.pin, true, bs.CHANGE, interruptCallback)) {
|
if (bonescript.attachInterrupt(node.pin, true, bonescript.CHANGE, interruptCallback)) {
|
||||||
node.interruptAttached = true;
|
node.interruptAttached = true;
|
||||||
node.on("input", inputCallback);
|
node.on("input", inputCallback);
|
||||||
node.intervalId = setInterval(timerCallback, node.updateInterval);
|
node.intervalId = setInterval(timerCallback, node.updateInterval);
|
||||||
} else {
|
} else {
|
||||||
node.error("Failed to attach interrupt");
|
node.error("Failed to attach interrupt");
|
||||||
}
|
}
|
||||||
setTimeout(function () { node.emit("input", {}); }, 50);
|
setTimeout(function () { node.emit("input", {}); }, 50);
|
||||||
});
|
});
|
||||||
}, 50);
|
}, 50);
|
||||||
} else {
|
} else {
|
||||||
node.error("Unconfigured input pin");
|
node.error("Unconfigured input pin");
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ RED.nodes.registerType("discrete-in", DiscreteInputNode);
|
|||||||
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
|
||||||
DiscreteInputNode.prototype.close = function () {
|
DiscreteInputNode.prototype.close = function () {
|
||||||
if (this.interruptAttached) {
|
if (this.interruptAttached) {
|
||||||
bs.detachInterrupt(this.pin);
|
bonescript.detachInterrupt(this.pin);
|
||||||
}
|
}
|
||||||
if (this.intervalId !== null) {
|
if (this.intervalId !== null) {
|
||||||
clearInterval(this.intervalId);
|
clearInterval(this.intervalId);
|
||||||
|
Loading…
Reference in New Issue
Block a user