From 09a1252410d575bdbd7446dad645b8236ec8f421 Mon Sep 17 00:00:00 2001 From: cTn Date: Wed, 26 Feb 2014 08:10:08 +0100 Subject: [PATCH] mostly working flash on connect sequence --- js/gui.js | 6 ++++ tabs/firmware_flasher.js | 59 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/js/gui.js b/js/gui.js index f5898843..b956ba95 100644 --- a/js/gui.js +++ b/js/gui.js @@ -259,6 +259,12 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) { }, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one }); break; + + case 'firmware_flasher': + PortHandler.flush_callbacks(); + + if (callback) callback(); + break; default: if (callback) callback(); diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index d19c53e4..40fb6ff7 100644 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -127,9 +127,64 @@ function tab_initialize_firmware_flasher() { }); }); + chrome.storage.local.get('flash_on_connet', function(result) { + if (typeof result.flash_on_connet === 'undefined') { + // wasn't saved yet, save and push false to the GUI + chrome.storage.local.set({'flash_on_connet': false}); + + $('input.flash_on_connet').prop('checked', false); + } else { + // TODO + } + }); + + $('input.flash_on_connet').change(function() { + var status = $(this).is(':checked'); + + if (status) { + var flashing_port; + + var start = function() { + PortHandler.port_detected('flash_next_device', function(result) { + // Fire flash callback over here + flashing_port = result[0]; + + // Trigger regular Flashing sequence + $('a.flash_firmware').click(); + + // Detect port removal to create a new callback + end(); + }, false, true); + }; + + var end = function() { + PortHandler.port_removed('flashed_device_removed', function(result) { + for (var i = 0; i < result.length; i++) { + if (result[i] == flashing_port) { + console.log('out'); + // flashed device removed + start(); + + return; + } + } + + // different device removed, we need to retry + end(); + }, false, true); + }; + + start(); + } else { + PortHandler.flush_callbacks(); + } + }); + $('a.back').click(function() { - if (!GUI.connect_lock) { // button disabled while flashing is in progress - tab_initialize_default(); + if (!GUI.connect_lock) { // button disabled while flashing is in progress + GUI.tab_switch_cleanup(function() { + tab_initialize_default(); + }); } else { GUI.log('You can\'t do this right now, please wait for current operation to finish ...'); }