mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-23 00:05:22 +03:00
Auto merged - #2524 at Sun, 01 Aug 2021 03:17:09 GMT
Detect board in firmware_flasher patch
This commit is contained in:
commit
3db052fda4
7 changed files with 107 additions and 29 deletions
|
@ -12,6 +12,7 @@ const PortHandler = new function () {
|
|||
this.port_detected_callbacks = [];
|
||||
this.port_removed_callbacks = [];
|
||||
this.dfu_available = false;
|
||||
this.port_available = false;
|
||||
};
|
||||
|
||||
PortHandler.initialize = function () {
|
||||
|
@ -118,6 +119,7 @@ PortHandler.removePort = function(currentPorts) {
|
|||
|
||||
if (removePorts.length) {
|
||||
console.log(`PortHandler - Removed: ${JSON.stringify(removePorts)}`);
|
||||
self.port_available = false;
|
||||
// disconnect "UI" - routine can't fire during atmega32u4 reboot procedure !!!
|
||||
if (GUI.connected_to) {
|
||||
for (let i = 0; i < removePorts.length; i++) {
|
||||
|
@ -170,6 +172,7 @@ PortHandler.detectPort = function(currentPorts) {
|
|||
}
|
||||
});
|
||||
|
||||
self.port_available = true;
|
||||
// Signal board verification
|
||||
if (GUI.active_tab === 'firmware_flasher') {
|
||||
TABS.firmware_flasher.boardNeedsVerification = true;
|
||||
|
@ -266,6 +269,7 @@ PortHandler.selectPort = function(ports) {
|
|||
const legacyDeviceRecognized = portName.includes('usb');
|
||||
if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) {
|
||||
this.portPickerElement.val(pathSelect);
|
||||
this.port_available = true;
|
||||
console.log(`Porthandler detected device ${portName} on port: ${pathSelect}`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,12 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
});
|
||||
} else {
|
||||
|
||||
var startFlashing = function() {
|
||||
let rebootMode = 0; // FIRMWARE
|
||||
const startFlashing = () => {
|
||||
if (rebootMode === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// refresh device list
|
||||
PortHandler.check_usb_devices(function(dfu_available) {
|
||||
if (dfu_available) {
|
||||
|
@ -144,7 +149,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
GUI.log(i18n.getMessage('apiVersionReceived', [FC.CONFIG.apiVersion]));
|
||||
|
||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
|
||||
|
||||
self.msp_connector.disconnect(function (disconnectionResult) {
|
||||
|
||||
// need some time for the port to be closed, serial port does not open if tried immediately
|
||||
|
@ -154,7 +158,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
console.log('Looking for capabilities via MSP');
|
||||
|
||||
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, () => {
|
||||
var rebootMode = 0; // FIRMWARE
|
||||
if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER)) {
|
||||
// Board has flash bootloader
|
||||
GUI.log(i18n.getMessage('deviceRebooting_flashBootloader'));
|
||||
|
@ -166,7 +169,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
rebootMode = 1; // MSP_REBOOT_BOOTLOADER_ROM;
|
||||
}
|
||||
|
||||
const selectedBoard = TABS.firmware_flasher.selectedBoard;
|
||||
const selectedBoard = TABS.firmware_flasher.selectedBoard !== '0' ? TABS.firmware_flasher.selectedBoard : 'NONE';
|
||||
const connectedBoard = FC.CONFIG.boardName ? FC.CONFIG.boardName : 'UNKNOWN';
|
||||
|
||||
function reboot() {
|
||||
|
@ -179,7 +182,6 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
self.msp_connector.disconnect(disconnectionResult => onDisconnect(disconnectionResult));
|
||||
|
||||
}, () => console.log('Reboot request received by device'));
|
||||
|
||||
}
|
||||
|
||||
function onAbort() {
|
||||
|
@ -190,12 +192,11 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
TABS.firmware_flasher.refresh();
|
||||
}
|
||||
|
||||
if (selectedBoard !== connectedBoard) {
|
||||
if (selectedBoard !== connectedBoard && !TABS.firmware_flasher.localFirmwareLoaded) {
|
||||
TABS.firmware_flasher.showDialogVerifyBoard(selectedBoard, connectedBoard, onAbort, reboot);
|
||||
} else {
|
||||
reboot();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -209,6 +210,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
|
|||
|
||||
var onFailureHandler = function() {
|
||||
GUI.connect_lock = false;
|
||||
TABS.firmware_flasher.refresh();
|
||||
};
|
||||
|
||||
GUI.connect_lock = true;
|
||||
|
@ -323,7 +325,6 @@ STM32_protocol.prototype.send = function (bytes_to_send, bytes_to_read, callback
|
|||
// data = response of n bytes from mcu (array)
|
||||
// result = true/false
|
||||
STM32_protocol.prototype.verify_response = function (val, data) {
|
||||
var self = this;
|
||||
|
||||
if (val != data[0]) {
|
||||
var message = 'STM32 Communication failed, wrong response, expected: ' + val + ' (0x' + val.toString(16) + ') received: ' + data[0] + ' (0x' + data[0].toString(16) + ')';
|
||||
|
|
|
@ -18,10 +18,7 @@ const serial = {
|
|||
connect: function (path, options, callback) {
|
||||
const self = this;
|
||||
const testUrl = path.match(/^tcp:\/\/([A-Za-z0-9\.-]+)(?:\:(\d+))?$/);
|
||||
if (self.connectionId || self.connected) {
|
||||
console.warn('We already connected. Aborting', self.connectionId, self.connected);
|
||||
return;
|
||||
}
|
||||
|
||||
if (testUrl) {
|
||||
self.connectTcp(testUrl[1], testUrl[2], options, callback);
|
||||
} else if (path === 'virtual') {
|
||||
|
|
|
@ -317,8 +317,6 @@ firmware_flasher.initialize = function (callback) {
|
|||
$('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
verifyBoard();
|
||||
}
|
||||
|
||||
const buildTypes = [
|
||||
|
@ -344,8 +342,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
loader: () => self.jenkinsLoader.loadBuilds(job.name, loadUnifiedBuilds)
|
||||
};
|
||||
});
|
||||
let buildTypesToShow;
|
||||
|
||||
let buildTypesToShow;
|
||||
const buildType_e = $('select[name="build_type"]');
|
||||
function buildBuildTypeOptionsList() {
|
||||
buildType_e.empty();
|
||||
|
@ -536,9 +534,15 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
$('select[name="board"]').change(function() {
|
||||
$("a.load_remote_file").addClass('disabled');
|
||||
const target = $(this).val();
|
||||
let target = $(this).val();
|
||||
|
||||
if (!GUI.connect_lock && target) {
|
||||
// exception for board flashed with local custom firmware
|
||||
if (target === null) {
|
||||
target = '0';
|
||||
$(this).val(target).trigger('change');
|
||||
}
|
||||
|
||||
if (!GUI.connect_lock) {
|
||||
if (TABS.firmware_flasher.selectedBoard !== target) {
|
||||
// We're sure the board actually changed
|
||||
if (self.isConfigLocal) {
|
||||
|
@ -547,7 +551,11 @@ firmware_flasher.initialize = function (callback) {
|
|||
self.unifiedTarget = {};
|
||||
}
|
||||
}
|
||||
ConfigStorage.set({'selected_board': target});
|
||||
|
||||
if (target !== '0') {
|
||||
ConfigStorage.set({'selected_board': target});
|
||||
}
|
||||
|
||||
TABS.firmware_flasher.selectedBoard = target;
|
||||
TABS.firmware_flasher.bareBoard = undefined;
|
||||
console.log('board changed to', target);
|
||||
|
@ -563,7 +571,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
|
||||
const versions_e = $('select[name="firmware_version"]');
|
||||
if (target === 0) {
|
||||
if (target === '0') {
|
||||
// target is 0 is the "Choose a Board" option. Throw out anything loaded
|
||||
clearBufferedFirmware();
|
||||
|
||||
|
@ -774,7 +782,6 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
function onFinishClose() {
|
||||
MSP.clearListeners();
|
||||
GUI.connect_lock = false;
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
|
@ -795,18 +802,28 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
function getBoard() {
|
||||
console.log(`Requesting board information`);
|
||||
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, () => MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, onFinish));
|
||||
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, () => {
|
||||
if (!FC.CONFIG.apiVersion || FC.CONFIG.apiVersion === 'null.null.0') {
|
||||
FC.CONFIG.apiVersion = '0.0.0';
|
||||
}
|
||||
console.log(FC.CONFIG.apiVersion);
|
||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_39)) {
|
||||
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, onFinish);
|
||||
} else {
|
||||
console.log('Firmware version not supported for reading board information');
|
||||
onClose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onConnect(openInfo) {
|
||||
if (openInfo) {
|
||||
GUI.connect_lock = true;
|
||||
serial.onReceive.addListener(data => MSP.read(data));
|
||||
const mspHelper = new MspHelper();
|
||||
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
||||
getBoard();
|
||||
} else {
|
||||
console.dir('Failed to open connection:', openInfo);
|
||||
GUI.log(i18n.getMessage('serialPortOpenFail'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -817,7 +834,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
if ($('input.flash_manual_baud').is(':checked')) {
|
||||
baud = parseInt($('#flash_manual_baud_rate').val());
|
||||
}
|
||||
console.log('Query board information to preselect right firmware');
|
||||
GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
|
||||
if (!(serial.connected || serial.connectionId)) {
|
||||
serial.connect(port, {bitrate: baud}, onConnect);
|
||||
} else {
|
||||
|
@ -825,12 +842,40 @@ firmware_flasher.initialize = function (callback) {
|
|||
serial.disconnect();
|
||||
}
|
||||
} else {
|
||||
console.log('Please select valid serial port');
|
||||
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const detectBoardElement = $('a.detect-board');
|
||||
let isClickable = true;
|
||||
|
||||
detectBoardElement.on('click', () => {
|
||||
detectBoardElement.addClass('disabled');
|
||||
|
||||
if (isClickable) {
|
||||
isClickable = false;
|
||||
verifyBoard();
|
||||
setTimeout(() => isClickable = true, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function updateDetectBoardButton() {
|
||||
const board = $('select[name="board"] option:selected').val();
|
||||
const firmwareVersion = $('select[name="firmware_version"] option:selected').val();
|
||||
const isDfu = portPickerElement.val().includes('DFU');
|
||||
const isBusy = GUI.connect_lock;
|
||||
const isLoaded = board !== '0' && firmwareVersion !== '0';
|
||||
const isAvailable = PortHandler.port_available || false;
|
||||
const isButtonDisabled = isDfu || isBusy || !isLoaded || !isAvailable;
|
||||
|
||||
detectBoardElement.toggleClass('disabled', isButtonDisabled);
|
||||
}
|
||||
|
||||
document.querySelector('select[name="build_type"]').addEventListener('change', updateDetectBoardButton);
|
||||
document.querySelector('select[name="board"]').addEventListener('change', updateDetectBoardButton);
|
||||
document.querySelector('select[name="firmware_version"]').addEventListener('change', updateDetectBoardButton);
|
||||
|
||||
ConfigStorage.get('erase_chip', function (result) {
|
||||
if (result.erase_chip) {
|
||||
$('input.erase_chip').prop('checked', true);
|
||||
|
@ -1092,6 +1137,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
exitDfuElement.addClass('disabled');
|
||||
}
|
||||
}
|
||||
updateDetectBoardButton();
|
||||
}).change();
|
||||
|
||||
$('a.flash_firmware').click(function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue