mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-19 14:25:14 +03:00
Merge pull request #1296 from mikeller/add_vcp_detection
Added auto-detection of VCP targets. Also added re-connecting after reboot for VCP targets.
This commit is contained in:
commit
0deb83a370
8 changed files with 71 additions and 135 deletions
46
src/js/fc.js
46
src/js/fc.js
|
@ -466,20 +466,6 @@ var FC = {
|
|||
};
|
||||
},
|
||||
|
||||
MCU_TYPES: {
|
||||
0: "SIMULATOR",
|
||||
1: "F103",
|
||||
2: "F303",
|
||||
3: "F40X",
|
||||
4: "F411",
|
||||
5: "F446",
|
||||
6: "F722",
|
||||
7: "F745",
|
||||
8: "F746",
|
||||
9: "F765",
|
||||
255: "Unknown MCU",
|
||||
},
|
||||
|
||||
getHardwareName: function () {
|
||||
let name;
|
||||
if (CONFIG.targetName) {
|
||||
|
@ -499,7 +485,37 @@ var FC = {
|
|||
return name;
|
||||
},
|
||||
|
||||
MCU_TYPES: {
|
||||
0: "SIMULATOR",
|
||||
1: "F103",
|
||||
2: "F303",
|
||||
3: "F40X",
|
||||
4: "F411",
|
||||
5: "F446",
|
||||
6: "F722",
|
||||
7: "F745",
|
||||
8: "F746",
|
||||
9: "F765",
|
||||
255: "Unknown MCU",
|
||||
},
|
||||
|
||||
getMcuType: function () {
|
||||
return FC.MCU_TYPES[CONFIG.mcuTypeId];
|
||||
}
|
||||
},
|
||||
|
||||
COMM_CAPABILITIES_FLAGS: {
|
||||
HAS_VCP: 0x01,
|
||||
HAS_SOFTSERIAL: 0x02,
|
||||
},
|
||||
|
||||
boardHasVcp: function () {
|
||||
var hasVcp = false;
|
||||
if (semver.gte(CONFIG.apiVersion, "1.37.0")) {
|
||||
hasVcp = (CONFIG.commCapabilities & FC.COMM_CAPABILITIES_FLAGS.HAS_VCP) !== 0;
|
||||
} else {
|
||||
hasVcp = BOARD.find_board_definition(CONFIG.boardIdentifier).vcp;
|
||||
}
|
||||
|
||||
return hasVcp;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -724,3 +724,23 @@ function update_dataflash_global() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
function reinitialiseConnection(originatorTab, callback) {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (FC.boardHasVcp()) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
setTimeout(function start_connection() {
|
||||
$('a.connect').click();
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}, 2500);
|
||||
} else {
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
originatorTab.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
}, 1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,24 +291,7 @@ TABS.cli.read = function (readInfo) {
|
|||
CONFIGURATOR.cliActive = false;
|
||||
CONFIGURATOR.cliValid = false;
|
||||
GUI.log(i18n.getMessage('cliReboot'));
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection', function start_connection() {
|
||||
$('a.connect').click();
|
||||
}, 2500);
|
||||
} else {
|
||||
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
if (!GUI.tab_switch_in_progress) {
|
||||
$('#tabs ul.mode-connected .tab_setup a').click();
|
||||
}
|
||||
});
|
||||
}, 1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
reinitialiseConnection(self);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -347,7 +330,10 @@ TABS.cli.send = function (line, callback) {
|
|||
|
||||
TABS.cli.cleanup = function (callback) {
|
||||
if (!(CONFIGURATOR.connectionValid && CONFIGURATOR.cliValid && CONFIGURATOR.cliActive)) {
|
||||
if (callback) callback();
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
this.send(getCliCommand('exit\r', this.cliBuffer), function (writeInfo) {
|
||||
|
@ -355,9 +341,10 @@ TABS.cli.cleanup = function (callback) {
|
|||
// (another approach is however much more complicated):
|
||||
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
|
||||
// we could probably implement this someday
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
if (callback) callback();
|
||||
}, 1000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
|
||||
reinitialiseConnection(self, function () {
|
||||
GUI.timeout_add('tab_change_callback', callback, 500);
|
||||
});
|
||||
CONFIGURATOR.cliActive = false;
|
||||
CONFIGURATOR.cliValid = false;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1194,29 +1194,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
|
|||
GUI.log(i18n.getMessage('configurationEepromSaved'));
|
||||
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
|
||||
reinitialiseConnection(self);
|
||||
});
|
||||
}
|
||||
|
||||
function reinitialize() {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection',function start_connection() {
|
||||
$('a.connect').click();
|
||||
},2500);
|
||||
} else {
|
||||
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
TABS.configuration.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
},1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
}
|
||||
|
||||
save_serial_config();
|
||||
});
|
||||
|
||||
|
|
|
@ -391,29 +391,11 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
|
|||
GUI.log(i18n.getMessage('configurationEepromSaved'));
|
||||
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
|
||||
reinitialiseConnection(self);
|
||||
});
|
||||
}
|
||||
|
||||
function reinitialize() {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection',function start_connection() {
|
||||
$('a.connect').click();
|
||||
},2500);
|
||||
} else {
|
||||
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
TABS.failsafe.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
},1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
}
|
||||
|
||||
MSP.send_message(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG), false, save_failssafe_config);
|
||||
});
|
||||
|
||||
|
|
|
@ -50,29 +50,11 @@ TABS.onboard_logging.initialize = function (callback) {
|
|||
GUI.log(i18n.getMessage('configurationEepromSaved'));
|
||||
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
|
||||
reinitialiseConnection(self);
|
||||
});
|
||||
}
|
||||
|
||||
function reinitialize() {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection',function start_connection() {
|
||||
$('a.connect').click();
|
||||
},2000);
|
||||
} else {
|
||||
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
TABS.onboard_logging.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
},1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
}
|
||||
|
||||
function load_html() {
|
||||
$('#content').load("./tabs/onboard_logging.html", function() {
|
||||
// translate to user-selected language
|
||||
|
@ -424,7 +406,7 @@ TABS.onboard_logging.initialize = function (callback) {
|
|||
|
||||
function flash_save_begin() {
|
||||
if (GUI.connected_to) {
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) {
|
||||
if (FC.boardHasVcp()) {
|
||||
if (semver.gte(CONFIG.apiVersion, "1.31.0")) {
|
||||
self.blockSize = self.VCP_BLOCK_SIZE;
|
||||
} else {
|
||||
|
|
|
@ -347,27 +347,10 @@ TABS.ports.initialize = function (callback, scrollPosition) {
|
|||
GUI.log(i18n.getMessage('configurationEepromSaved'));
|
||||
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, on_reboot_success_handler);
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
|
||||
reinitialiseConnection(self);
|
||||
});
|
||||
}
|
||||
|
||||
function on_reboot_success_handler() {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
|
||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection',function start_connection() {
|
||||
$('a.connect').click();
|
||||
},2500);
|
||||
} else {
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_STATUS, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
TABS.ports.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
}, 1500); // seems to be just the right amount of delay to prevent data request timeouts
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -304,7 +304,8 @@ TABS.transponder.initialize = function(callback, scrollPosition) {
|
|||
GUI.log(i18n.getMessage('transponderEepromSaved'));
|
||||
if ( $(_this).hasClass('reboot') ) {
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false, reinitialize);
|
||||
MSP.send_message(MSPCodes.MSP_SET_REBOOT, false, false);
|
||||
reinitialiseConnection(self);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -320,23 +321,6 @@ TABS.transponder.initialize = function(callback, scrollPosition) {
|
|||
});
|
||||
}
|
||||
|
||||
function reinitialize() {
|
||||
GUI.log(i18n.getMessage('deviceRebooting'));
|
||||
if ( BOARD.find_board_definition(CONFIG.boardIdentifier).vcp ) {
|
||||
$('a.connect').click();
|
||||
GUI.timeout_add('start_connection', function start_connection() {
|
||||
$('a.connect').click();
|
||||
}, 2500);
|
||||
} else {
|
||||
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
|
||||
MSP.send_message(MSPCodes.MSP_IDENT, false, false, function() {
|
||||
GUI.log(i18n.getMessage('deviceReady'));
|
||||
TABS.configuration.initialize(false, $('#content').scrollTop());
|
||||
});
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.content_ready(callback);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue