mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add warning to Arduino node (as underlying firmata won't allow pins to be both inputas and outputs at the same time)
This commit is contained in:
parent
f3ec90eee0
commit
f3040ae95c
@ -33,6 +33,7 @@
|
|||||||
<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>
|
||||||
|
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="arduino in">
|
<script type="text/x-red" data-help-name="arduino in">
|
||||||
@ -87,6 +88,7 @@
|
|||||||
<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>
|
||||||
|
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="arduino out">
|
<script type="text/x-red" data-help-name="arduino out">
|
||||||
|
@ -19,6 +19,7 @@ var util = require("util");
|
|||||||
var firmata = require("firmata");
|
var firmata = require("firmata");
|
||||||
var arduinoReady = false;
|
var arduinoReady = false;
|
||||||
var thisboard = null;
|
var thisboard = null;
|
||||||
|
var pins = [];
|
||||||
|
|
||||||
// The Board Definition - this opens (and closes) the connection
|
// The Board Definition - this opens (and closes) the connection
|
||||||
function ArduinoNode(n) {
|
function ArduinoNode(n) {
|
||||||
@ -33,7 +34,7 @@ function ArduinoNode(n) {
|
|||||||
if (thisboard == null) {
|
if (thisboard == null) {
|
||||||
node.board = new firmata.Board(node.device, function(err) {
|
node.board = new firmata.Board(node.device, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log("[firmata] error: ",err);
|
util.log("[firmata] error: "+err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
arduinoReady = true;
|
arduinoReady = true;
|
||||||
@ -74,6 +75,10 @@ function DuinoNodeIn(n) {
|
|||||||
this.state = n.state;
|
this.state = n.state;
|
||||||
this.arduino = n.arduino;
|
this.arduino = n.arduino;
|
||||||
this.serverConfig = RED.nodes.getNode(this.arduino);
|
this.serverConfig = RED.nodes.getNode(this.arduino);
|
||||||
|
if (pins.indexOf(this.pin) > -1) {
|
||||||
|
this.error("Arduino pin being used more than once");
|
||||||
|
}
|
||||||
|
else pins.push(this.pin);
|
||||||
if (typeof this.serverConfig === "object") {
|
if (typeof this.serverConfig === "object") {
|
||||||
this.board = this.serverConfig.board;
|
this.board = this.serverConfig.board;
|
||||||
this.repeat = this.serverConfig.repeat;
|
this.repeat = this.serverConfig.repeat;
|
||||||
@ -84,7 +89,7 @@ function DuinoNodeIn(n) {
|
|||||||
node.board = thisboard;
|
node.board = thisboard;
|
||||||
clearInterval(node.toui);
|
clearInterval(node.toui);
|
||||||
node.toui = false;
|
node.toui = false;
|
||||||
//console.log(node.state,node.pin,node.board.MODES[node.state]);
|
//console.log("i",node.state,node.pin,node.board.MODES[node.state]);
|
||||||
node.board.pinMode(node.pin, node.board.MODES[node.state]);
|
node.board.pinMode(node.pin, node.board.MODES[node.state]);
|
||||||
node.board.setSamplingInterval(node.repeat);
|
node.board.setSamplingInterval(node.repeat);
|
||||||
var oldrdg = "";
|
var oldrdg = "";
|
||||||
@ -128,6 +133,10 @@ function DuinoNodeOut(n) {
|
|||||||
this.pin = n.pin;
|
this.pin = n.pin;
|
||||||
this.state = n.state;
|
this.state = n.state;
|
||||||
this.arduino = n.arduino;
|
this.arduino = n.arduino;
|
||||||
|
if (pins.indexOf(this.pin) > -1) {
|
||||||
|
this.error("Arduino pin being used more than once");
|
||||||
|
}
|
||||||
|
else pins.push(this.pin);
|
||||||
this.serverConfig = RED.nodes.getNode(this.arduino);
|
this.serverConfig = RED.nodes.getNode(this.arduino);
|
||||||
if (typeof this.serverConfig === "object") {
|
if (typeof this.serverConfig === "object") {
|
||||||
this.board = this.serverConfig.board;
|
this.board = this.serverConfig.board;
|
||||||
@ -135,7 +144,7 @@ function DuinoNodeOut(n) {
|
|||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
if (thisboard != null) {
|
if (node.board != null) {
|
||||||
if (node.state == "OUTPUT") {
|
if (node.state == "OUTPUT") {
|
||||||
if ((msg.payload == true)||(msg.payload == 1)||(msg.payload.toString().toLowerCase() == "on")) {
|
if ((msg.payload == true)||(msg.payload == 1)||(msg.payload.toString().toLowerCase() == "on")) {
|
||||||
node.board.digitalWrite(node.pin, node.board.HIGH);
|
node.board.digitalWrite(node.pin, node.board.HIGH);
|
||||||
@ -167,6 +176,7 @@ function DuinoNodeOut(n) {
|
|||||||
clearInterval(node.touo);
|
clearInterval(node.touo);
|
||||||
node.touo = false;
|
node.touo = false;
|
||||||
node.board = thisboard;
|
node.board = thisboard;
|
||||||
|
//console.log("o",node.state,node.pin,node.board.MODES[node.state]);
|
||||||
node.board.pinMode(node.pin, node.board.MODES[node.state]);
|
node.board.pinMode(node.pin, node.board.MODES[node.state]);
|
||||||
}
|
}
|
||||||
else { util.log("[firmata] waiting for arduino to connect"); }
|
else { util.log("[firmata] waiting for arduino to connect"); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user