mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-25 01:05:12 +03:00
Filter list of Linux devices to more sane set (front page and SITL)
This commit is contained in:
parent
9c66cd9c0e
commit
3d3f5aac8e
2 changed files with 24 additions and 14 deletions
|
@ -18,13 +18,13 @@ class ConnectionSerial extends Connection {
|
||||||
super._type = ConnectionType.Serial;
|
super._type = ConnectionType.Serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectImplementation(path, options, callback) {
|
connectImplementation(path, options, callback) {
|
||||||
try {
|
try {
|
||||||
this._serialport = new SerialPortStream({binding, path: path, baudRate: options.bitrate, autoOpen: true}, () => {
|
this._serialport = new SerialPortStream({binding, path: path, baudRate: options.bitrate, autoOpen: true}, () => {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback({
|
callback({
|
||||||
connectionId: ++this._connectionId,
|
connectionId: ++this._connectionId,
|
||||||
bitrate: options.bitrate
|
bitrate: options.bitrate
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -50,12 +50,12 @@ class ConnectionSerial extends Connection {
|
||||||
this.abort();
|
this.abort();
|
||||||
console.log("Serial error: " + error);
|
console.log("Serial error: " + error);
|
||||||
this._onReceiveErrorListeners.forEach(listener => {
|
this._onReceiveErrorListeners.forEach(listener => {
|
||||||
listener(error);
|
listener(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectImplementation(callback) {
|
disconnectImplementation(callback) {
|
||||||
if (this._serialport && this._serialport.isOpen) {
|
if (this._serialport && this._serialport.isOpen) {
|
||||||
this._serialport.close(error => {
|
this._serialport.close(error => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -68,7 +68,7 @@ class ConnectionSerial extends Connection {
|
||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendImplementation(data, callback) {
|
sendImplementation(data, callback) {
|
||||||
if (this._serialport && this._serialport.isOpen) {
|
if (this._serialport && this._serialport.isOpen) {
|
||||||
this._serialport.write(Buffer.from(data), error => {
|
this._serialport.write(Buffer.from(data), error => {
|
||||||
|
@ -105,14 +105,23 @@ class ConnectionSerial extends Connection {
|
||||||
this._onReceiveErrorListeners = this._onReceiveErrorListeners.filter(listener => listener !== callback);
|
this._onReceiveErrorListeners = this._onReceiveErrorListeners.filter(listener => listener !== callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getDevices(callback) {
|
static async getDevices(callback) {
|
||||||
SerialPort.list().then((ports, error) => {
|
SerialPort.list().then((ports, error) => {
|
||||||
var devices = [];
|
var devices = [];
|
||||||
if (error) {
|
if (error) {
|
||||||
GUI.log("Unable to list serial ports.");
|
GUI.log("Unable to list serial ports.");
|
||||||
} else {
|
} else {
|
||||||
ports.forEach(port => {
|
ports.forEach(port => {
|
||||||
devices.push(port.path);
|
if (GUI.operating_system == 'Linux') {
|
||||||
|
/* Limit to: USB serial, RFCOMM (BT), 6 legacy devices */
|
||||||
|
if (port.pnpId ||
|
||||||
|
port.path.match(/rfcomm\d*/) ||
|
||||||
|
port.path.match(/ttyS[0-5]$/)) {
|
||||||
|
devices.push(port.path);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
devices.push(port.path);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (callback)
|
if (callback)
|
||||||
|
|
15
js/sitl.js
15
js/sitl.js
|
@ -138,19 +138,20 @@ var Ser2TCP = {
|
||||||
var devices = [];
|
var devices = [];
|
||||||
if (error) {
|
if (error) {
|
||||||
GUI.log("Unable to list serial ports.");
|
GUI.log("Unable to list serial ports.");
|
||||||
} else {
|
} else {
|
||||||
ports.forEach((device) => {
|
ports.forEach((device) => {
|
||||||
if (GUI.operating_system == 'Windows') {
|
if (GUI.operating_system == 'Windows') {
|
||||||
var m = device.path.match(/COM\d?\d/g)
|
var m = device.path.match(/COM\d?\d/g)
|
||||||
if (m)
|
if (m)
|
||||||
devices.push(m[0]);
|
devices.push(m[0]);
|
||||||
} else {
|
} else {
|
||||||
if (device.displayName != null) {
|
/* Limit to: USB serial, RFCOMM (BT), 6 legacy devices */
|
||||||
var m = device.path.match(/\/dev\/.*/)
|
if (device.pnpId ||
|
||||||
if (m)
|
device.path.match(/rfcomm\d*/) ||
|
||||||
devices.push(m[0]);
|
device.path.match(/ttyS[0-5]$/)) {
|
||||||
|
devices.push(device.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
callback(devices);
|
callback(devices);
|
||||||
|
@ -231,7 +232,7 @@ var SITLProcess = {
|
||||||
if (err)
|
if (err)
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
alert(GUI.operating_system);
|
alert(GUI.operating_system);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue