2013-11-13 07:55:29 +00:00
|
|
|
function tab_initialize_firmware_flasher() {
|
|
|
|
ga_tracker.sendAppView('Firmware Flasher');
|
|
|
|
GUI.active_tab = 'firmware_flasher';
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 08:13:24 +00:00
|
|
|
var intel_hex = false; // standard intel hex in string format
|
2013-11-15 15:17:43 +00:00
|
|
|
var parsed_hex = false; // parsed raw hex in array format
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 07:55:29 +00:00
|
|
|
$('#content').load("./tabs/firmware_flasher.html", function() {
|
2014-05-06 14:48:46 +00:00
|
|
|
// translate to user-selected language
|
|
|
|
localize();
|
|
|
|
|
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;
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-27 17:56:12 +00:00
|
|
|
// hide github info (if it exists)
|
|
|
|
$('div.git_info').slideUp();
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 08:09:02 +00:00
|
|
|
chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
|
|
|
|
console.log('Loading file from: ' + path);
|
2013-11-13 08:32:33 +00:00
|
|
|
$('span.path').html(path);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 08:09:02 +00:00
|
|
|
fileEntry.file(function(file) {
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
2014-01-10 23:08:24 +00:00
|
|
|
reader.onprogress = function(e) {
|
|
|
|
if (e.total > 1048576) { // 1 MB
|
|
|
|
// dont allow reading files bigger then 1 MB
|
|
|
|
console.log('File limit (1 MB) exceeded, aborting');
|
|
|
|
reader.abort();
|
|
|
|
}
|
2013-11-13 08:09:02 +00:00
|
|
|
};
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 08:09:02 +00:00
|
|
|
reader.onloadend = function(e) {
|
2014-01-10 23:08:24 +00:00
|
|
|
if (e.total != 0 && e.total == e.loaded) {
|
|
|
|
console.log('File loaded');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-10 23:08:24 +00:00
|
|
|
intel_hex = e.target.result;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-10 23:08:24 +00:00
|
|
|
parse_hex(intel_hex, function(data) {
|
|
|
|
parsed_hex = data;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-10 23:08:24 +00:00
|
|
|
if (parsed_hex) {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherFirmwareLoaded'));
|
2014-01-10 23:08:24 +00:00
|
|
|
$('a.flash_firmware').removeClass('locked');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-09 14:36:22 +00:00
|
|
|
$('span.size').html(parsed_hex.bytes_total + ' bytes');
|
2014-01-10 23:08:24 +00:00
|
|
|
} else {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherHexCorrupted'));
|
2014-01-10 23:08:24 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-11-13 08:09:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsText(file);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
|
|
|
$('a.load_remote_file').click(function() {
|
2014-04-25 22:08:18 +00:00
|
|
|
$.get('https://raw.githubusercontent.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
|
2013-11-13 12:24:05 +00:00
|
|
|
intel_hex = data;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-16 09:01:29 +00:00
|
|
|
parse_hex(intel_hex, function(data) {
|
|
|
|
parsed_hex = data;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-16 09:01:29 +00:00
|
|
|
if (parsed_hex) {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherRemoteFirmwareLoaded'));
|
2013-11-16 09:01:29 +00:00
|
|
|
$('a.flash_firmware').removeClass('locked');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 10:01:07 +00:00
|
|
|
$('span.path').text('Using remote Firmware');
|
|
|
|
$('span.size').text(parsed_hex.bytes_total + ' bytes');
|
2013-11-16 09:01:29 +00:00
|
|
|
} else {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherHexCorrupted'));
|
2013-11-16 09:01:29 +00:00
|
|
|
}
|
|
|
|
});
|
2013-11-13 12:24:05 +00:00
|
|
|
}).fail(function() {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherFailedToLoadOnlineFirmware'));
|
2013-11-14 18:02:32 +00:00
|
|
|
$('a.flash_firmware').addClass('locked');
|
2013-11-13 12:24:05 +00:00
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-27 17:56:12 +00:00
|
|
|
$.get('https://api.github.com/repos/multiwii/baseflight/commits?page=1&per_page=1&path=obj/baseflight.hex', function(data) {
|
|
|
|
var data = data[0];
|
|
|
|
var d = new Date(data.commit.author.date);
|
|
|
|
var date = ('0' + (d.getMonth() + 1)).slice(-2) + '.' + ('0' + (d.getDate() + 1)).slice(-2) + '.' + d.getFullYear();
|
|
|
|
date += ' @ ' + ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 10:01:07 +00:00
|
|
|
$('div.git_info .committer').text(data.commit.author.name);
|
|
|
|
$('div.git_info .date').text(date);
|
|
|
|
$('div.git_info .message').text(data.commit.message);
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-27 17:56:12 +00:00
|
|
|
$('div.git_info').slideDown();
|
|
|
|
});
|
2013-11-13 12:24:05 +00:00
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-13 08:32:33 +00:00
|
|
|
$('a.flash_firmware').click(function() {
|
2013-11-14 18:02:32 +00:00
|
|
|
if (!$(this).hasClass('locked')) {
|
|
|
|
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
2014-03-08 05:25:15 +00:00
|
|
|
if (parsed_hex != false) {
|
2013-12-10 07:19:18 +00:00
|
|
|
STM32.connect(parsed_hex);
|
2013-11-14 18:02:32 +00:00
|
|
|
} else {
|
2014-05-08 10:01:07 +00:00
|
|
|
STM32.GUI_status(chrome.i18n.getMessage('firmwareFlasherFirmwareNotLoaded'));
|
2013-11-14 18:02:32 +00:00
|
|
|
}
|
2013-11-14 06:39:39 +00:00
|
|
|
}
|
2013-11-13 08:32:33 +00:00
|
|
|
}
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-25 14:40:18 +00:00
|
|
|
chrome.storage.local.get('no_reboot_sequence', function(result) {
|
2014-05-08 12:56:25 +00:00
|
|
|
if (result.no_reboot_sequence) {
|
|
|
|
$('input.updating').prop('checked', true);
|
|
|
|
$('label.flash_on_connect_wrapper').show();
|
2014-02-25 14:40:18 +00:00
|
|
|
} else {
|
2014-05-08 12:56:25 +00:00
|
|
|
$('input.updating').prop('checked', false);
|
2014-02-25 14:40:18 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-25 14:40:18 +00:00
|
|
|
// bind UI hook so the status is saved on change
|
2014-02-26 06:09:53 +00:00
|
|
|
$('input.updating').change(function() {
|
|
|
|
var status = $(this).is(':checked');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 06:09:53 +00:00
|
|
|
if (status) {
|
|
|
|
$('label.flash_on_connect_wrapper').show();
|
|
|
|
} else {
|
2014-02-26 07:32:57 +00:00
|
|
|
$('input.flash_on_connect').prop('checked', false).change();
|
2014-05-08 12:56:25 +00:00
|
|
|
$('label.flash_on_connect_wrapper').hide();
|
2014-02-26 06:09:53 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-07 02:08:52 +00:00
|
|
|
chrome.storage.local.set({'no_reboot_sequence': status});
|
2014-02-25 14:40:18 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
chrome.storage.local.get('flash_on_connect', function(result) {
|
2014-05-08 12:56:25 +00:00
|
|
|
if (result.flash_on_connect) {
|
|
|
|
$('input.flash_on_connect').prop('checked', true);
|
2014-02-26 07:10:08 +00:00
|
|
|
} else {
|
2014-05-08 12:56:25 +00:00
|
|
|
$('input.flash_on_connect').prop('checked', false);
|
2014-02-26 07:10:08 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
$('input.flash_on_connect').change(function() {
|
|
|
|
var status = $(this).is(':checked');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
if (status) {
|
|
|
|
var flashing_port;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 12:56:25 +00:00
|
|
|
function start() {
|
2014-02-26 07:20:30 +00:00
|
|
|
PortHandler.port_detected('flash_next_device', function(result) {
|
|
|
|
flashing_port = result[0];
|
2014-02-26 07:32:57 +00:00
|
|
|
GUI.log('Detected: <strong>' + flashing_port + '</strong> - triggering flash on connect');
|
|
|
|
console.log('Detected: ' + flashing_port + ' - triggering flash on connect');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
// Trigger regular Flashing sequence
|
|
|
|
$('a.flash_firmware').click();
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
// Detect port removal to create a new callback
|
|
|
|
end();
|
|
|
|
}, false, true);
|
2014-05-08 12:56:25 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-08 12:56:25 +00:00
|
|
|
function end() {
|
2014-02-26 07:20:30 +00:00
|
|
|
PortHandler.port_removed('flashed_device_removed', function(result) {
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
if (result[i] == flashing_port) {
|
|
|
|
// flashed device removed
|
2014-02-26 07:32:57 +00:00
|
|
|
GUI.log('Removed: <strong>' + flashing_port + '</strong> - ready for next device');
|
|
|
|
console.log('Removed: ' + flashing_port + ' - ready for next device');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:32:57 +00:00
|
|
|
flashing_port = false;
|
2014-02-26 07:20:30 +00:00
|
|
|
start();
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-26 07:10:08 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
// different device removed, we need to retry
|
|
|
|
end();
|
|
|
|
}, false, true);
|
2014-05-08 12:56:25 +00:00
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-02-26 07:20:30 +00:00
|
|
|
start();
|
|
|
|
} else {
|
|
|
|
PortHandler.flush_callbacks();
|
|
|
|
}
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-07 02:08:52 +00:00
|
|
|
chrome.storage.local.set({'flash_on_connect': status});
|
2014-02-26 07:20:30 +00:00
|
|
|
}).change();
|
2014-02-26 07:10:08 +00:00
|
|
|
});
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-07 06:07:49 +00:00
|
|
|
chrome.storage.local.get('erase_chip', function(result) {
|
2014-05-08 12:56:25 +00:00
|
|
|
if (result.erase_chip) {
|
|
|
|
$('input.erase_chip').prop('checked', true);
|
2014-05-07 06:07:49 +00:00
|
|
|
} else {
|
2014-05-08 12:56:25 +00:00
|
|
|
$('input.erase_chip').prop('checked', false);
|
2014-05-07 06:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// bind UI hook so the status is saved on change
|
|
|
|
$('input.erase_chip').change(function() {
|
|
|
|
var status = $(this).is(':checked');
|
|
|
|
|
|
|
|
chrome.storage.local.set({'erase_chip': status});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-11 19:21:48 +00:00
|
|
|
/*
|
|
|
|
chrome.storage.local.get('dev_mode', function(result) {
|
|
|
|
if (typeof result.dev_mode !== 'undefined') {
|
|
|
|
if (result.dev_mode) {
|
|
|
|
GUI.log('Dev mode: <strong>Enabled</strong>');
|
|
|
|
bind_enter_handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var keys_down = {};
|
|
|
|
$(document).keydown(function(e) {
|
|
|
|
keys_down[e.which] = true;
|
|
|
|
|
|
|
|
// idkfa
|
|
|
|
if (keys_down[65] && keys_down[68] && keys_down[70] && keys_down[73] && keys_down[75]) {
|
|
|
|
chrome.storage.local.get('dev_mode', function(result) {
|
|
|
|
if (typeof result.dev_mode === 'undefined') {
|
|
|
|
GUI.log('Dev mode: <strong>Enabled</strong>');
|
|
|
|
bind_enter_handler();
|
|
|
|
|
|
|
|
chrome.storage.local.set({'dev_mode': true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).keyup(function(e) {
|
|
|
|
delete keys_down[e.which];
|
|
|
|
});
|
|
|
|
|
|
|
|
function bind_enter_handler() {
|
|
|
|
// unbind first (in case there is anything bound here)
|
|
|
|
$(document).unbind('keypress');
|
|
|
|
|
|
|
|
$(document).keypress(function(e) {
|
|
|
|
if (e.which == 13) { // enter
|
|
|
|
// Trigger regular Flashing sequence
|
|
|
|
$('a.flash_firmware').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2014-05-02 23:03:24 +00:00
|
|
|
/*
|
|
|
|
GUI.interval_add('factory_mode', function factory_mode() {
|
|
|
|
serial.getControlSignals(function(result) {
|
|
|
|
if (result.cts == true) {
|
|
|
|
// Trigger regular Flashing sequence
|
|
|
|
$('a.flash_firmware').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 500);
|
|
|
|
*/
|
|
|
|
|
2014-04-11 19:21:48 +00:00
|
|
|
$(document).keypress(function(e) {
|
|
|
|
if (e.which == 13) { // enter
|
|
|
|
// Trigger regular Flashing sequence
|
|
|
|
$('a.flash_firmware').click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// back button
|
2013-11-14 06:49:02 +00:00
|
|
|
$('a.back').click(function() {
|
2014-02-26 07:10:08 +00:00
|
|
|
if (!GUI.connect_lock) { // button disabled while flashing is in progress
|
|
|
|
GUI.tab_switch_cleanup(function() {
|
|
|
|
tab_initialize_default();
|
|
|
|
});
|
2013-11-14 06:49:02 +00:00
|
|
|
} else {
|
2014-05-08 10:01:07 +00:00
|
|
|
GUI.log(chrome.i18n.getMessage('firmwareFlasherWaitForFinish'));
|
2013-11-14 06:49:02 +00:00
|
|
|
}
|
|
|
|
});
|
2013-11-13 07:55:29 +00:00
|
|
|
});
|
2013-11-16 09:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function parse_hex(str, callback) {
|
|
|
|
// parsing hex in different thread
|
2014-02-07 20:48:04 +00:00
|
|
|
var worker = new Worker('./js/workers/hex_parser.js');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-16 09:01:29 +00:00
|
|
|
// "callback"
|
|
|
|
worker.onmessage = function (event) {
|
|
|
|
callback(event.data);
|
|
|
|
};
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2013-11-16 09:01:29 +00:00
|
|
|
// send data/string over for processing
|
|
|
|
worker.postMessage(str);
|
2013-11-13 07:55:29 +00:00
|
|
|
}
|