mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Arduino - ensure port list populated on start,
also allow connect to first found board - by not specifying a port.
This commit is contained in:
parent
d28a6eaf9d
commit
72e1f20383
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright 2013,2014 IBM Corp.
|
Copyright 2013,2015 IBM Corp.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -59,7 +59,7 @@
|
|||||||
icon: "arduino.png",
|
icon: "arduino.png",
|
||||||
label: function() {
|
label: function() {
|
||||||
var a = "";
|
var a = "";
|
||||||
if (this.state == "ANALOG") a = "A";
|
if (this.state === "ANALOG") { a = "A"; }
|
||||||
return this.name||"Pin: "+a+this.pin;
|
return this.name||"Pin: "+a+this.pin;
|
||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
@ -128,14 +128,14 @@
|
|||||||
<input type="text" id="node-config-input-device" style="width:60%;" placeholder="e.g. /dev/ttyUSB0 COM1"/>
|
<input type="text" id="node-config-input-device" style="width:60%;" placeholder="e.g. /dev/ttyUSB0 COM1"/>
|
||||||
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
|
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips"><b>Tip:</b> Use search to try to auto-detect serial port.</div>
|
<div class="form-tips"><b>Tip:</b> Use search to list serial ports, or leave blank to connect to first device found.</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
RED.nodes.registerType('arduino-board',{
|
RED.nodes.registerType('arduino-board',{
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
device: {value:"",required:true}
|
device: {value:""}
|
||||||
},
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.device||"arduino";
|
return this.device||"arduino";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013,2014 IBM Corp.
|
* Copyright 2013,2015 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -18,9 +18,6 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var ArduinoFirmata = require('arduino-firmata');
|
var ArduinoFirmata = require('arduino-firmata');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var portlist = ArduinoFirmata.list(function (err, ports) {
|
|
||||||
portlist = ports;
|
|
||||||
});
|
|
||||||
|
|
||||||
// The Board Definition - this opens (and closes) the connection
|
// The Board Definition - this opens (and closes) the connection
|
||||||
function ArduinoNode(n) {
|
function ArduinoNode(n) {
|
||||||
@ -30,15 +27,18 @@ module.exports = function(RED) {
|
|||||||
//node.log("opening connection "+this.device);
|
//node.log("opening connection "+this.device);
|
||||||
var node = this;
|
var node = this;
|
||||||
node.board = new ArduinoFirmata();
|
node.board = new ArduinoFirmata();
|
||||||
if (portlist.indexOf(node.device) === -1) {
|
ArduinoFirmata.list(function (err, ports) {
|
||||||
node.error("device "+node.device+" not found");
|
if (ports.indexOf(node.device) === -1) {
|
||||||
}
|
node.board.connect();
|
||||||
else {
|
node.log("connecting to first device found.");
|
||||||
node.board.connect(node.device);
|
}
|
||||||
}
|
else {
|
||||||
|
node.board.connect(node.device);
|
||||||
|
}
|
||||||
|
|
||||||
node.board.on('boardReady', function(){
|
node.board.on('boardReady', function() {
|
||||||
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
|
if (RED.settings.verbose) { node.log("version "+node.board.boardVersion); }
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
node.on('close', function(done) {
|
node.on('close', function(done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user