2013-11-13 07:55:29 +00:00
|
|
|
function tab_initialize_firmware_flasher() {
|
|
|
|
ga_tracker.sendAppView('Firmware Flasher');
|
|
|
|
GUI.active_tab = 'firmware_flasher';
|
|
|
|
|
2013-11-13 08:13:24 +00:00
|
|
|
var intel_hex = false; // standard intel hex in string format
|
|
|
|
var raw_hex = false; // parsed raw hex in array format
|
2013-11-13 08:09:02 +00:00
|
|
|
|
2013-11-13 07:55:29 +00:00
|
|
|
$('#content').load("./tabs/firmware_flasher.html", function() {
|
2013-11-13 08:09:02 +00:00
|
|
|
// UI Hooks
|
|
|
|
$('a.load_file').click(function() {
|
|
|
|
chrome.fileSystem.chooseEntry({type: 'openFile', accepts: [{extensions: ['hex']}]}, function(fileEntry) {
|
|
|
|
if (!fileEntry) {
|
|
|
|
// no "valid" file selected/created, aborting
|
|
|
|
console.log('No valid file selected, aborting');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
|
|
|
|
console.log('Loading file from: ' + path);
|
2013-11-13 08:32:33 +00:00
|
|
|
$('span.path').html(path);
|
2013-11-13 08:09:02 +00:00
|
|
|
|
|
|
|
fileEntry.file(function(file) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
|
|
|
reader.onerror = function (e) {
|
|
|
|
console.error(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.onloadend = function(e) {
|
|
|
|
console.log('File loaded');
|
2013-11-13 09:56:14 +00:00
|
|
|
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
|
2013-11-13 08:09:02 +00:00
|
|
|
|
|
|
|
intel_hex = e.target.result;
|
2013-11-13 08:13:24 +00:00
|
|
|
raw_hex = read_hex_file(intel_hex);
|
2013-11-13 08:32:33 +00:00
|
|
|
|
|
|
|
$('span.size').html((raw_hex.length / 1000) + ' kB');
|
2013-11-13 08:09:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsText(file);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-13 08:32:33 +00:00
|
|
|
|
2013-11-13 12:24:05 +00:00
|
|
|
$('a.load_remote_file').click(function() {
|
2013-11-13 12:53:44 +00:00
|
|
|
/* for future use
|
|
|
|
$.get('https://api.github.com/repos/multiwii/baseflight/tags', function(data) {
|
|
|
|
console.log(data)
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
2013-11-13 12:24:05 +00:00
|
|
|
$.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
|
|
|
|
intel_hex = data;
|
|
|
|
raw_hex = read_hex_file(intel_hex);
|
|
|
|
|
|
|
|
$('span.path').html('Using remote Firmware');
|
|
|
|
$('span.size').html((raw_hex.length / 1000) + ' kB');
|
|
|
|
|
|
|
|
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
|
|
|
|
}).fail(function() {
|
|
|
|
STM32.GUI_status('<span style="color: red">Failed to load remote firmware</span>');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-11-13 08:32:33 +00:00
|
|
|
$('a.flash_firmware').click(function() {
|
2013-11-14 06:39:39 +00:00
|
|
|
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
|
|
|
if (raw_hex != false) {
|
|
|
|
STM32.hex_to_flash = raw_hex.slice(0);
|
|
|
|
|
|
|
|
STM32.connect();
|
|
|
|
} else {
|
|
|
|
STM32.GUI_status('<span style="color: red">Firmware not loaded</span>');
|
|
|
|
}
|
2013-11-13 08:32:33 +00:00
|
|
|
}
|
|
|
|
});
|
2013-11-14 06:49:02 +00:00
|
|
|
|
|
|
|
$('a.back').click(function() {
|
|
|
|
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
|
|
|
tab_initialize_default();
|
|
|
|
} else {
|
|
|
|
notify('You <span style="color: red">can\'t</span> do this right now, please wait for current operation to finish ...');
|
|
|
|
}
|
|
|
|
});
|
2013-11-13 07:55:29 +00:00
|
|
|
});
|
|
|
|
}
|