mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fixes for Arduino (firmata) node - to try to make it work on a Pi... very slow to initialise... was never coming ready in time... hopefully fixes Issue #35
This commit is contained in:
parent
c5da163d50
commit
ee92967efa
@ -138,7 +138,7 @@
|
|||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
//baud: {baud:"57600",required:true},
|
//baud: {baud:"57600",required:true},
|
||||||
repeat: {value:"25",required:true,validate:RED.validators.number()},
|
repeat: {value:"50",required:true,validate:RED.validators.number()},
|
||||||
device: {value:"",required:true}
|
device: {value:"",required:true}
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
|
@ -30,7 +30,6 @@ function ArduinoNode(n) {
|
|||||||
|
|
||||||
node.toun = setInterval(function() {
|
node.toun = setInterval(function() {
|
||||||
if (!arduinoReady) {
|
if (!arduinoReady) {
|
||||||
arduinoReady = false;
|
|
||||||
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) {
|
||||||
@ -44,21 +43,22 @@ function ArduinoNode(n) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
util.log("[firmata] Arduino already connected");
|
|
||||||
node.board = thisboard;
|
node.board = thisboard;
|
||||||
console.log(node.board.sp);
|
|
||||||
node.board.removeAllListeners();
|
node.board.removeAllListeners();
|
||||||
arduinoReady = true;
|
arduinoReady = true;
|
||||||
clearInterval(node.toun);
|
clearInterval(node.toun);
|
||||||
|
node.toun = false;
|
||||||
|
util.log("[firmata] Arduino already connected");
|
||||||
}
|
}
|
||||||
} else { util.log("[firmata] Waiting for Firmata"); }
|
} else { util.log("[firmata] Waiting for Firmata"); }
|
||||||
}, 10000); // wait for firmata to connect to arduino
|
}, 10000); // wait for firmata to connect to arduino
|
||||||
|
|
||||||
this.on('close', function() {
|
this.on('close', function() {
|
||||||
//this.board.sp.close(function() { console.log("[firmata] Serial port closed"); arduinoReady = false; });
|
//this.board.sp.close(function() { console.log("[firmata] Serial port closed"); arduinoReady = false; });
|
||||||
|
arduinoReady = false;
|
||||||
if (node.toun) {
|
if (node.toun) {
|
||||||
clearInterval(node.toun);
|
clearInterval(node.toun);
|
||||||
util.log("[arduino] arduino wait loop stopped");
|
util.log("[firmata] arduino wait loop stopped");
|
||||||
}
|
}
|
||||||
util.log("[firmata] Stopped");
|
util.log("[firmata] Stopped");
|
||||||
});
|
});
|
||||||
@ -80,9 +80,11 @@ function DuinoNodeIn(n) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
node.toui = setInterval(function() {
|
node.toui = setInterval(function() {
|
||||||
if (arduinoReady) {
|
if (thisboard != null) {
|
||||||
|
node.board = thisboard;
|
||||||
clearInterval(node.toui);
|
clearInterval(node.toui);
|
||||||
console.log(node.state,node.pin,node.board.MODES[node.state]);
|
node.toui = false;
|
||||||
|
//console.log(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 = "";
|
||||||
@ -108,12 +110,12 @@ function DuinoNodeIn(n) {
|
|||||||
this.on('close', function() {
|
this.on('close', function() {
|
||||||
if (node.toui) {
|
if (node.toui) {
|
||||||
clearInterval(node.toui);
|
clearInterval(node.toui);
|
||||||
util.log("[arduino] input wait loop stopped");
|
util.log("[firmata] input wait loop stopped");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
util.log("[arduino] Serial Port not Configured");
|
util.log("[firmata] Serial Port not Configured");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("arduino in",DuinoNodeIn);
|
RED.nodes.registerType("arduino in",DuinoNodeIn);
|
||||||
@ -133,7 +135,7 @@ function DuinoNodeOut(n) {
|
|||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
//console.log(msg);
|
//console.log(msg);
|
||||||
if (arduinoReady) {
|
if (thisboard != 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);
|
||||||
@ -161,22 +163,24 @@ function DuinoNodeOut(n) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.touo = setInterval(function() {
|
node.touo = setInterval(function() {
|
||||||
if (arduinoReady) {
|
if (thisboard != null) {
|
||||||
clearInterval(node.touo);
|
clearInterval(node.touo);
|
||||||
//console.log(node.state,node.pin,node.board.MODES[node.state]);
|
node.touo = false;
|
||||||
|
node.board = thisboard;
|
||||||
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"); }
|
||||||
}, 5000); // loop to wait for firmata to connect to arduino
|
}, 5000); // loop to wait for firmata to connect to arduino
|
||||||
|
|
||||||
this.on('close', function() {
|
this.on('close', function() {
|
||||||
if (node.touo) {
|
if (node.touo) {
|
||||||
clearInterval(node.touo);
|
clearInterval(node.touo);
|
||||||
util.log("[arduino] output wait loop stopped");
|
util.log("[firmata] output wait loop stopped");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
util.log("[arduino] Serial Port not Configured");
|
util.log("[firmata] Serial Port not Configured");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("arduino out",DuinoNodeOut);
|
RED.nodes.registerType("arduino out",DuinoNodeOut);
|
||||||
|
Loading…
Reference in New Issue
Block a user