mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 03:19:54 +03:00
Implemented target autodetection
This PR adds target autodetection to the firmware flasher. It will attempt an autodetect on load. Plus there is a manual button to autodetect by the description. - Extended MSPHelper to collect the missing data sent in `MSP_BOARD_INFO`. Plus added a `getTarget()` function. - Added target autodetect on load of Firmware Flasher. - Added button to Firmware Flasher to command an autodetect. - Toggling **Show unstable builds** now remembers the selected target. - Fixed **Offline** notices in the board and version select boxes. - Added target name to firmware version displayed when connected.
This commit is contained in:
parent
50d931f739
commit
cc09a8fe90
6 changed files with 188 additions and 7 deletions
|
@ -2176,6 +2176,9 @@
|
|||
"firmwareFlasherOptionLabelSelectFirmwareVersionFor": {
|
||||
"message": "Choose a Firmware version for"
|
||||
},
|
||||
"firmwareFlasherButtonAutoSelect": {
|
||||
"message": "Auto-select Target"
|
||||
},
|
||||
"firmwareFlasherButtonLoadLocal": {
|
||||
"message": "Load Firmware [Local]"
|
||||
},
|
||||
|
|
|
@ -777,6 +777,18 @@ var mspHelper = (function (gui) {
|
|||
CONFIG.boardIdentifier = identifier;
|
||||
CONFIG.boardVersion = data.getUint16(offset, 1);
|
||||
offset += 2;
|
||||
if (semver.gt(CONFIG.flightControllerVersion, "4.1.0")) {
|
||||
CONFIG.osdUsed = data.getUint8(offset++);
|
||||
CONFIG.commCompatability = data.getUint8(offset++);
|
||||
let targetNameLen = data.getUint8(offset++);
|
||||
let targetName = "";
|
||||
targetNameLen += offset;
|
||||
for (offset = offset; offset < targetNameLen; offset++) {
|
||||
targetName += String.fromCharCode(data.getUint8(offset));
|
||||
}
|
||||
CONFIG.target = targetName;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MSPCodes.MSP_SET_CHANNEL_FORWARDING:
|
||||
|
@ -3190,6 +3202,15 @@ var mspHelper = (function (gui) {
|
|||
MSP.send_message(MSPCodes.MSP_MOTOR, false, false, callback);
|
||||
};
|
||||
|
||||
self.getTarget = function(callback) {
|
||||
MSP.send_message(MSPCodes.MSP_FC_VERSION, false, false, function(resp){
|
||||
var target = resp.data.readString();
|
||||
if (callback) {
|
||||
callback(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.getCraftName = function (callback) {
|
||||
MSP.send_message(MSPCodes.MSP_NAME, false, false, function (resp) {
|
||||
var name = resp.data.readString();
|
||||
|
|
2
main.js
2
main.js
|
@ -657,7 +657,7 @@ function updateActivatedTab() {
|
|||
|
||||
function updateFirmwareVersion() {
|
||||
if (CONFIGURATOR.connectionValid) {
|
||||
$('#logo .firmware_version').text(CONFIG.flightControllerVersion);
|
||||
$('#logo .firmware_version').text(CONFIG.flightControllerVersion + " [" + CONFIG.target + "]");
|
||||
} else {
|
||||
$('#logo .firmware_version').text(chrome.i18n.getMessage('fcNotConnected'));
|
||||
}
|
||||
|
|
|
@ -49,6 +49,11 @@
|
|||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.tab-firmware_flasher .autoselect_description {
|
||||
margin-left: 10px;
|
||||
line-height: 25px;
|
||||
}
|
||||
|
||||
/*noinspection ALL*/
|
||||
.tab-firmware_flasher .info .progress::-webkit-progress-bar {
|
||||
background-color: #4f4f4f;
|
||||
|
|
|
@ -8,7 +8,10 @@
|
|||
<select name="board" id="board_targets">
|
||||
<option value="0">Loading ...</option>
|
||||
</select></td>
|
||||
<td><span class="description" i18n="firmwareFlasherOnlineSelectBoardDescription"></span></td>
|
||||
<td><div class="default_btn narrow">
|
||||
<a class="auto_select_target" href="#" i18n="firmwareFlasherButtonAutoSelect"></a>
|
||||
</div>
|
||||
<span class="autoselect_description description" i18n="firmwareFlasherOnlineSelectBoardDescription"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><select name="firmware_version">
|
||||
|
|
|
@ -50,8 +50,17 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
};
|
||||
}
|
||||
|
||||
$('input.show_development_releases').click(function(){
|
||||
$('input.show_development_releases').click(function() {
|
||||
let selectedTarget = String($('select[name="board"]').val());
|
||||
GUI.log("selected target = " + selectedTarget);
|
||||
buildBoardOptions();
|
||||
GUI.log("toggled RCs");
|
||||
if (selectedTarget === "0") {
|
||||
TABS.firmware_flasher.getTarget();
|
||||
} else {
|
||||
$('select[name="board"] option[value=' + selectedTarget + ']').attr("selected", "selected");
|
||||
$('select[name="board"]').change();
|
||||
}
|
||||
});
|
||||
|
||||
$('.target_search').on('input', function(){
|
||||
|
@ -74,10 +83,10 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
var buildBoardOptions = function(){
|
||||
var boards_e = $('select[name="board"]').empty();
|
||||
var showDevReleases = ($('input.show_development_releases').is(':checked'));
|
||||
boards_e.append($("<option value='0'>{0}</option>".format(chrome.i18n.getMessage('firmwareFlasherOptionLabelSelectBoard'))));
|
||||
|
||||
var versions_e = $('select[name="firmware_version"]').empty();
|
||||
var showDevReleases = ($('input.show_development_releases').is(':checked'));
|
||||
|
||||
boards_e.append($("<option value='0'>{0}</option>".format(chrome.i18n.getMessage('firmwareFlasherOptionLabelSelectBoard'))));
|
||||
versions_e.append($("<option value='0'>{0}</option>".format(chrome.i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion'))));
|
||||
|
||||
var releases = {};
|
||||
|
@ -140,6 +149,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
releases[result.target].push(descriptor);
|
||||
});
|
||||
});
|
||||
|
||||
var selectTargets = [];
|
||||
Object.keys(releases)
|
||||
.sort()
|
||||
|
@ -158,6 +168,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
});
|
||||
});
|
||||
TABS.firmware_flasher.releases = releases;
|
||||
return;
|
||||
};
|
||||
|
||||
$.get('https://api.github.com/repos/iNavFlight/inav/releases?per_page=10', function (releasesData){
|
||||
|
@ -198,11 +209,15 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
$('a.auto_select_target').removeClass('disabled');
|
||||
TABS.firmware_flasher.getTarget();
|
||||
}).fail(function (data){
|
||||
if (data["responseJSON"]){
|
||||
GUI.log("<b>GITHUB Query Failed: <code>{0}</code></b>".format(data["responseJSON"].message));
|
||||
}
|
||||
$('select[name="release"]').empty().append('<option value="0">Offline</option>');
|
||||
$('select[name="board"]').empty().append('<option value="0">Offline</option>');
|
||||
$('select[name="firmware_version"]').empty().append('<option value="0">Offline</option>');
|
||||
$('a.auto_select_target').addClass('disabled');
|
||||
});
|
||||
|
||||
$('a.load_file').on('click', function () {
|
||||
|
@ -561,6 +576,10 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
$('a.auto_select_target').click(function () {
|
||||
TABS.firmware_flasher.getTarget();
|
||||
});
|
||||
|
||||
GUI.content_ready(callback);
|
||||
});
|
||||
};
|
||||
|
@ -614,3 +633,133 @@ TABS.firmware_flasher.cleanup = function (callback) {
|
|||
|
||||
if (callback) callback();
|
||||
};
|
||||
|
||||
TABS.firmware_flasher.getTarget = function() {
|
||||
GUI.log("Attempting automatic target selection");
|
||||
|
||||
var selected_baud = parseInt($('#baud').val());
|
||||
var selected_port = $('#port').find('option:selected').data().isManual ? $('#port-override').val() : String($('#port').val());
|
||||
|
||||
if (selected_port !== 'DFU') {
|
||||
if (selected_port == '0') {
|
||||
GUI.log("Cannot prefetch target: No port");
|
||||
} else {
|
||||
console.log('Connecting to: ' + selected_port);
|
||||
GUI.connecting_to = selected_port;
|
||||
|
||||
if (selected_port == 'tcp' || selected_port == 'udp') {
|
||||
CONFIGURATOR.connection.connect($portOverride.val(), {}, TABS.firmware_flasher.onOpen);
|
||||
} else {
|
||||
CONFIGURATOR.connection.connect(selected_port, {bitrate: selected_baud}, TABS.firmware_flasher.onOpen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GUI.log("Cannot prefetch target: Flight Controller in DFU");
|
||||
}
|
||||
};
|
||||
|
||||
TABS.firmware_flasher.onOpen = function(openInfo) {
|
||||
if (openInfo) {
|
||||
GUI.connected_to = GUI.connecting_to;
|
||||
|
||||
// reset connecting_to
|
||||
GUI.connecting_to = false;
|
||||
|
||||
// save selected port with chrome.storage if the port differs
|
||||
chrome.storage.local.get('last_used_port', function (result) {
|
||||
if (result.last_used_port) {
|
||||
if (result.last_used_port != GUI.connected_to) {
|
||||
// last used port doesn't match the one found in local db, we will store the new one
|
||||
chrome.storage.local.set({'last_used_port': GUI.connected_to});
|
||||
}
|
||||
} else {
|
||||
// variable isn't stored yet, saving
|
||||
chrome.storage.local.set({'last_used_port': GUI.connected_to});
|
||||
}
|
||||
});
|
||||
|
||||
chrome.storage.local.set({last_used_bps: CONFIGURATOR.connection.bitrate});
|
||||
chrome.storage.local.set({wireless_mode_enabled: $('#wireless-mode').is(":checked")});
|
||||
|
||||
CONFIGURATOR.connection.addOnReceiveListener(read_serial);
|
||||
|
||||
// disconnect after 10 seconds with error if we don't get IDENT data
|
||||
helper.timeout.add('connecting', function () {
|
||||
if (!CONFIGURATOR.connectionValid) {
|
||||
GUI.log("Cannot prefetch target: " + chrome.i18n.getMessage('noConfigurationReceived'));
|
||||
|
||||
TABS.firmware_flasher.closeTempConnection();
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
FC.resetState();
|
||||
|
||||
// request configuration data. Start with MSPv1 and
|
||||
// upgrade to MSPv2 if possible.
|
||||
MSP.protocolVersion = MSP.constants.PROTOCOL_V2;
|
||||
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () {
|
||||
|
||||
if (CONFIG.apiVersion === "0.0.0") {
|
||||
GUI_control.prototype.log("Cannot prefetch target: <span style='color: red; font-weight: bolder'><strong>" + chrome.i18n.getMessage("illegalStateRestartRequired") + "</strong></span>");
|
||||
FC.restartRequired = true;
|
||||
return;
|
||||
}
|
||||
|
||||
MSP.send_message(MSPCodes.MSP_FC_VARIANT, false, false, function () {
|
||||
if (CONFIG.flightControllerIdentifier == 'INAV') {
|
||||
MSP.send_message(MSPCodes.MSP_FC_VERSION, false, false, function () {
|
||||
if (semver.gte(CONFIG.flightControllerVersion, CONFIGURATOR.minfirmwareVersionAccepted) && semver.lt(CONFIG.flightControllerVersion, CONFIGURATOR.maxFirmwareVersionAccepted)) {
|
||||
if (CONFIGURATOR.connection.type == ConnectionType.BLE && semver.lt(CONFIG.flightControllerVersion, "5.0.0")) {
|
||||
onBleNotSupported();
|
||||
} else {
|
||||
mspHelper.getCraftName(function(name) {
|
||||
if (name) {
|
||||
CONFIG.name = name;
|
||||
}
|
||||
TABS.firmware_flasher.onValidFirmware();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
onInvalidFirmwareVersion();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
GUI.log("Cannot prefetch target: Non-INAV Firmware");
|
||||
onInvalidFirmwareVariant();
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
GUI.log("Cannot prefetch target: " + chrome.i18n.getMessage('serialPortOpenFail'));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
TABS.firmware_flasher.onValidFirmware = function() {
|
||||
MSP.send_message(MSPCodes.MSP_BUILD_INFO, false, false, function () {
|
||||
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, function () {
|
||||
$('select[name="board"] option[value=' + CONFIG.target + ']').attr("selected", "selected");
|
||||
GUI.log("Target prefetch successful: " + CONFIG.target);
|
||||
|
||||
TABS.firmware_flasher.closeTempConnection();
|
||||
$('select[name="board"]').change();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
TABS.firmware_flasher.closeTempConnection = function() {
|
||||
helper.timeout.killAll();
|
||||
helper.interval.killAll(['global_data_refresh', 'msp-load-update']);
|
||||
helper.mspBalancedInterval.flush();
|
||||
|
||||
helper.mspQueue.flush();
|
||||
helper.mspQueue.freeHardLock();
|
||||
helper.mspQueue.freeSoftLock();
|
||||
CONFIGURATOR.connection.emptyOutputBuffer();
|
||||
|
||||
CONFIGURATOR.connectionValid = false;
|
||||
GUI.connected_to = false;
|
||||
|
||||
CONFIGURATOR.connection.disconnect(onClosed);
|
||||
MSP.disconnect_cleanup();
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue