simplify some interval cleaning code

pull/3/head
cTn 10 years ago
parent c6700a8588
commit aca493301a

@ -191,45 +191,10 @@ GUI_control.prototype.log = function(message) {
// default switch doesn't require callback to be set
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 'initial_setup':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'pid_tuning':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'receiver':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'auxiliary_configuration':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'servos':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'gps':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'motor_outputs':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'sensors':
GUI.interval_kill_all();
serial.empty_output_buffer();
// sensor data tab uses scrollbars, emptying the content before loading another tab
@ -261,11 +226,6 @@ 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 'logging':
GUI.interval_kill_all();
if (callback) callback();
break;
case 'firmware_flasher':
PortHandler.flush_callbacks();
@ -274,6 +234,7 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
if (callback) callback();
break;
default:
if (callback) callback();
}

@ -59,7 +59,7 @@ function tab_initialize_logging(callback) {
// print header for the csv file
print_head();
function poll_data() {
function log_data_poll() {
if (requests) {
// save current data (only after everything is initialized)
crunch_data();
@ -73,8 +73,8 @@ function tab_initialize_logging(callback) {
}
}
GUI.interval_add('log_data_pull', poll_data, parseInt($('select.speed').val()), true); // refresh rate goes here
GUI.interval_add('flush_data', function() {
GUI.interval_add('log_data_poll', log_data_poll, parseInt($('select.speed').val()), true); // refresh rate goes here
GUI.interval_add('write_data', function write_data() {
if (log_buffer.length) { // only execute when there is actual data to write
if (fileWriter.readyState == 0 || fileWriter.readyState == 2) {
append_to_file(log_buffer.join('\n'));
@ -95,8 +95,7 @@ function tab_initialize_logging(callback) {
GUI.log(chrome.i18n.getMessage('loggingErrorOneProperty'));
}
} else {
GUI.interval_remove('log_data_pull');
GUI.interval_remove('flush_data');
GUI.interval_kill_all();
$('.speed').prop('disabled', false);
$(this).text(chrome.i18n.getMessage('loggingStart'));

Loading…
Cancel
Save