Finish up work on unified targets
parent
59d9832efa
commit
000e537283
|
@ -2582,9 +2582,6 @@
|
|||
"firmwareFlasherReleaseDate": {
|
||||
"message": "Date:"
|
||||
},
|
||||
"firmwareFlasherReleaseStatus": {
|
||||
"message": "State:"
|
||||
},
|
||||
"firmwareFlasherReleaseTarget": {
|
||||
"message": "Target:"
|
||||
},
|
||||
|
@ -2616,6 +2613,9 @@
|
|||
"firmwareFlasherLoadFirmwareFile": {
|
||||
"message": "Please load firmware file"
|
||||
},
|
||||
"firmwareFlasherLoadedConfig": {
|
||||
"message": "Loaded target, please load firmware file"
|
||||
},
|
||||
"firmwareFlasherNoReboot": {
|
||||
"message": "No reboot sequence"
|
||||
},
|
||||
|
|
|
@ -4,7 +4,8 @@ TABS.firmware_flasher = {
|
|||
releases: null,
|
||||
releaseChecker: new ReleaseChecker('firmware', 'https://api.github.com/repos/betaflight/betaflight/releases'),
|
||||
jenkinsLoader: new JenkinsLoader('https://ci.betaflight.tech'),
|
||||
localFileLoaded: false,
|
||||
localFirmwareLoaded: false,
|
||||
selectedBoard: undefined,
|
||||
};
|
||||
|
||||
TABS.firmware_flasher.initialize = function (callback) {
|
||||
|
@ -14,19 +15,25 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
GUI.active_tab = 'firmware_flasher';
|
||||
}
|
||||
|
||||
|
||||
TABS.firmware_flasher.selectedBoard = undefined;
|
||||
TABS.firmware_flasher.localFirmwareLoaded = false;
|
||||
var intel_hex = false; // standard intel hex in string format
|
||||
var parsed_hex = false; // parsed raw hex in array format
|
||||
var targetConfig; // the Unified Target configuration to be spliced into the configuration
|
||||
var isConfigLocal = false; // Set to true if the user loads one locally
|
||||
var unifiedConfig; // Unified target configuration loaded from the menu, used when throwing out a local config
|
||||
|
||||
self.peekTargetConfig = function () { // This maybe should get removed before merging.
|
||||
return targetConfig;
|
||||
}
|
||||
var unifiedSource = 'https://api.github.com/repos/betaflight/unified-targets/contents/configs/default';
|
||||
|
||||
|
||||
// These two functions are handy for peeking under the hood. Please don't call them in code.
|
||||
self.peekTargetConfig = function () {
|
||||
return targetConfig;
|
||||
}
|
||||
self.peekHex = function () {
|
||||
return parsed_hex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change boldness of firmware option depending on cache status
|
||||
*
|
||||
|
@ -62,10 +69,9 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
self.enableFlashing(true);
|
||||
|
||||
$('div.release_info .target').text(summary.target);
|
||||
$('div.release_info .target').text(TABS.firmware_flasher.selectedBoard);
|
||||
$('div.release_info .name').text(summary.version).prop('href', summary.releaseUrl);
|
||||
$('div.release_info .date').text(summary.date);
|
||||
$('div.release_info .status').text(summary.status);
|
||||
$('div.release_info .file').text(summary.file).prop('href', summary.url);
|
||||
|
||||
var formattedNotes = summary.notes.replace(/#(\d+)/g, '[#$1](https://github.com/betaflight/betaflight/pull/$1)');
|
||||
|
@ -99,6 +105,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
|
||||
function onLoadSuccess(data, summary) {
|
||||
self.localFirmwareLoaded = false;
|
||||
// The path from getting a firmware doesn't fill in summary.
|
||||
summary = typeof summary === "object"
|
||||
? summary
|
||||
|
@ -146,7 +153,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
ConfigStorage.get('selected_board', function (result) {
|
||||
if (result.selected_board) {
|
||||
var boardBuilds = builds[result.selected_board]
|
||||
var boardBuilds = builds[result.selected_board];
|
||||
$('select[name="board"]').val(boardBuilds ? result.selected_board : 0).trigger('change');
|
||||
}
|
||||
});
|
||||
|
@ -432,10 +439,18 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
|
||||
function grabBuildNameFromConfig(config) {
|
||||
return config.split("\n")[0].split(' ')[3];
|
||||
let bareBoard;
|
||||
try {
|
||||
bareBoard = config.split("\n")[0].split(' ')[3];
|
||||
} catch (e) {
|
||||
bareBoard = undefined;
|
||||
console.log('grabBuildNameFromConfig failed: ', e.message);
|
||||
}
|
||||
return bareBoard;
|
||||
}
|
||||
|
||||
function setUnifiedConfig(target, configText, bareBoard) {
|
||||
// a target might request a firmware with the same name, remove configuration in this case.
|
||||
if (bareBoard == target) {
|
||||
console.log(bareBoard, '==', target);
|
||||
if (!isConfigLocal) {
|
||||
|
@ -450,26 +465,48 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
unifiedConfig = configText;
|
||||
}
|
||||
}
|
||||
function clearBufferedFirmware() {
|
||||
isConfigLocal = false;
|
||||
targetConfig = undefined;
|
||||
unifiedConfig = undefined;
|
||||
intel_hex = false;
|
||||
parsed_hex = false;
|
||||
self.localFirmwareLoaded = false;
|
||||
}
|
||||
|
||||
$('select[name="board"]').change(function() {
|
||||
$("a.load_remote_file").addClass('disabled');
|
||||
var target = $(this).val();
|
||||
ConfigStorage.set({'selected_board': target});
|
||||
console.log('board changed to', target);
|
||||
|
||||
if (!GUI.connect_lock) {
|
||||
if (TABS.firmware_flasher.selectedBoard != target) {
|
||||
// We're sure the board actually changed
|
||||
if (isConfigLocal) {
|
||||
console.log('Board changed, unloading local config');
|
||||
isConfigLocal = false;
|
||||
targetConfig = undefined;
|
||||
}
|
||||
}
|
||||
ConfigStorage.set({'selected_board': target});
|
||||
TABS.firmware_flasher.selectedBoard = target;
|
||||
TABS.firmware_flasher.bareBoard = undefined;
|
||||
console.log('board changed to', target);
|
||||
|
||||
self.flashingMessage('firmwareFlasherLoadFirmwareFile', self.FLASH_MESSAGE_TYPES.NEUTRAL)
|
||||
.flashProgress(0);
|
||||
|
||||
$('div.git_info').slideUp();
|
||||
$('div.release_info').slideUp();
|
||||
|
||||
if (!self.localFileLoaded) {
|
||||
if (!self.localFirmwareLoaded) {
|
||||
self.enableFlashing(false);
|
||||
}
|
||||
|
||||
var versions_e = $('select[name="firmware_version"]');
|
||||
if(target == 0) {
|
||||
// target == 0 is the "Choose a Board" option. Throw out anything loaded
|
||||
clearBufferedFirmware();
|
||||
|
||||
versions_e.empty();
|
||||
versions_e.append($("<option value='0'>{0}</option>".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion'))));
|
||||
} else {
|
||||
|
@ -499,6 +536,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
chrome.storage.local.set(newStorageObj);
|
||||
|
||||
bareBoard = grabBuildNameFromConfig(data);
|
||||
TABS.firmware_flasher.bareBoard = bareBoard;
|
||||
setUnifiedConfig(target, data, bareBoard);
|
||||
populateVersions(versions_e, TABS.firmware_flasher.releases[bareBoard], target);
|
||||
}).fail(xhr => {
|
||||
|
@ -515,6 +553,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
var data = storageObj.data;
|
||||
|
||||
bareBoard = grabBuildNameFromConfig(data);
|
||||
TABS.firmware_flasher.bareBoard = bareBoard;
|
||||
setUnifiedConfig(target, data, bareBoard);
|
||||
populateVersions(versions_e, TABS.firmware_flasher.releases[bareBoard], target);
|
||||
}
|
||||
|
@ -526,6 +565,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
} else {
|
||||
unifiedConfig = undefined;
|
||||
}
|
||||
TABS.firmware_flasher.bareBoard = target;
|
||||
populateVersions(versions_e, TABS.firmware_flasher.releases[target], target);
|
||||
}
|
||||
}
|
||||
|
@ -533,10 +573,24 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
function flashingMessageLocal() {
|
||||
// used by the a.load_file hook, evaluate the loaded information, and enable flashing if suitable
|
||||
if (isConfigLocal && !parsed_hex) {
|
||||
self.flashingMessage(i18n.getMessage('firmwareFlasherLoadedConfig'), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
}
|
||||
if (isConfigLocal && parsed_hex && !self.localFirmwareLoaded) {
|
||||
self.enableFlashing(true);
|
||||
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
}
|
||||
if (self.localFirmwareLoaded) {
|
||||
self.enableFlashing(true);
|
||||
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
}
|
||||
}
|
||||
// UI Hooks
|
||||
$('a.load_file').click(function () {
|
||||
self.enableFlashing(false);
|
||||
self.localFileLoaded = true;
|
||||
//self.localFileLoaded = true;
|
||||
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_CHANNEL, undefined);
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'file');
|
||||
|
@ -580,16 +634,17 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
if (parsed_hex) {
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SIZE, parsed_hex.bytes_total);
|
||||
|
||||
self.enableFlashing(true);
|
||||
|
||||
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
self.localFirmwareLoaded = true;
|
||||
flashingMessageLocal();
|
||||
} else {
|
||||
self.flashingMessage('firmwareFlasherHexCorrupted', self.FLASH_MESSAGE_TYPES.INVALID);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
clearBufferedFirmware();
|
||||
targetConfig = e.target.result;
|
||||
isConfigLocal = true;
|
||||
flashingMessageLocal();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -606,8 +661,15 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
$('select[name="firmware_version"]').change(function(evt){
|
||||
$('div.release_info').slideUp();
|
||||
|
||||
if (!self.localFileLoaded) {
|
||||
if (!self.localFirmwareLoaded) {
|
||||
self.enableFlashing(false);
|
||||
self.flashingMessage(i18n.getMessage('firmwareFlasherLoadFirmwareFile'), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
if(parsed_hex && parsed_hex.bytes_total) {
|
||||
// Changing the board triggers a version change, so we need only dump it here.
|
||||
console.log('throw out loaded hex');
|
||||
intel_hex = false;
|
||||
parsed_hex = false;
|
||||
}
|
||||
}
|
||||
|
||||
let release = $("option:selected", evt.target).data("summary");
|
||||
|
@ -631,7 +693,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
$('a.load_remote_file').click(function (evt) {
|
||||
self.enableFlashing(false);
|
||||
self.localFileLoaded = false;
|
||||
self.localFirmwareLoaded = false;
|
||||
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'http');
|
||||
|
||||
|
@ -649,6 +711,16 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
var summary = $('select[name="firmware_version"] option:selected').data('summary');
|
||||
if (summary) { // undefined while list is loading or while running offline
|
||||
if (isConfigLocal && FirmwareCache.has(summary)) {
|
||||
// Load the .hex from Cache if available when the user is providing their own config.
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_SOURCE, 'cache');
|
||||
FirmwareCache.get(summary, cached => {
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, summary.file);
|
||||
console.info("Release found in cache: " + summary.file);
|
||||
onLoadSuccess(cached.hexdata, summary);
|
||||
});
|
||||
return;
|
||||
}
|
||||
analytics.setFirmwareData(analytics.DATA.FIRMWARE_NAME, summary.file);
|
||||
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonDownloading'));
|
||||
$("a.load_remote_file").addClass('disabled');
|
||||
|
|
|
@ -93,7 +93,6 @@
|
|||
href="#" target="_blank"></a><br /> <strong i18n="firmwareFlasherReleaseFile"></strong> <a
|
||||
i18n_title="firmwareFlasherReleaseFileUrl" class="file" href="#" target="_blank"></a><br /> <strong
|
||||
i18n="firmwareFlasherReleaseDate"></strong> <span class="date"></span><br /> <strong
|
||||
i18n="firmwareFlasherReleaseStatus"></strong> <span class="status"></span><br /> <strong
|
||||
i18n="firmwareFlasherReleaseNotes"></strong>
|
||||
<div class=notes></div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue