mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02: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>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||
</script>
|
||||
|
||||
<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>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips"><b>Note:</b> You cannot use the same pin for both output and input.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="arduino out">
|
||||
|
@ -19,6 +19,7 @@ var util = require("util");
|
||||
var firmata = require("firmata");
|
||||
var arduinoReady = false;
|
||||
var thisboard = null;
|
||||
var pins = [];
|
||||
|
||||
// The Board Definition - this opens (and closes) the connection
|
||||
function ArduinoNode(n) {
|
||||
@ -33,7 +34,7 @@ function ArduinoNode(n) {
|
||||
if (thisboard == null) {
|
||||
node.board = new firmata.Board(node.device, function(err) {
|
||||
if (err) {
|
||||
console.log("[firmata] error: ",err);
|
||||
util.log("[firmata] error: "+err);
|
||||
return;
|
||||
}
|
||||
arduinoReady = true;
|
||||
@ -74,6 +75,10 @@ function DuinoNodeIn(n) {
|
||||
this.state = n.state;
|
||||
this.arduino = n.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") {
|
||||
this.board = this.serverConfig.board;
|
||||
this.repeat = this.serverConfig.repeat;
|
||||
@ -84,7 +89,7 @@ function DuinoNodeIn(n) {
|
||||
node.board = thisboard;
|
||||
clearInterval(node.toui);
|
||||
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.setSamplingInterval(node.repeat);
|
||||
var oldrdg = "";
|
||||
@ -128,6 +133,10 @@ function DuinoNodeOut(n) {
|
||||
this.pin = n.pin;
|
||||
this.state = n.state;
|
||||
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);
|
||||
if (typeof this.serverConfig === "object") {
|
||||
this.board = this.serverConfig.board;
|
||||
@ -135,7 +144,7 @@ function DuinoNodeOut(n) {
|
||||
|
||||
this.on("input", function(msg) {
|
||||
//console.log(msg);
|
||||
if (thisboard != null) {
|
||||
if (node.board != null) {
|
||||
if (node.state == "OUTPUT") {
|
||||
if ((msg.payload == true)||(msg.payload == 1)||(msg.payload.toString().toLowerCase() == "on")) {
|
||||
node.board.digitalWrite(node.pin, node.board.HIGH);
|
||||
@ -167,6 +176,7 @@ function DuinoNodeOut(n) {
|
||||
clearInterval(node.touo);
|
||||
node.touo = false;
|
||||
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]);
|
||||
}
|
||||
else { util.log("[firmata] waiting for arduino to connect"); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user