mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
parent
4fea844edb
commit
3b088d7416
3 changed files with 58 additions and 69 deletions
|
@ -1,4 +1,4 @@
|
||||||
import GUI, { TABS } from "./gui";
|
import GUI from "./gui";
|
||||||
import FC from "./fc";
|
import FC from "./fc";
|
||||||
import { i18n } from "./localization";
|
import { i18n } from "./localization";
|
||||||
import { get as getConfig } from "./ConfigStorage";
|
import { get as getConfig } from "./ConfigStorage";
|
||||||
|
@ -109,7 +109,8 @@ PortHandler.check_serial_devices = function () {
|
||||||
} else {
|
} else {
|
||||||
self.removePort();
|
self.removePort();
|
||||||
self.detectPort();
|
self.detectPort();
|
||||||
self.selectActivePort();
|
// already done in detectPort
|
||||||
|
// self.selectActivePort();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -235,10 +236,6 @@ PortHandler.detectPort = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.port_available = true;
|
self.port_available = true;
|
||||||
// Signal board verification
|
|
||||||
if (GUI.active_tab === 'firmware_flasher' && TABS.firmware_flasher.allowBoardDetection) {
|
|
||||||
TABS.firmware_flasher.boardNeedsVerification = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// auto-connect if enabled
|
// auto-connect if enabled
|
||||||
if (this.portPicker.autoConnect && !GUI.connecting_to && !GUI.connected_to && GUI.active_tab !== 'firmware_flasher') {
|
if (this.portPicker.autoConnect && !GUI.connecting_to && !GUI.connected_to && GUI.active_tab !== 'firmware_flasher') {
|
||||||
|
|
|
@ -694,6 +694,10 @@ function onClosed(result) {
|
||||||
|
|
||||||
MSP.clearListeners();
|
MSP.clearListeners();
|
||||||
|
|
||||||
|
serial.removeEventListener('receive', read_serial_adapter);
|
||||||
|
serial.removeEventListener('connect', connectHandler);
|
||||||
|
serial.removeEventListener('disconnect', disconnectHandler);
|
||||||
|
|
||||||
CONFIGURATOR.connectionValid = false;
|
CONFIGURATOR.connectionValid = false;
|
||||||
CONFIGURATOR.cliValid = false;
|
CONFIGURATOR.cliValid = false;
|
||||||
CONFIGURATOR.cliActive = false;
|
CONFIGURATOR.cliActive = false;
|
||||||
|
|
|
@ -33,8 +33,6 @@ const firmware_flasher = {
|
||||||
sponsor: new Sponsor(),
|
sponsor: new Sponsor(),
|
||||||
localFirmwareLoaded: false,
|
localFirmwareLoaded: false,
|
||||||
selectedBoard: undefined,
|
selectedBoard: undefined,
|
||||||
boardNeedsVerification: false,
|
|
||||||
allowBoardDetection: true,
|
|
||||||
cloudBuildKey: null,
|
cloudBuildKey: null,
|
||||||
cloudBuildOptions: null,
|
cloudBuildOptions: null,
|
||||||
isFlashing: false,
|
isFlashing: false,
|
||||||
|
@ -57,7 +55,6 @@ firmware_flasher.initialize = function (callback) {
|
||||||
|
|
||||||
// reset on tab change
|
// reset on tab change
|
||||||
self.selectedBoard = undefined;
|
self.selectedBoard = undefined;
|
||||||
self.allowBoardDetection = true;
|
|
||||||
|
|
||||||
self.cloudBuildKey = null;
|
self.cloudBuildKey = null;
|
||||||
self.cloudBuildOptions = null;
|
self.cloudBuildOptions = null;
|
||||||
|
@ -978,31 +975,6 @@ firmware_flasher.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
portPickerElement.on('change', function () {
|
|
||||||
if (GUI.active_tab === 'firmware_flasher') {
|
|
||||||
if (!GUI.connect_lock) {
|
|
||||||
if ($('option:selected', this).data().isDFU) {
|
|
||||||
self.enableDfuExitButton(true);
|
|
||||||
} else {
|
|
||||||
if (!self.isFlashing) {
|
|
||||||
// Porthandler resets board on port detect
|
|
||||||
if (self.allowBoardDetection && self.boardNeedsVerification) {
|
|
||||||
// reset to prevent multiple calls
|
|
||||||
self.boardNeedsVerification = false;
|
|
||||||
self.verifyBoard();
|
|
||||||
}
|
|
||||||
if (self.selectedBoard) {
|
|
||||||
self.enableLoadRemoteFileButton(true);
|
|
||||||
self.enableLoadFileButton(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.enableDfuExitButton(false);
|
|
||||||
self.updateDetectBoardButton();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).trigger('change');
|
|
||||||
|
|
||||||
const targetSupportInfo = $('#targetSupportInfoUrl');
|
const targetSupportInfo = $('#targetSupportInfoUrl');
|
||||||
|
|
||||||
targetSupportInfo.on('click', function() {
|
targetSupportInfo.on('click', function() {
|
||||||
|
@ -1018,13 +990,14 @@ firmware_flasher.initialize = function (callback) {
|
||||||
|
|
||||||
detectBoardElement.on('click', () => {
|
detectBoardElement.on('click', () => {
|
||||||
detectBoardElement.toggleClass('disabled', true);
|
detectBoardElement.toggleClass('disabled', true);
|
||||||
self.boardNeedsVerification = false;
|
|
||||||
|
|
||||||
self.verifyBoard();
|
self.verifyBoard();
|
||||||
// prevent spamming the button
|
// prevent spamming the button
|
||||||
setTimeout(() => detectBoardElement.toggleClass('disabled', false), 1000);
|
setTimeout(() => detectBoardElement.toggleClass('disabled', false), 2000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.updateDetectBoardButton();
|
||||||
|
|
||||||
$('a.flash_firmware').on('click', function () {
|
$('a.flash_firmware').on('click', function () {
|
||||||
self.isFlashing = true;
|
self.isFlashing = true;
|
||||||
const isFlashOnConnect = $('input.flash_on_connect').is(':checked');
|
const isFlashOnConnect = $('input.flash_on_connect').is(':checked');
|
||||||
|
@ -1242,7 +1215,7 @@ firmware_flasher.isSerialPortAvailable = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
firmware_flasher.updateDetectBoardButton = function() {
|
firmware_flasher.updateDetectBoardButton = function() {
|
||||||
$('a.detect-board').toggleClass('disabled', !this.isSerialPortAvailable() && this.boardNeedsVerification && this.allowBoardDetection);
|
$('a.detect-board').toggleClass('disabled', !this.isSerialPortAvailable());
|
||||||
};
|
};
|
||||||
|
|
||||||
firmware_flasher.validateBuildKey = function() {
|
firmware_flasher.validateBuildKey = function() {
|
||||||
|
@ -1256,36 +1229,51 @@ firmware_flasher.validateBuildKey = function() {
|
||||||
|
|
||||||
firmware_flasher.verifyBoard = function() {
|
firmware_flasher.verifyBoard = function() {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
const isFlashOnConnect = $('input.flash_on_connect').is(':checked');
|
const isFlashOnConnect = $('input.flash_on_connect').is(':checked');
|
||||||
|
let targetAvailable = false;
|
||||||
|
|
||||||
if (!self.isSerialPortAvailable() || isFlashOnConnect) {
|
if (!self.isSerialPortAvailable() || isFlashOnConnect) {
|
||||||
// return silently as port-picker will trigger again when port becomes available
|
// return silently as port-picker will trigger again when port becomes available
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onClose(success) {
|
function read_serial_adapter(event) {
|
||||||
if (!success) {
|
MSP.read(event.detail.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectHandler(event) {
|
||||||
|
onConnect(event.detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function disconnectHandler(event) {
|
||||||
|
onClosed(event.detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onClosed(result) {
|
||||||
|
if (result) { // All went as expected
|
||||||
|
gui_log(i18n.getMessage('serialPortClosedOk'));
|
||||||
|
} else { // Something went wrong
|
||||||
|
gui_log(i18n.getMessage('serialPortClosedFail'));
|
||||||
|
}
|
||||||
|
if (!targetAvailable) {
|
||||||
gui_log(i18n.getMessage('firmwareFlasherBoardVerificationFail'));
|
gui_log(i18n.getMessage('firmwareFlasherBoardVerificationFail'));
|
||||||
}
|
}
|
||||||
|
|
||||||
serial.disconnect(function () {
|
MSP.clearListeners();
|
||||||
MSP.clearListeners();
|
|
||||||
MSP.disconnect_cleanup();
|
|
||||||
});
|
|
||||||
|
|
||||||
// re-enable auto-detect
|
serial.removeEventListener('receive', read_serial_adapter);
|
||||||
self.allowBoardDetection = true;
|
serial.removeEventListener('connect', connectHandler);
|
||||||
|
serial.removeEventListener('disconnect', disconnectHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFinish() {
|
function onFinishClose() {
|
||||||
const board = FC.CONFIG.boardName;
|
const board = FC.CONFIG.boardName;
|
||||||
const boardSelect = $('select[name="board"]');
|
|
||||||
const boardSelectOptions = $('select[name="board"] option');
|
|
||||||
const target = boardSelect.val();
|
|
||||||
let targetAvailable = false;
|
|
||||||
|
|
||||||
if (board) {
|
if (board) {
|
||||||
|
const boardSelect = $('select[name="board"]');
|
||||||
|
const boardSelectOptions = $('select[name="board"] option');
|
||||||
|
const target = boardSelect.val();
|
||||||
|
|
||||||
boardSelectOptions.each((_, e) => {
|
boardSelectOptions.each((_, e) => {
|
||||||
if ($(e).text() === board) {
|
if ($(e).text() === board) {
|
||||||
targetAvailable = true;
|
targetAvailable = true;
|
||||||
|
@ -1299,7 +1287,8 @@ firmware_flasher.verifyBoard = function() {
|
||||||
gui_log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', { boardName: board }));
|
gui_log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', { boardName: board }));
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose(targetAvailable);
|
serial.disconnect(onClosed);
|
||||||
|
MSP.disconnect_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestBoardInformation(onSucces, onFail) {
|
function requestBoardInformation(onSucces, onFail) {
|
||||||
|
@ -1320,7 +1309,7 @@ firmware_flasher.verifyBoard = function() {
|
||||||
FC.processBuildOptions();
|
FC.processBuildOptions();
|
||||||
self.cloudBuildOptions = FC.CONFIG.buildOptions;
|
self.cloudBuildOptions = FC.CONFIG.buildOptions;
|
||||||
}
|
}
|
||||||
onFinish();
|
onFinishClose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,18 +1345,19 @@ firmware_flasher.verifyBoard = function() {
|
||||||
|
|
||||||
function onConnect(openInfo) {
|
function onConnect(openInfo) {
|
||||||
if (openInfo) {
|
if (openInfo) {
|
||||||
serial.onReceive.addListener(data => MSP.read(data));
|
serial.removeEventListener('receive', read_serial_adapter);
|
||||||
|
serial.addEventListener('receive', read_serial_adapter);
|
||||||
|
|
||||||
mspHelper = new MspHelper();
|
mspHelper = new MspHelper();
|
||||||
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
||||||
requestBoardInformation(getBuildInfo, onClose);
|
requestBoardInformation(getBuildInfo, onFinishClose);
|
||||||
} else {
|
} else {
|
||||||
gui_log(i18n.getMessage('serialPortOpenFail'));
|
gui_log(i18n.getMessage('serialPortOpenFail'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mspHelper;
|
let mspHelper;
|
||||||
const port = String($('div#port-picker #port').val());
|
const port = PortHandler.portPicker.selectedPort;
|
||||||
const baud = $('input.flash_manual_baud').is(':checked') ? parseInt($('#flash_manual_baud_rate').val()) : 115200;
|
|
||||||
const isLoaded = self.targets ? Object.keys(self.targets).length > 0 : false;
|
const isLoaded = self.targets ? Object.keys(self.targets).length > 0 : false;
|
||||||
|
|
||||||
if (!isLoaded) {
|
if (!isLoaded) {
|
||||||
|
@ -1376,14 +1366,18 @@ firmware_flasher.verifyBoard = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(serial.connected || serial.connectionId)) {
|
if (serial.connected || serial.connectionId) {
|
||||||
// Prevent auto-detect during board verification
|
|
||||||
self.allowBoardDetection = false;
|
|
||||||
gui_log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
|
|
||||||
serial.connect(port, {bitrate: baud}, onConnect);
|
|
||||||
} else {
|
|
||||||
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId, serial.openCanceled);
|
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId, serial.openCanceled);
|
||||||
|
serial.disconnect();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui_log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
|
||||||
|
|
||||||
|
serial.addEventListener('connect', connectHandler);
|
||||||
|
serial.addEventListener('disconnect', disconnectHandler);
|
||||||
|
|
||||||
|
serial.connect(port, { baudRate: 115200 });
|
||||||
};
|
};
|
||||||
|
|
||||||
firmware_flasher.getPort = function () {
|
firmware_flasher.getPort = function () {
|
||||||
|
@ -1501,8 +1495,6 @@ firmware_flasher.backupConfig = function (callback) {
|
||||||
if (PortHandler.port_available) {
|
if (PortHandler.port_available) {
|
||||||
console.log(`Connection ready for flashing in ${count / 10} seconds`);
|
console.log(`Connection ready for flashing in ${count / 10} seconds`);
|
||||||
clearInterval(disconnect);
|
clearInterval(disconnect);
|
||||||
// Allow auto-detect after CLI reset
|
|
||||||
self.allowBoardDetection = true;
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
@ -1521,8 +1513,6 @@ firmware_flasher.backupConfig = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSaveConfig() {
|
function onSaveConfig() {
|
||||||
// Prevent auto-detect after CLI reset
|
|
||||||
TABS.firmware_flasher.allowBoardDetection = false;
|
|
||||||
|
|
||||||
activateCliMode()
|
activateCliMode()
|
||||||
.then(readCommand)
|
.then(readCommand)
|
||||||
|
@ -1556,8 +1546,6 @@ firmware_flasher.backupConfig = function (callback) {
|
||||||
const port = this.getPort();
|
const port = this.getPort();
|
||||||
|
|
||||||
if (port !== '0') {
|
if (port !== '0') {
|
||||||
// Prevent auto-detect during backup
|
|
||||||
self.allowBoardDetection = false;
|
|
||||||
const baud = parseInt($('#flash_manual_baud_rate').val()) || 115200;
|
const baud = parseInt($('#flash_manual_baud_rate').val()) || 115200;
|
||||||
serial.connect(port, {bitrate: baud}, onConnect);
|
serial.connect(port, {bitrate: baud}, onConnect);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue