From 0f23b5f5d9af1ef06e719e5d051da24737064e11 Mon Sep 17 00:00:00 2001 From: cTn Date: Sat, 9 Nov 2013 06:14:21 +0100 Subject: [PATCH] utilizing tab_switch_cleanup functionality --- js/gui.js | 21 +++++++++++++++ js/main.js | 63 ++++++++++++++++++++++---------------------- js/serial_backend.js | 15 +++++++++-- tabs/cli.js | 20 -------------- 4 files changed, 65 insertions(+), 54 deletions(-) diff --git a/js/gui.js b/js/gui.js index 1f83621d..c2b0e44f 100644 --- a/js/gui.js +++ b/js/gui.js @@ -124,6 +124,27 @@ GUI_control.prototype.timeout_kill_all = function() { GUI_control.prototype.tab_switch_cleanup = function(callback) { switch (this.active_tab) { 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 + + chrome.serial.write(connectionId, bufferOut, function(writeInfo) { + if (callback) { + // 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; + callback(); + }, 3000); + } + }); break; default: if (callback) { diff --git a/js/main.js b/js/main.js index 82da4d1c..0bb98173 100644 --- a/js/main.js +++ b/js/main.js @@ -44,41 +44,40 @@ $(document).ready(function() { return; } + var self = this; + // Disable any active "data pulling" timer disable_timers(); - // Disable CLI (there is no "nicer way of doing so right now) - if (CLI_active == true) { - leave_CLI(); - } - - // Disable previous active button - $('li', tabs).removeClass('active'); - - // Highlight selected button - $(this).parent().addClass('active'); - - if ($(this).parent().hasClass('tab_initial_setup')) { - $('#content').load("./tabs/initial_setup.html", tab_initialize_initial_setup); - } else if ($(this).parent().hasClass('tab_pid_tuning')) { - $('#content').load("./tabs/pid_tuning.html", tab_initialize_pid_tuning); - } else if ($(this).parent().hasClass('tab_receiver')) { - $('#content').load("./tabs/receiver.html", tab_initialize_receiver); - } else if ($(this).parent().hasClass('tab_auxiliary_configuration')) { - $('#content').load("./tabs/auxiliary_configuration.html", tab_initialize_auxiliary_configuration); - } else if ($(this).parent().hasClass('tab_servos')) { - $('#content').load("./tabs/servos.html", tab_initialize_servos); - } else if ($(this).parent().hasClass('tab_gps')) { - $('#content').load("./tabs/gps.html", tab_initialize_gps); - } else if ($(this).parent().hasClass('tab_motor_outputs')) { - $('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs); - } else if ($(this).parent().hasClass('tab_sensors')) { - $('#content').load("./tabs/sensors.html", tab_initialize_sensors); - } else if ($(this).parent().hasClass('tab_cli')) { - $('#content').load("./tabs/cli.html", tab_initialize_cli); - } else if ($(this).parent().hasClass('tab_about')) { - $('#content').load("./tabs/about.html", tab_initialize_about); - } + GUI.tab_switch_cleanup(function() { + // Disable previous active button + $('li', tabs).removeClass('active'); + + // Highlight selected button + $(self).parent().addClass('active'); + + if ($(self).parent().hasClass('tab_initial_setup')) { + $('#content').load("./tabs/initial_setup.html", tab_initialize_initial_setup); + } else if ($(self).parent().hasClass('tab_pid_tuning')) { + $('#content').load("./tabs/pid_tuning.html", tab_initialize_pid_tuning); + } else if ($(self).parent().hasClass('tab_receiver')) { + $('#content').load("./tabs/receiver.html", tab_initialize_receiver); + } else if ($(self).parent().hasClass('tab_auxiliary_configuration')) { + $('#content').load("./tabs/auxiliary_configuration.html", tab_initialize_auxiliary_configuration); + } else if ($(self).parent().hasClass('tab_servos')) { + $('#content').load("./tabs/servos.html", tab_initialize_servos); + } else if ($(self).parent().hasClass('tab_gps')) { + $('#content').load("./tabs/gps.html", tab_initialize_gps); + } else if ($(self).parent().hasClass('tab_motor_outputs')) { + $('#content').load("./tabs/motor_outputs.html", tab_initialize_motor_outputs); + } else if ($(self).parent().hasClass('tab_sensors')) { + $('#content').load("./tabs/sensors.html", tab_initialize_sensors); + } else if ($(self).parent().hasClass('tab_cli')) { + $('#content').load("./tabs/cli.html", tab_initialize_cli); + } else if ($(self).parent().hasClass('tab_about')) { + $('#content').load("./tabs/about.html", tab_initialize_about); + } + }); } }); diff --git a/js/serial_backend.js b/js/serial_backend.js index 519d079f..960af736 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -144,13 +144,24 @@ $(document).ready(function() { // Disable CLI (there is no "nicer way of doing so right now) if (CLI_active == true) { - leave_CLI(function() { + 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 + + chrome.serial.write(connectionId, bufferOut, function(writeInfo) { chrome.serial.close(connectionId, onClosed); clearTimeout(connection_delay); clearInterval(serial_poll); clearInterval(port_usage_poll); - }); + }); + + CLI_active = false; } else { chrome.serial.close(connectionId, onClosed); diff --git a/tabs/cli.js b/tabs/cli.js index 95c78884..f7919b2f 100644 --- a/tabs/cli.js +++ b/tabs/cli.js @@ -98,26 +98,6 @@ function send_slowly(out_arr, i, timeout_needle) { }, timeout_needle * 5); } -function leave_CLI(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 - - chrome.serial.write(connectionId, bufferOut, function(writeInfo) { - if (callback) { - callback(); - } - }); - - CLI_active = false; -} - - /* Some info about handling line feeds and carriage return line feed = LF = \n = 0x0A = 10