Added logging to the arduino module to list all connected devices.
This commit is contained in:
parent
d501623290
commit
7c61af7043
|
@ -35,6 +35,11 @@ class Arduino {
|
||||||
this.timer = 0;
|
this.timer = 0;
|
||||||
this.lock = false;
|
this.lock = false;
|
||||||
this.locks = {};
|
this.locks = {};
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
async init() {
|
||||||
|
const Log = require('log');
|
||||||
|
this.log = await Log({ label: 'arduino' });
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Enumerate all connected devices that might be Arduinos
|
* Enumerate all connected devices that might be Arduinos
|
||||||
|
@ -50,7 +55,8 @@ class Arduino {
|
||||||
catch (err) {
|
catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
//console.dir(ports)
|
this.log.info('Available ports:');
|
||||||
|
this.log.info(ports.map((port) => { return port.path; }).join(','));
|
||||||
ports.forEach((port) => {
|
ports.forEach((port) => {
|
||||||
if (this.known.indexOf(port.path) !== -1) {
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
matches.push(port.path);
|
matches.push(port.path);
|
||||||
|
@ -100,6 +106,7 @@ class Arduino {
|
||||||
async send(serial, cmd) {
|
async send(serial, cmd) {
|
||||||
const device = this.alias[serial];
|
const device = this.alias[serial];
|
||||||
let results;
|
let results;
|
||||||
|
console.log(`${cmd} -> ${serial}`);
|
||||||
if (this.locks[serial]) {
|
if (this.locks[serial]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -35,6 +35,11 @@ class Arduino {
|
||||||
this.timer = 0;
|
this.timer = 0;
|
||||||
this.lock = false;
|
this.lock = false;
|
||||||
this.locks = {};
|
this.locks = {};
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
async init() {
|
||||||
|
const Log = require('log');
|
||||||
|
this.log = await Log({ label: 'arduino' });
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Enumerate all connected devices that might be Arduinos
|
* Enumerate all connected devices that might be Arduinos
|
||||||
|
@ -50,7 +55,8 @@ class Arduino {
|
||||||
catch (err) {
|
catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
//console.dir(ports)
|
this.log.info('Available ports:');
|
||||||
|
this.log.info(ports.map((port) => { return port.path; }).join(','));
|
||||||
ports.forEach((port) => {
|
ports.forEach((port) => {
|
||||||
if (this.known.indexOf(port.path) !== -1) {
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
matches.push(port.path);
|
matches.push(port.path);
|
||||||
|
@ -100,6 +106,7 @@ class Arduino {
|
||||||
async send(serial, cmd) {
|
async send(serial, cmd) {
|
||||||
const device = this.alias[serial];
|
const device = this.alias[serial];
|
||||||
let results;
|
let results;
|
||||||
|
console.log(`${cmd} -> ${serial}`);
|
||||||
if (this.locks[serial]) {
|
if (this.locks[serial]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -32,6 +32,7 @@ const KNOWN : string[] = [
|
||||||
|
|
||||||
class Arduino {
|
class Arduino {
|
||||||
|
|
||||||
|
private log : any;
|
||||||
private path : any = {}
|
private path : any = {}
|
||||||
private known : string[] = KNOWN
|
private known : string[] = KNOWN
|
||||||
private alias : any = {}
|
private alias : any = {}
|
||||||
|
@ -44,8 +45,14 @@ class Arduino {
|
||||||
private confirmExec : any
|
private confirmExec : any
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
|
this.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async init () {
|
||||||
|
const Log = require('log');
|
||||||
|
this.log = await Log({ label : 'arduino' });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumerate all connected devices that might be Arduinos
|
* Enumerate all connected devices that might be Arduinos
|
||||||
*
|
*
|
||||||
|
@ -59,7 +66,8 @@ class Arduino {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
//console.dir(ports)
|
this.log.info('Available ports:')
|
||||||
|
this.log.info(ports.map((port : any) => { return port.path }).join(','))
|
||||||
ports.forEach((port : any) => {
|
ports.forEach((port : any) => {
|
||||||
if (this.known.indexOf(port.path) !== -1) {
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
matches.push(port.path)
|
matches.push(port.path)
|
||||||
|
@ -106,6 +114,7 @@ class Arduino {
|
||||||
async send (serial : string, cmd : string) {
|
async send (serial : string, cmd : string) {
|
||||||
const device : any = this.alias[serial]
|
const device : any = this.alias[serial]
|
||||||
let results : any
|
let results : any
|
||||||
|
console.log(`${cmd} -> ${serial}`)
|
||||||
if (this.locks[serial]) {
|
if (this.locks[serial]) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue