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.
|
||||
-->
|
||||
|
||||
<!-- First, the content of the edit dialog is defined. -->
|
||||
|
||||
<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 -->
|
||||
<!-- Define the edit dialog -->
|
||||
<script type="text/x-red" data-template-name="analog-in">
|
||||
<div class="form-row">
|
||||
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 150px;">
|
||||
<option value="">select pin</option>
|
||||
<option value="P9_39">AIN0 (P9 pin 39)</option>
|
||||
<option value="P9_40">AIN1 (P9 pin 40)</option>
|
||||
<option value="P9_37">AIN2 (P9 pin 37)</option>
|
||||
<option value="P9_38">AIN3 (P9 pin 38)</option>
|
||||
<option value="P9_33">AIN4 (P9 pin 33)</option>
|
||||
<option value="P9_36">AIN5 (P9 pin 36)</option>
|
||||
<option value="P9_35">AIN6 (P9 pin 35)</option>
|
||||
</select>
|
||||
<label for="node-input-pin"><i class="icon-asterisk"></i>Input pin</label>
|
||||
<select type="text" id="node-input-pin" style="width: 150px;">
|
||||
<option value="">select pin</option>
|
||||
<option value="P9_39">AIN0 (P9 pin 39)</option>
|
||||
<option value="P9_40">AIN1 (P9 pin 40)</option>
|
||||
<option value="P9_37">AIN2 (P9 pin 37)</option>
|
||||
<option value="P9_38">AIN3 (P9 pin 38)</option>
|
||||
<option value="P9_33">AIN4 (P9 pin 33)</option>
|
||||
<option value="P9_36">AIN5 (P9 pin 36)</option>
|
||||
<option value="P9_35">AIN6 (P9 pin 35)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-topic"><i class="icon-tasks"></i> Topic</label>
|
||||
<input type="text" id="node-input-topic" placeholder="Topic">
|
||||
</div>
|
||||
|
||||
<!-- By convention, most nodes have a 'name' property. The following div -->
|
||||
<!-- provides the necessary field. -->
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
||||
<!-- Next, some simple help text is provided for the node. -->
|
||||
<script type="text/x-red" data-help-name="BBB-analog-in">
|
||||
<!-- data-help-name identifies the node type this help is for -->
|
||||
<!-- This content appears in the Info sidebar when a node is selected -->
|
||||
<!-- The first <p> is used as the pop-up tool tip when hovering over a -->
|
||||
<!-- node in the palette. -->
|
||||
<p>Analogue input for the Beaglebone Black. Reads an anlogue pin when triggered</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>
|
||||
<!-- Add help text -->
|
||||
<script type="text/x-red" data-help-name="analog-in">
|
||||
<p>
|
||||
Analogue input for the Beaglebone Black. Reads an anlogue pin when triggered
|
||||
</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>
|
||||
|
||||
<!-- Finally, the node type is registered along with all of its properties -->
|
||||
<!-- The example below shows a small subset of the properties that can be set-->
|
||||
<!-- Register the node -->
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('BBB-analog-in',{
|
||||
category: 'advanced-input', // the palette category
|
||||
color:"#c6abef",
|
||||
defaults: { // defines the editable properties of the node
|
||||
name: { value:"" }, // along with default values.
|
||||
RED.nodes.registerType('analog-in', {
|
||||
category: 'advanced-input', // the palette category
|
||||
color:"#c6dbef",
|
||||
defaults: { // defines the editable properties of the node
|
||||
name: { value:"" }, // along with default values.
|
||||
topic: { value:"", required:true },
|
||||
pin: { value:"", required:true },
|
||||
pin: { value:"", required:true },
|
||||
},
|
||||
inputs:1, // set the number of inputs - only 0 or 1
|
||||
outputs:1, // set the number of outputs - 0 to n
|
||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||
label: function() { // sets the default label contents
|
||||
return this.name || "analog-in: " + this.pin;
|
||||
},
|
||||
labelStyle: function() { // sets the class to apply to the label
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
inputs:1, // set the number of inputs - only 0 or 1
|
||||
outputs:1, // set the number of outputs - 0 to n
|
||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||
label: function() { // sets the default label contents
|
||||
return this.name || "analog-in: " + this.pin;
|
||||
},
|
||||
labelStyle: function() { // sets the class to apply to the label
|
||||
return this.name ? "node_label_italic" : "";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -19,9 +19,9 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
|
||||
// Require bonescript
|
||||
try {
|
||||
var bs = require("bonescript");
|
||||
} catch(err) {
|
||||
require("util").log("[BBB-analog-in] Error: cannot find module 'bonescript'");
|
||||
var bonescript = require("bonescript");
|
||||
} catch (err) {
|
||||
require("util").log("[144-analog-in] Error: cannot find module 'bonescript'");
|
||||
}
|
||||
|
||||
// The main node definition - most things happen in here
|
||||
@ -33,30 +33,28 @@ function AnalogInputNode(n) {
|
||||
this.topic = n.topic;
|
||||
this.pin = n.pin;
|
||||
|
||||
// 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!)
|
||||
// Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
|
||||
// otherwise there is only one global 'node' for all instances of AnalogInputNode!)
|
||||
var node = this;
|
||||
|
||||
// A callback function variable seems to be more reliable than a lambda ?!
|
||||
var cbFun = function (x) {
|
||||
var msg = {};
|
||||
msg.topic = node.topic;
|
||||
msg.payload = x.value;
|
||||
if (isNaN(x.value)) {
|
||||
this.log(x.err);
|
||||
}
|
||||
node.send(msg);
|
||||
};
|
||||
// A callback function variable seems to be more reliable than a lambda ?!
|
||||
var readCallback = function (x) {
|
||||
var msg = {};
|
||||
msg.topic = node.topic;
|
||||
msg.payload = x.value;
|
||||
if (isNaN(x.value)) {
|
||||
node.log(x.err);
|
||||
}
|
||||
node.send(msg);
|
||||
};
|
||||
|
||||
// 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) {
|
||||
node.on("input", function (msg) { bs.analogRead(node.pin, cbFun) });
|
||||
} else {
|
||||
node.error("Unconfigured input pin");
|
||||
}
|
||||
// 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) {
|
||||
node.on("input", function (msg) { bonescript.analogRead(node.pin, readCallback) });
|
||||
} else {
|
||||
node.error("Unconfigured input pin");
|
||||
}
|
||||
}
|
||||
|
||||
// Register the node by name. This must be called before overriding any of the Node functions.
|
||||
RED.nodes.registerType("BBB-analog-in", AnalogInputNode);
|
||||
|
||||
// AnalogInputNode.prototype.close = function () { };
|
||||
RED.nodes.registerType("analog-in", AnalogInputNode);
|
||||
|
@ -14,8 +14,7 @@
|
||||
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">
|
||||
<div class="form-row">
|
||||
<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>
|
||||
<input type="text" id="node-input-topic" placeholder="Topic">
|
||||
</div>
|
||||
|
||||
<!-- By convention, most nodes have a 'name' property. The following div -->
|
||||
<!-- provides the necessary field. -->
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
@ -76,38 +72,42 @@
|
||||
</script>
|
||||
|
||||
|
||||
<!-- Next, some simple help text is provided for the node. -->
|
||||
<!-- Add help text -->
|
||||
<script type="text/x-red" data-help-name="discrete-in">
|
||||
<p>Discrete input for the Beaglebone Black. Sends a message on the first output
|
||||
each time the pin changes state, and records the total time in the active state</p>
|
||||
<p>A timer updates the total active time, sending a message on the second output
|
||||
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 active time, not the
|
||||
value read from the pin and sent on the first output</p>
|
||||
<p>
|
||||
Discrete input for the Beaglebone Black. Sends a message on the first output
|
||||
each time the pin changes state, and records the total time in the active state
|
||||
</p>
|
||||
<p>
|
||||
A timer updates the total active time, sending a message on the second output
|
||||
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>
|
||||
|
||||
<!-- Finally, the node type is registered along with all of its properties -->
|
||||
<!-- The example below shows a small subset of the properties that can be set-->
|
||||
<!-- Register the node -->
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('discrete-in',{
|
||||
category: 'advanced-input', // the palette category
|
||||
color:"#c6baef",
|
||||
defaults: { // defines the editable properties of the node
|
||||
name: { value:"" }, // along with default values.
|
||||
updateInterval: { value:30 },
|
||||
RED.nodes.registerType('discrete-in', {
|
||||
category: 'advanced-input', // the palette category
|
||||
color:"#c6dbef",
|
||||
defaults: { // defines the editable properties of the node
|
||||
name: { value:"" }, // along with default values.
|
||||
updateInterval: { value:60 },
|
||||
topic: { value:"", required:true },
|
||||
pin: { value:"", required:true },
|
||||
activeLow: { value:false, required:true}
|
||||
},
|
||||
inputs:1, // set the number of inputs - only 0 or 1
|
||||
outputs:2, // set the number of outputs - 0 to n
|
||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||
label: function() { // sets the default label contents
|
||||
inputs:1, // set the number of inputs - only 0 or 1
|
||||
outputs:2, // set the number of outputs - 0 to n
|
||||
icon: "arrow-in.png", // set the icon (held in public/icons)
|
||||
label: function() { // sets the default label contents
|
||||
return this.name || "discrete-in: " + this.pin;
|
||||
},
|
||||
labelStyle: function() { // sets the class to apply to the label
|
||||
return this.name?"node_label_italic":"";
|
||||
labelStyle: function() { // sets the class to apply to the label
|
||||
return this.name ? "node_label_italic" : "";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -19,7 +19,7 @@ var RED = require(process.env.NODE_RED_HOME + "/red/red");
|
||||
|
||||
// Require bonescript
|
||||
try {
|
||||
var bs = require("bonescript");
|
||||
var bonescript = require("bonescript");
|
||||
} catch (err) {
|
||||
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_27", "P9_30", "P9_41", "P9_42"].indexOf(node.pin) >= 0) {
|
||||
setTimeout(function () {
|
||||
bs.pinMode(node.pin, bs.INPUT);
|
||||
bs.digitalRead(node.pin, function (x) {
|
||||
// Initialise the currentState and lastActveTime variables based on the value read
|
||||
node.log("digitalRead: x.value = " + x.value);
|
||||
node.log("digitalRead: node.currentState = " + node.currentState);
|
||||
node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
|
||||
node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
|
||||
node.currentState = x.value - 0;
|
||||
node.log("First read - currentState: " + node.currentState);
|
||||
if (node.currentState === node.activeState) {
|
||||
node.lastActiveTime = Date.now();
|
||||
}
|
||||
// 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
|
||||
// pin state on the first output
|
||||
if (bs.attachInterrupt(node.pin, true, bs.CHANGE, interruptCallback)) {
|
||||
node.interruptAttached = true;
|
||||
node.on("input", inputCallback);
|
||||
node.intervalId = setInterval(timerCallback, node.updateInterval);
|
||||
} else {
|
||||
node.error("Failed to attach interrupt");
|
||||
}
|
||||
setTimeout(function () { node.emit("input", {}); }, 50);
|
||||
});
|
||||
}, 50);
|
||||
bonescript.pinMode(node.pin, bonescript.INPUT);
|
||||
bonescript.digitalRead(node.pin, function (x) {
|
||||
// Initialise the currentState and lastActveTime variables based on the value read
|
||||
node.log("digitalRead: x.value = " + x.value);
|
||||
node.log("digitalRead: node.currentState = " + node.currentState);
|
||||
node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
|
||||
node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
|
||||
node.currentState = x.value - 0;
|
||||
node.log("First read - currentState: " + node.currentState);
|
||||
if (node.currentState === node.activeState) {
|
||||
node.lastActiveTime = Date.now();
|
||||
}
|
||||
// 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
|
||||
// pin state on the first output
|
||||
if (bonescript.attachInterrupt(node.pin, true, bonescript.CHANGE, interruptCallback)) {
|
||||
node.interruptAttached = true;
|
||||
node.on("input", inputCallback);
|
||||
node.intervalId = setInterval(timerCallback, node.updateInterval);
|
||||
} else {
|
||||
node.error("Failed to attach interrupt");
|
||||
}
|
||||
setTimeout(function () { node.emit("input", {}); }, 50);
|
||||
});
|
||||
}, 50);
|
||||
} else {
|
||||
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)
|
||||
DiscreteInputNode.prototype.close = function () {
|
||||
if (this.interruptAttached) {
|
||||
bs.detachInterrupt(this.pin);
|
||||
bonescript.detachInterrupt(this.pin);
|
||||
}
|
||||
if (this.intervalId !== null) {
|
||||
clearInterval(this.intervalId);
|
||||
|
Loading…
Reference in New Issue
Block a user