mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-15 12:25:15 +03:00
initial implementation of firmware cache
This commit is contained in:
parent
c5ae5d07a6
commit
bd1dbf21d0
5 changed files with 249 additions and 41 deletions
|
@ -17,6 +17,8 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
parsed_hex = false; // parsed raw hex in array format
|
||||
|
||||
$('#content').load("./tabs/firmware_flasher.html", function () {
|
||||
FirmwareCache.load();
|
||||
|
||||
function parse_hex(str, callback) {
|
||||
// parsing hex in different thread
|
||||
var worker = new Worker('./js/workers/hex_parser.js');
|
||||
|
@ -30,6 +32,54 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
worker.postMessage(str);
|
||||
}
|
||||
|
||||
function process_hex(data, summary) {
|
||||
intel_hex = data;
|
||||
|
||||
parse_hex(intel_hex, function (data) {
|
||||
parsed_hex = data;
|
||||
|
||||
if (parsed_hex) {
|
||||
if (!FirmwareCache.has(summary)) {
|
||||
FirmwareCache.put(summary, intel_hex);
|
||||
console.info("Release put to cache: " + summary.file);
|
||||
}
|
||||
|
||||
var url;
|
||||
|
||||
$('span.progressLabel').html('<a class="save_firmware" href="#" title="Save Firmware">Loaded Online Firmware: (' + parsed_hex.bytes_total + ' bytes)</a>');
|
||||
|
||||
$('a.flash_firmware').removeClass('disabled');
|
||||
|
||||
$('div.release_info .target').text(summary.target);
|
||||
$('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)');
|
||||
formattedNotes = marked(formattedNotes);
|
||||
$('div.release_info .notes').html(formattedNotes);
|
||||
$('div.release_info .notes').find('a').each(function() {
|
||||
$(this).attr('target', '_blank');
|
||||
});
|
||||
|
||||
$('div.release_info').slideDown();
|
||||
|
||||
} else {
|
||||
$('span.progressLabel').text(i18n.getMessage('firmwareFlasherHexCorrupted'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onLoadSuccess(data, summary) {
|
||||
summary = typeof summary === "object"
|
||||
? summary
|
||||
: $('select[name="firmware_version"] option:selected').data('summary');
|
||||
process_hex(data, summary);
|
||||
$("a.load_remote_file").removeClass('disabled');
|
||||
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline'));
|
||||
};
|
||||
|
||||
function buildBoardOptions(releaseData) {
|
||||
if (!releaseData) {
|
||||
$('select[name="board"]').empty().append('<option value="0">Offline</option>');
|
||||
|
@ -226,7 +276,15 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
$('select[name="firmware_version"]').change(function(evt){
|
||||
$('div.release_info').slideUp();
|
||||
$('a.flash_firmware').addClass('disabled');
|
||||
if (evt.target.value=="0") {
|
||||
let release = $("option:selected", evt.target).data("summary");
|
||||
let isCached = FirmwareCache.has(release);
|
||||
if (evt.target.value=="0" || isCached) {
|
||||
if (isCached) {
|
||||
FirmwareCache.get(release, cached => {
|
||||
console.info("Release found in cache: " + release.file);
|
||||
onLoadSuccess(cached.hexdata, release);
|
||||
});
|
||||
}
|
||||
$("a.load_remote_file").addClass('disabled');
|
||||
}
|
||||
else {
|
||||
|
@ -241,40 +299,6 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
return;
|
||||
}
|
||||
|
||||
function process_hex(data, summary) {
|
||||
intel_hex = data;
|
||||
|
||||
parse_hex(intel_hex, function (data) {
|
||||
parsed_hex = data;
|
||||
|
||||
if (parsed_hex) {
|
||||
var url;
|
||||
|
||||
$('span.progressLabel').html('<a class="save_firmware" href="#" title="Save Firmware">Loaded Online Firmware: (' + parsed_hex.bytes_total + ' bytes)</a>');
|
||||
|
||||
$('a.flash_firmware').removeClass('disabled');
|
||||
|
||||
$('div.release_info .target').text(summary.target);
|
||||
$('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)');
|
||||
formattedNotes = marked(formattedNotes);
|
||||
$('div.release_info .notes').html(formattedNotes);
|
||||
$('div.release_info .notes').find('a').each(function() {
|
||||
$(this).attr('target', '_blank');
|
||||
});
|
||||
|
||||
$('div.release_info').slideDown();
|
||||
|
||||
} else {
|
||||
$('span.progressLabel').text(i18n.getMessage('firmwareFlasherHexCorrupted'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function failed_to_load() {
|
||||
$('span.progressLabel').text(i18n.getMessage('firmwareFlasherFailedToLoadOnlineFirmware'));
|
||||
$('a.flash_firmware').addClass('disabled');
|
||||
|
@ -286,11 +310,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
if (summary) { // undefined while list is loading or while running offline
|
||||
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonDownloading'));
|
||||
$("a.load_remote_file").addClass('disabled');
|
||||
$.get(summary.url, function (data) {
|
||||
process_hex(data, summary);
|
||||
$("a.load_remote_file").removeClass('disabled');
|
||||
$("a.load_remote_file").text(i18n.getMessage('firmwareFlasherButtonLoadOnline'));
|
||||
}).fail(failed_to_load);
|
||||
$.get(summary.url, onLoadSuccess).fail(failed_to_load);
|
||||
} else {
|
||||
$('span.progressLabel').text(i18n.getMessage('firmwareFlasherFailedToLoadOnlineFirmware'));
|
||||
}
|
||||
|
@ -507,6 +527,7 @@ TABS.firmware_flasher.initialize = function (callback) {
|
|||
|
||||
TABS.firmware_flasher.cleanup = function (callback) {
|
||||
PortHandler.flush_callbacks();
|
||||
FirmwareCache.flush();
|
||||
|
||||
// unbind "global" events
|
||||
$(document).unbind('keypress');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue