1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-21 15:25:36 +03:00

moving to GUI integrated interval/timeout model

This commit is contained in:
cTn 2013-12-11 18:57:29 +01:00
parent 5e636b2920
commit e7a02d0e21
10 changed files with 192 additions and 190 deletions

View file

@ -10,7 +10,7 @@ function configuration_backup() {
// applying 200ms delay (should be enough to pull all the data down) // applying 200ms delay (should be enough to pull all the data down)
// we might increase this in case someone would be using very slow baudrate (ergo 9600 and lower) // we might increase this in case someone would be using very slow baudrate (ergo 9600 and lower)
setTimeout(function() { GUI.timeout_add('backup_timeout', function() {
var chosenFileEntry = null; var chosenFileEntry = null;
var accepts = [{ var accepts = [{

View file

@ -170,11 +170,39 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
case 'initial_setup': case 'initial_setup':
GUI.interval_remove('initial_setup_data_pull'); GUI.interval_remove('initial_setup_data_pull');
if (callback) callback();
break;
case 'pid_tuning':
GUI.interval_remove('pid_data_poll');
if (callback) callback();
break;
case 'receiver':
GUI.interval_remove('receiver_poll');
if (callback) callback(); if (callback) callback();
break; break;
case 'auxiliary_configuration': case 'auxiliary_configuration':
GUI.interval_remove('aux_data_poll'); GUI.interval_remove('aux_data_poll');
if (callback) callback();
break;
case 'servos':
if (callback) callback();
break;
case 'gps':
GUI.interval_remove('gps_pull');
if (callback) callback();
break;
case 'motor_outputs':
GUI.interval_remove('motor_poll');
if (callback) callback();
break;
case 'sensors':
GUI.interval_kill_all(['port-update', 'port_usage', 'serial_read']);
if (callback) callback(); if (callback) callback();
break; break;
case 'cli': case 'cli':

View file

@ -116,26 +116,22 @@ $(document).ready(function() {
chrome.serial.open(selected_port, {bitrate: selected_baud}, onOpen); chrome.serial.open(selected_port, {bitrate: selected_baud}, onOpen);
} else { } else {
// Disable any active "data pulling" timer // Disable any active "data pulling" timer
disable_timers(); GUI.interval_kill_all(['port-update']);
GUI.tab_switch_cleanup(); GUI.tab_switch_cleanup();
GUI.timeout_remove('connecting'); // kill connecting timer GUI.timeout_remove('connecting');
GUI.timeout_remove('connection_delay');
chrome.serial.close(connectionId, onClosed); chrome.serial.close(connectionId, onClosed);
GUI.connected_to = false; GUI.connected_to = false;
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
// Change port utilization to 0 // Change port utilization to 0
$('span.port-usage').html('0%'); $('span.port-usage').html('0%');
MSP.packet_error = 0; // reset CRC packet error counter for next session
configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly) configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly)
MSP.packet_error = 0; // reset CRC packet error counter for next session
// unlock port select & baud // unlock port select & baud
$('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', false); $('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', false);
@ -180,10 +176,10 @@ function onOpen(openInfo) {
} }
}); });
connection_delay = setTimeout(function() { GUI.timeout_add('connection_delay', function() {
// start polling // start polling
serial_poll = setInterval(readPoll, 10); GUI.interval_add('serial_read', readPoll, 10);
port_usage_poll = setInterval(port_usage, 1000); GUI.interval_add('port_usage', port_usage, 1000);
// disconnect after 10 seconds with error if we don't get IDENT data // disconnect after 10 seconds with error if we don't get IDENT data
GUI.timeout_add('connecting', function() { GUI.timeout_add('connecting', function() {

16
main.js
View file

@ -7,19 +7,6 @@ chrome.runtime.getBackgroundPage(function(result) {
backgroundPage.app_window = window; backgroundPage.app_window = window;
}); });
var timers = new Array();
function disable_timers() {
for (var i = 0; i < timers.length; i++) {
clearInterval(timers[i]);
}
// kill all the refferences
timers = [];
return true;
}
// Google Analytics stuff begin // Google Analytics stuff begin
var service = analytics.getService('ice_cream_app'); var service = analytics.getService('ice_cream_app');
var ga_tracker = service.getTracker('UA-32728876-6'); var ga_tracker = service.getTracker('UA-32728876-6');
@ -38,9 +25,6 @@ $(document).ready(function() {
var self = this; var self = this;
// Disable any active "data pulling" timer
disable_timers();
GUI.tab_switch_cleanup(function() { GUI.tab_switch_cleanup(function() {
// disable previously active tab highlight // disable previously active tab highlight
$('li', tabs).removeClass('active'); $('li', tabs).removeClass('active');

View file

@ -84,7 +84,7 @@ function tab_initialize_cli() {
} }
function send_slowly(out_arr, i, timeout_needle) { function send_slowly(out_arr, i, timeout_needle) {
setTimeout(function() { GUI.timeout_add('CLI_send_slowly', function() {
var bufferOut = new ArrayBuffer(out_arr[i].length + 1); var bufferOut = new ArrayBuffer(out_arr[i].length + 1);
var bufView = new Uint8Array(bufferOut); var bufView = new Uint8Array(bufferOut);

View file

@ -3,10 +3,7 @@ function tab_initialize_gps () {
GUI.active_tab = 'gps'; GUI.active_tab = 'gps';
// enable data pulling // enable data pulling
timers.push(setInterval(gps_pull, 75)); GUI.interval_add('gps_pull', function() {
}
function gps_pull() {
// Update GPS data // Update GPS data
$('.GPS_info td.alt').html(GPS_DATA.alt + ' m'); $('.GPS_info td.alt').html(GPS_DATA.alt + ' m');
$('.GPS_info td.lat').html((GPS_DATA.lat / 10000000).toFixed(4) + ' deg'); $('.GPS_info td.lat').html((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
@ -30,4 +27,5 @@ function gps_pull() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS); send_message(MSP_codes.MSP_RAW_GPS, MSP_codes.MSP_RAW_GPS);
send_message(MSP_codes.MSP_GPSSVINFO, MSP_codes.MSP_GPSSVINFO); send_message(MSP_codes.MSP_GPSSVINFO, MSP_codes.MSP_GPSSVINFO);
}, 75);
} }

View file

@ -41,10 +41,7 @@ function tab_initialize_motor_outputs() {
}); });
// enable Motor data pulling // enable Motor data pulling
timers.push(setInterval(motorPoll, 50)); GUI.interval_add('motor_poll', function() {
}
function motorPoll() {
// Request New Motor data // Request New Motor data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR); send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR);
@ -69,4 +66,5 @@ function motorPoll() {
var color = parseInt(SERVO_DATA[i] * 0.256); var color = parseInt(SERVO_DATA[i] * 0.256);
$('.servo-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'}); $('.servo-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
} }
}, 50);
} }

View file

@ -228,9 +228,7 @@ function tab_initialize_pid_tuning() {
}); });
// enable data pulling // enable data pulling
timers.push(setInterval(pid_data_poll, 50)); GUI.interval_add('pid_data_poll', function() {
}
function pid_data_poll() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
}, 50);
} }

View file

@ -134,10 +134,7 @@ function tab_initialize_receiver() {
}); });
// enable RC data pulling // enable RC data pulling
timers.push(setInterval(receiverPoll, 50)); GUI.interval_add('receiver_poll', function() {
}
function receiverPoll() {
// Update UI with latest data // Update UI with latest data
$('.tab-receiver meter:eq(0)').val(RC.throttle); $('.tab-receiver meter:eq(0)').val(RC.throttle);
$('.tab-receiver .value:eq(0)').html(RC.throttle); $('.tab-receiver .value:eq(0)').html(RC.throttle);
@ -202,4 +199,5 @@ function receiverPoll() {
// Request new data // Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC); send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
}, 50);
} }

View file

@ -204,18 +204,43 @@ function tab_initialize_sensors() {
} }
// timer initialization // timer initialization
disable_timers(); GUI.interval_kill_all(['port-update', 'port_usage', 'serial_read']);
// data pulling timers // data pulling timers
timers.push(setInterval(sensor_status_pull, 50)); GUI.interval_add('status_pull', function() {
timers.push(setInterval(sensor_IMU_pull, fastest)); send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
timers.push(setInterval(sensor_altitude_pull, rates.baro)); }, 50);
timers.push(setInterval(sensor_debug_pull, rates.debug));
GUI.interval_add('IMU_pull', function() {
send_message(MSP_codes.MSP_RAW_IMU, MSP_codes.MSP_RAW_IMU);
}, fastest);
GUI.interval_add('altitude_pull', function() {
send_message(MSP_codes.MSP_ALTITUDE, MSP_codes.MSP_ALTITUDE);
// we can process this one right here
sensor_process_baro();
}, rates.baro);
GUI.interval_add('debug_pull', function() {
send_message(MSP_codes.MSP_DEBUG, MSP_codes.MSP_DEBUG);
// we can process this one right here
sensor_process_debug();
}, rates.debug);
// processing timers // processing timers
timers.push(setInterval(sensor_process_gyro, rates.gyro)); GUI.interval_add('process_gyro', function() {
timers.push(setInterval(sensor_process_accel, rates.accel)); sensor_process_gyro();
timers.push(setInterval(sensor_process_mag, rates.mag)); }, rates.gyro);
GUI.interval_add('process_accel', function() {
sensor_process_accel();
}, rates.accel);
GUI.interval_add('process_mag', function() {
sensor_process_mag();
}, rates.mag);
// store current/latest refresh rates in the storage // store current/latest refresh rates in the storage
chrome.storage.local.set({'sensor_refresh_rates': rates}, function() { chrome.storage.local.set({'sensor_refresh_rates': rates}, function() {
@ -223,29 +248,6 @@ function tab_initialize_sensors() {
}); });
} }
function sensor_status_pull() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
}
function sensor_IMU_pull() {
send_message(MSP_codes.MSP_RAW_IMU, MSP_codes.MSP_RAW_IMU);
}
function sensor_altitude_pull() {
send_message(MSP_codes.MSP_ALTITUDE, MSP_codes.MSP_ALTITUDE);
// we can process this one right here
sensor_process_baro();
}
function sensor_debug_pull() {
send_message(MSP_codes.MSP_DEBUG, MSP_codes.MSP_DEBUG);
// we can process this one right here
sensor_process_debug();
}
function sensor_process_gyro() { function sensor_process_gyro() {
gyro_data[0].push([samples_gyro_i, SENSOR_DATA.gyroscope[0]]); gyro_data[0].push([samples_gyro_i, SENSOR_DATA.gyroscope[0]]);
gyro_data[1].push([samples_gyro_i, SENSOR_DATA.gyroscope[1]]); gyro_data[1].push([samples_gyro_i, SENSOR_DATA.gyroscope[1]]);