diff --git a/js/gui.js b/js/gui.js index 7dad1f8eb8..27f453c5dd 100644 --- a/js/gui.js +++ b/js/gui.js @@ -196,51 +196,7 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) { MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive GUI.interval_kill_all(); // all intervals (mostly data pulling) needs to be removed on tab switch - switch (this.active_tab) { - case 'sensors': - serial.empty_output_buffer(); - - // sensor data tab uses scrollbars, emptying the content before loading another tab - // prevents scrollbar exposure to any of the tabs while new content is loaded in - $('#content').empty(); - - if (callback) callback(); - break; - case 'cli': - var bufferOut = new ArrayBuffer(5); - var bufView = new Uint8Array(bufferOut); - - bufView[0] = 0x65; // e - bufView[1] = 0x78; // x - bufView[2] = 0x69; // i - bufView[3] = 0x74; // t - bufView[4] = 0x0D; // enter - - serial.send(bufferOut, function(writeInfo) { - // we could handle this "nicely", but this will do for now - // (another approach is however much more complicated): - // we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched - // we could probably implement this someday - GUI.timeout_add('waiting_for_bootup', function() { - CLI_active = false; - CLI_valid = false; - - if (callback) 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(); - - // unbind "global" events - $(document).unbind('keypress'); - - if (callback) callback(); - break; - - default: - if (callback) callback(); - } + this.active_tab_ref.cleanup(callback); }; // initialize object into GUI variable diff --git a/tabs/cli.js b/tabs/cli.js index eb0dba942d..9aa419f429 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -85,7 +85,27 @@ tabs.cli.initialize = function(callback) { }; tabs.cli.cleanup = function(callback) { - if (callback) callback(); + var bufferOut = new ArrayBuffer(5); + var bufView = new Uint8Array(bufferOut); + + bufView[0] = 0x65; // e + bufView[1] = 0x78; // x + bufView[2] = 0x69; // i + bufView[3] = 0x74; // t + bufView[4] = 0x0D; // enter + + serial.send(bufferOut, function(writeInfo) { + // we could handle this "nicely", but this will do for now + // (another approach is however much more complicated): + // we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched + // we could probably implement this someday + GUI.timeout_add('waiting_for_bootup', function() { + CLI_active = false; + CLI_valid = false; + + if (callback) callback(); + }, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one + }); }; function send_slowly(out_arr, i, timeout_needle) { diff --git a/tabs/firmware_flasher.js b/tabs/firmware_flasher.js index 6889de9987..b98621c623 100644 --- a/tabs/firmware_flasher.js +++ b/tabs/firmware_flasher.js @@ -237,6 +237,11 @@ tabs.firmware_flasher.initialize = function(callback) { }; tabs.firmware_flasher.cleanup = function(callback) { + PortHandler.flush_callbacks(); + + // unbind "global" events + $(document).unbind('keypress'); + if (callback) callback(); }; diff --git a/tabs/sensors.js b/tabs/sensors.js index 280e1d9abf..00ff192f91 100644 --- a/tabs/sensors.js +++ b/tabs/sensors.js @@ -414,5 +414,11 @@ tabs.sensors.initialize = function(callback) { }; tabs.sensors.cleanup = function(callback) { + serial.empty_output_buffer(); + + // sensor data tab uses scrollbars, emptying the content before loading another tab + // prevents scrollbar exposure to any of the tabs while new content is loaded in + $('#content').empty(); + if (callback) callback(); };