mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 11:29:53 +03:00
Init
This commit is contained in:
parent
939f5af04b
commit
f24ccfc637
96 changed files with 16438 additions and 8058 deletions
|
@ -1,11 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var usbDevices = {
|
||||
filters: [
|
||||
{'vendorId': 1155, 'productId': 57105},
|
||||
{'vendorId': 11836, 'productId': 57105}
|
||||
]
|
||||
};
|
||||
const { findByIds } = require('usb');
|
||||
|
||||
var usbDevices = [
|
||||
{ 'vendorId': 1155, 'productId': 57105},
|
||||
{ 'vendorId': 11836, 'productId': 57105}
|
||||
];
|
||||
|
||||
// TODO: Replace with events
|
||||
|
||||
var PortHandler = new function () {
|
||||
this.initial_ports = false;
|
||||
|
@ -22,16 +24,7 @@ PortHandler.initialize = function () {
|
|||
PortHandler.check = function () {
|
||||
var self = this;
|
||||
|
||||
ConnectionSerial.getDevices(function(all_ports) {
|
||||
|
||||
// filter out ports that are not serial
|
||||
let current_ports = [];
|
||||
for (var i = 0; i < all_ports.length; i++) {
|
||||
if (all_ports[i].indexOf(':') === -1) {
|
||||
current_ports.push(all_ports[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ConnectionSerial.getDevices(function(current_ports) {
|
||||
// port got removed or initial_ports wasn't initialized yet
|
||||
if (self.array_difference(self.initial_ports, current_ports).length > 0 || !self.initial_ports) {
|
||||
var removed_ports = self.array_difference(self.initial_ports, current_ports);
|
||||
|
@ -75,35 +68,31 @@ PortHandler.check = function () {
|
|||
|
||||
// auto-select last used port (only during initialization)
|
||||
if (!self.initial_ports) {
|
||||
chrome.storage.local.get('last_used_port', function (result) {
|
||||
// if last_used_port was set, we try to select it
|
||||
if (result.last_used_port) {
|
||||
if (result.last_used_port == "ble" || result.last_used_port == "tcp" || result.last_used_port == "udp" || result.last_used_port == "sitl" || result.last_used_port == "sitl-demo") {
|
||||
$('#port').val(result.last_used_port);
|
||||
} else {
|
||||
current_ports.forEach(function(port) {
|
||||
if (port == result.last_used_port) {
|
||||
console.log('Selecting last used port: ' + result.last_used_port);
|
||||
$('#port').val(result.last_used_port);
|
||||
}
|
||||
});
|
||||
}
|
||||
var last_used_port = store.get('last_used_port', false);
|
||||
// if last_used_port was set, we try to select it
|
||||
if (last_used_port) {
|
||||
if (last_used_port == "ble" || last_used_port == "tcp" || last_used_port == "udp" || last_used_port == "sitl" || last_used_port == "sitl-demo") {
|
||||
$('#port').val(last_used_port);
|
||||
} else {
|
||||
console.log('Last used port wasn\'t saved "yet", auto-select disabled.');
|
||||
current_ports.forEach(function(port) {
|
||||
if (port == last_used_port) {
|
||||
console.log('Selecting last used port: ' + last_used_port);
|
||||
$('#port').val(last_used_port);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Last used port wasn\'t saved "yet", auto-select disabled.');
|
||||
}
|
||||
|
||||
var last_used_bps = store.get('last_used_bps', false);
|
||||
if (last_used_bps) {
|
||||
$('#baud').val(last_used_bps);
|
||||
}
|
||||
|
||||
chrome.storage.local.get('last_used_bps', function (result) {
|
||||
if (result['last_used_bps']) {
|
||||
$('#baud').val(result['last_used_bps']);
|
||||
}
|
||||
});
|
||||
|
||||
chrome.storage.local.get('wireless_mode_enabled', function (result) {
|
||||
if (result['wireless_mode_enabled']) {
|
||||
$('#wireless-mode').prop('checked', true).change();
|
||||
}
|
||||
});
|
||||
if (store.get('wireless_mode_enabled', false)) {
|
||||
$('#wireless-mode').prop('checked', true).change();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -154,7 +143,7 @@ PortHandler.check = function () {
|
|||
self.initial_ports = current_ports;
|
||||
}
|
||||
|
||||
self.check_usb_devices();
|
||||
//self.check_usb_devices();
|
||||
|
||||
GUI.updateManualPortVisibility();
|
||||
setTimeout(function () {
|
||||
|
@ -164,22 +153,29 @@ PortHandler.check = function () {
|
|||
};
|
||||
|
||||
PortHandler.check_usb_devices = function (callback) {
|
||||
chrome.usb.getDevices(usbDevices, function (result) {
|
||||
if (result.length) {
|
||||
if (!$("div#port-picker #port [value='DFU']").length) {
|
||||
$('div#port-picker #port').append($('<option/>', {value: "DFU", text: "DFU", data: {isDFU: true}}));
|
||||
$('div#port-picker #port').val('DFU');
|
||||
}
|
||||
|
||||
self.dfu_available = false;
|
||||
for (const device of usbDevices) {
|
||||
if (findByIds(device.vendorId, device.productId)) {
|
||||
self.dfu_available = true;
|
||||
} else {
|
||||
if ($("div#port-picker #port [value='DFU']").length) {
|
||||
$("div#port-picker #port [value='DFU']").remove();
|
||||
}
|
||||
self.dfu_available = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.dfu_available) {
|
||||
if (!$("div#port-picker #port [value='DFU']").length) {
|
||||
$('div#port-picker #port').append($('<option/>', {value: "DFU", text: "DFU", data: {isDFU: true}}));
|
||||
$('div#port-picker #port').val('DFU');
|
||||
}
|
||||
} else {
|
||||
if ($("div#port-picker #port [value='DFU']").length) {
|
||||
$("div#port-picker #port [value='DFU']").remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (callback)
|
||||
callback(self.dfu_available);
|
||||
|
||||
if (callback) callback(self.dfu_available);
|
||||
});
|
||||
};
|
||||
|
||||
PortHandler.update_port_select = function (ports) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue