mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Arduino node tidy internal status
This commit is contained in:
parent
8d45e85acf
commit
cb6d147680
@ -9,21 +9,21 @@ module.exports = function(RED) {
|
||||
function ArduinoNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.device = n.device || null;
|
||||
this.running = false;
|
||||
this.reported = false;
|
||||
var node = this;
|
||||
var running = false;
|
||||
var reported = false;
|
||||
|
||||
var startup = function() {
|
||||
node.board = new Board(node.device, function(e) {
|
||||
if ((e !== undefined) && (e.toString().indexOf("cannot open") !== -1) ) {
|
||||
if (!reported) {
|
||||
if (node.reported === false) {
|
||||
node.error(RED._("arduino.errors.portnotfound",{device:node.device}));
|
||||
reported = true;
|
||||
node.reported = true;
|
||||
}
|
||||
}
|
||||
else if (e === undefined) {
|
||||
running = true;
|
||||
reported = false;
|
||||
node.running = true;
|
||||
node.reported = false;
|
||||
node.board.once('ready', function() {
|
||||
node.log(RED._("arduino.status.connected",{device:node.board.sp.path}));
|
||||
if (RED.settings.verbose) {
|
||||
@ -34,16 +34,16 @@ module.exports = function(RED) {
|
||||
node.error(RED._("arduino.status.portclosed"));
|
||||
});
|
||||
node.board.once('disconnect', function() {
|
||||
if (running) { setTimeout(function() { running = false; startup(); }, 5000); }
|
||||
if (node.running === true) { setTimeout(function() { node.running = false; startup(); }, 5000); }
|
||||
});
|
||||
}
|
||||
});
|
||||
setTimeout(function() { if (!running) { startup(); } }, 5000);
|
||||
setTimeout(function() { if (node.running === false) { startup(); } }, 5000);
|
||||
};
|
||||
startup();
|
||||
|
||||
node.on('close', function(done) {
|
||||
running = false;
|
||||
node.running = false;
|
||||
if (node.board) {
|
||||
try {
|
||||
node.board.transport.close(function() {
|
||||
@ -185,12 +185,12 @@ module.exports = function(RED) {
|
||||
});
|
||||
node.board.once('disconnect', function() {
|
||||
node.status({fill:"red",shape:"ring",text:"node-red:common.status.not-connected"});
|
||||
if (node.running) { setTimeout(function() { node.running = false; startup(); }, 5500); }
|
||||
if (node.running === true) { setTimeout(function() { node.running = false; startup(); }, 5500); }
|
||||
});
|
||||
}
|
||||
if (node.board.isReady) { doit(); }
|
||||
else { node.board.once("ready", function() { doit(); }); }
|
||||
setTimeout(function() { if (!node.running) { startup(); } }, 4500);
|
||||
setTimeout(function() { if (node.running === false) { startup(); } }, 4500);
|
||||
}
|
||||
startup();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "node-red-node-arduino",
|
||||
"version" : "0.2.2",
|
||||
"version" : "0.2.3",
|
||||
"description" : "A Node-RED node to talk to an Arduino running firmata",
|
||||
"dependencies" : {
|
||||
"firmata" : "^2.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user