Serialport library was updated and changed to Promise-based returns from callbacks as was being used in the arduino lib.
This commit is contained in:
parent
c6ebab4032
commit
4c8c2b66f3
|
@ -42,37 +42,37 @@ class Arduino {
|
||||||
* @returns {Promise} Resolves after enumerating
|
* @returns {Promise} Resolves after enumerating
|
||||||
**/
|
**/
|
||||||
async enumerate() {
|
async enumerate() {
|
||||||
return new Promise((resolve, reject) => {
|
let ports;
|
||||||
return SerialPort.list((err, ports) => {
|
let matches = [];
|
||||||
let matches = [];
|
try {
|
||||||
if (err) {
|
ports = await SerialPort.list();
|
||||||
return reject(err);
|
}
|
||||||
}
|
catch (err) {
|
||||||
ports.forEach((port) => {
|
throw err;
|
||||||
if (this.known.indexOf(port.comName) !== -1) {
|
}
|
||||||
matches.push(port.comName);
|
ports.forEach((port) => {
|
||||||
}
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
||||||
});
|
matches.push(port.path);
|
||||||
if (matches.length === 0) {
|
}
|
||||||
return reject('No USB devices found');
|
|
||||||
}
|
|
||||||
else if (matches.length > 0) {
|
|
||||||
return resolve(matches);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
if (matches.length === 0) {
|
||||||
|
throw new Error('No USB devices found');
|
||||||
|
}
|
||||||
|
else if (matches.length > 0) {
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Send a command to an Arduino using async/await
|
* Send a command to an Arduino using async/await
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -427,7 +427,6 @@ class Devices {
|
||||||
this.settings.save();
|
this.settings.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
@ -460,7 +459,6 @@ class Devices {
|
||||||
this.ui.send('ready', args);
|
this.ui.send('ready', args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
module.exports = function (arduino, settings, mainWindow, cam) {
|
module.exports = function (arduino, settings, mainWindow, cam) {
|
||||||
return new Devices(arduino, settings, mainWindow, cam);
|
return new Devices(arduino, settings, mainWindow, cam);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -42,37 +42,37 @@ class Arduino {
|
||||||
* @returns {Promise} Resolves after enumerating
|
* @returns {Promise} Resolves after enumerating
|
||||||
**/
|
**/
|
||||||
async enumerate() {
|
async enumerate() {
|
||||||
return new Promise((resolve, reject) => {
|
let ports;
|
||||||
return SerialPort.list((err, ports) => {
|
let matches = [];
|
||||||
let matches = [];
|
try {
|
||||||
if (err) {
|
ports = await SerialPort.list();
|
||||||
return reject(err);
|
}
|
||||||
}
|
catch (err) {
|
||||||
ports.forEach((port) => {
|
throw err;
|
||||||
if (this.known.indexOf(port.comName) !== -1) {
|
}
|
||||||
matches.push(port.comName);
|
ports.forEach((port) => {
|
||||||
}
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
||||||
else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
matches.push(port.path);
|
||||||
matches.push(port.comName);
|
}
|
||||||
}
|
else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
||||||
});
|
matches.push(port.path);
|
||||||
if (matches.length === 0) {
|
}
|
||||||
return reject('No USB devices found');
|
|
||||||
}
|
|
||||||
else if (matches.length > 0) {
|
|
||||||
return resolve(matches);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
if (matches.length === 0) {
|
||||||
|
throw new Error('No USB devices found');
|
||||||
|
}
|
||||||
|
else if (matches.length > 0) {
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Send a command to an Arduino using async/await
|
* Send a command to an Arduino using async/await
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -427,7 +427,6 @@ class Devices {
|
||||||
this.settings.save();
|
this.settings.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
@ -460,7 +459,6 @@ class Devices {
|
||||||
this.ui.send('ready', args);
|
this.ui.send('ready', args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
module.exports = function (arduino, settings, mainWindow, cam) {
|
module.exports = function (arduino, settings, mainWindow, cam) {
|
||||||
return new Devices(arduino, settings, mainWindow, cam);
|
return new Devices(arduino, settings, mainWindow, cam);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -52,32 +52,31 @@ class Arduino {
|
||||||
* @returns {Promise} Resolves after enumerating
|
* @returns {Promise} Resolves after enumerating
|
||||||
**/
|
**/
|
||||||
async enumerate () {
|
async enumerate () {
|
||||||
return new Promise( (resolve, reject) => {
|
let ports : any[]
|
||||||
return SerialPort.list((err : any, ports : any[]) => {
|
let matches : string[] = []
|
||||||
let matches : string[] = []
|
try {
|
||||||
if (err) {
|
ports = await SerialPort.list()
|
||||||
return reject(err)
|
} catch (err) {
|
||||||
}
|
throw err
|
||||||
ports.forEach((port : any) => {
|
}
|
||||||
if (this.known.indexOf(port.comName) !== -1) {
|
ports.forEach((port : any) => {
|
||||||
matches.push(port.comName)
|
if (this.known.indexOf(port.path) !== -1) {
|
||||||
} else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
matches.push(port.path)
|
||||||
matches.push(port.comName)
|
} else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
|
||||||
} else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
|
matches.push(port.path)
|
||||||
matches.push(port.comName)
|
} else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
|
||||||
} else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
matches.push(port.path)
|
||||||
matches.push(port.comName)
|
} else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
|
||||||
} else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
matches.push(port.path)
|
||||||
matches.push(port.comName)
|
} else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
|
||||||
}
|
matches.push(port.path)
|
||||||
})
|
}
|
||||||
if (matches.length === 0) {
|
|
||||||
return reject('No USB devices found');
|
|
||||||
} else if (matches.length > 0) {
|
|
||||||
return resolve(matches)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
if (matches.length === 0) {
|
||||||
|
throw new Error('No USB devices found')
|
||||||
|
} else if (matches.length > 0) {
|
||||||
|
return matches
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -405,7 +405,6 @@ class Devices {
|
||||||
c.intval = this.settings.state.camera.intval
|
c.intval = this.settings.state.camera.intval
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.ready(p, c, l, cs, ps)
|
return this.ready(p, c, l, cs, ps)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -427,7 +426,7 @@ class Devices {
|
||||||
this.settings.update('devices', this.settings.state.devices)
|
this.settings.update('devices', this.settings.state.devices)
|
||||||
this.settings.save()
|
this.settings.save()
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
@ -463,7 +462,7 @@ class Devices {
|
||||||
this.ui.send('ready', args)
|
this.ui.send('ready', args)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue