add initialization timeout for flash on connect, rework functionality so each new detected port can trigger flashing sequence

10.3.x-maintenance
cTn 2014-10-19 09:38:39 +02:00
parent b6097d6271
commit 3c4307ae57
1 changed files with 16 additions and 31 deletions

View File

@ -253,43 +253,28 @@ TABS.firmware_flasher.initialize = function (callback) {
var status = $(this).is(':checked'); var status = $(this).is(':checked');
if (status) { if (status) {
var flashing_port; var catch_new_port = function () {
PortHandler.port_detected('flash_detected_device', function (result) {
var port = result[0];
var start = function () { if (!GUI.connect_lock) {
PortHandler.port_detected('flash_next_device', function (result) { GUI.log('Detected: <strong>' + port + '</strong> - triggering flash on connect');
flashing_port = result[0]; console.log('Detected: ' + port + ' - triggering flash on connect');
GUI.log('Detected: <strong>' + flashing_port + '</strong> - triggering flash on connect');
console.log('Detected: ' + flashing_port + ' - triggering flash on connect');
// Trigger regular Flashing sequence // Trigger regular Flashing sequence
$('a.flash_firmware').click(); GUI.timeout_add('initialization_timeout', function () {
$('a.flash_firmware').click();
// Detect port removal to create a new callback }, 100); // timeout so bus have time to initialize after being detected by the system
end(); } else {
}, false, true); GUI.log('Detected <strong>' + port + '</strong> - previous device still flashing, please replug to try again');
}
var end = function () {
PortHandler.port_removed('flashed_device_removed', function (result) {
for (var i = 0; i < result.length; i++) {
if (result[i] == flashing_port) {
// flashed device removed
GUI.log('Removed: <strong>' + flashing_port + '</strong> - ready for next device');
console.log('Removed: ' + flashing_port + ' - ready for next device');
flashing_port = false;
start();
return;
}
} }
// different device removed, we need to retry // Since current port_detected request was consumed, create new one
end(); catch_new_port();
}, false, true); }, false, true);
} };
start(); catch_new_port();
} else { } else {
PortHandler.flush_callbacks(); PortHandler.flush_callbacks();
} }