1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 14:25:20 +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)
// 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 accepts = [{

View file

@ -170,11 +170,39 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
case 'initial_setup':
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();
break;
case 'auxiliary_configuration':
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();
break;
case 'cli':

View file

@ -116,26 +116,22 @@ $(document).ready(function() {
chrome.serial.open(selected_port, {bitrate: selected_baud}, onOpen);
} else {
// Disable any active "data pulling" timer
disable_timers();
GUI.interval_kill_all(['port-update']);
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);
GUI.connected_to = false;
clearTimeout(connection_delay);
clearInterval(serial_poll);
clearInterval(port_usage_poll);
// Change port utilization to 0
$('span.port-usage').html('0%');
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
configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly)
// unlock port select & baud
$('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
serial_poll = setInterval(readPoll, 10);
port_usage_poll = setInterval(port_usage, 1000);
GUI.interval_add('serial_read', readPoll, 10);
GUI.interval_add('port_usage', port_usage, 1000);
// disconnect after 10 seconds with error if we don't get IDENT data
GUI.timeout_add('connecting', function() {

16
main.js
View file

@ -7,19 +7,6 @@ chrome.runtime.getBackgroundPage(function(result) {
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
var service = analytics.getService('ice_cream_app');
var ga_tracker = service.getTracker('UA-32728876-6');
@ -38,9 +25,6 @@ $(document).ready(function() {
var self = this;
// Disable any active "data pulling" timer
disable_timers();
GUI.tab_switch_cleanup(function() {
// disable previously active tab highlight
$('li', tabs).removeClass('active');

View file

@ -84,7 +84,7 @@ function tab_initialize_cli() {
}
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 bufView = new Uint8Array(bufferOut);

View file

@ -3,31 +3,29 @@ function tab_initialize_gps () {
GUI.active_tab = 'gps';
// enable data pulling
timers.push(setInterval(gps_pull, 75));
}
GUI.interval_add('gps_pull', function() {
// Update GPS data
$('.GPS_info td.alt').html(GPS_DATA.alt + ' m');
$('.GPS_info td.lat').html((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
$('.GPS_info td.lon').html((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
$('.GPS_info td.speed').html(GPS_DATA.speed + ' cm/s');
$('.GPS_info td.sats').html(GPS_DATA.numSat);
$('.GPS_info td.distToHome').html(GPS_DATA.distanceToHome + ' m');
// Update GPS Signal Strengths
var e_ss_table = $('div.GPS_signal_strength table tr:not(.titles)')
for (var i = 0; i < GPS_DATA.chn.length; i++) {
var row = e_ss_table.eq(i);
function gps_pull() {
// Update GPS data
$('.GPS_info td.alt').html(GPS_DATA.alt + ' m');
$('.GPS_info td.lat').html((GPS_DATA.lat / 10000000).toFixed(4) + ' deg');
$('.GPS_info td.lon').html((GPS_DATA.lon / 10000000).toFixed(4) + ' deg');
$('.GPS_info td.speed').html(GPS_DATA.speed + ' cm/s');
$('.GPS_info td.sats').html(GPS_DATA.numSat);
$('.GPS_info td.distToHome').html(GPS_DATA.distanceToHome + ' m');
// Update GPS Signal Strengths
var e_ss_table = $('div.GPS_signal_strength table tr:not(.titles)')
for (var i = 0; i < GPS_DATA.chn.length; i++) {
var row = e_ss_table.eq(i);
$('td', row).eq(0).html(GPS_DATA.svid[i]);
$('td', row).eq(1).html(GPS_DATA.quality[i]);
$('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]);
}
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_GPSSVINFO, MSP_codes.MSP_GPSSVINFO);
$('td', row).eq(0).html(GPS_DATA.svid[i]);
$('td', row).eq(1).html(GPS_DATA.quality[i]);
$('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]);
}
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_GPSSVINFO, MSP_codes.MSP_GPSSVINFO);
}, 75);
}

View file

@ -41,32 +41,30 @@ function tab_initialize_motor_outputs() {
});
// enable Motor data pulling
timers.push(setInterval(motorPoll, 50));
}
GUI.interval_add('motor_poll', function() {
// Request New Motor data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR);
// Update UI
for (var i = 0; i < MOTOR_DATA.length; i++) {
MOTOR_DATA[i] -= 1000;
var margin_top = 220.0 - (MOTOR_DATA[i] * 0.22);
var height = (MOTOR_DATA[i] * 0.22);
var color = parseInt(MOTOR_DATA[i] * 0.256);
$('.motor-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
}
function motorPoll() {
// Request New Motor data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_MOTOR, MSP_codes.MSP_MOTOR);
// Update UI
for (var i = 0; i < MOTOR_DATA.length; i++) {
MOTOR_DATA[i] -= 1000;
var margin_top = 220.0 - (MOTOR_DATA[i] * 0.22);
var height = (MOTOR_DATA[i] * 0.22);
var color = parseInt(MOTOR_DATA[i] * 0.256);
$('.motor-' + i + ' .indicator').css({'margin-top' : margin_top + 'px', 'height' : height + 'px', 'background-color' : 'rgb(' + color + ',0,0)'});
}
// Request New Servo data
send_message(MSP_codes.MSP_SERVO, MSP_codes.MSP_SERVO);
// Update UI
for (var i = 0; i < SERVO_DATA.length; i++) {
SERVO_DATA[i] -= 1000;
var margin_top = 220.0 - (SERVO_DATA[i] * 0.22);
var height = (SERVO_DATA[i] * 0.22);
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)'});
}
// Request New Servo data
send_message(MSP_codes.MSP_SERVO, MSP_codes.MSP_SERVO);
// Update UI
for (var i = 0; i < SERVO_DATA.length; i++) {
SERVO_DATA[i] -= 1000;
var margin_top = 220.0 - (SERVO_DATA[i] * 0.22);
var height = (SERVO_DATA[i] * 0.22);
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)'});
}
}, 50);
}

View file

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

View file

@ -134,72 +134,70 @@ function tab_initialize_receiver() {
});
// enable RC data pulling
timers.push(setInterval(receiverPoll, 50));
}
function receiverPoll() {
// Update UI with latest data
$('.tab-receiver meter:eq(0)').val(RC.throttle);
$('.tab-receiver .value:eq(0)').html(RC.throttle);
$('.tab-receiver meter:eq(1)').val(RC.pitch);
$('.tab-receiver .value:eq(1)').html(RC.pitch);
$('.tab-receiver meter:eq(2)').val(RC.roll);
$('.tab-receiver .value:eq(2)').html(RC.roll);
$('.tab-receiver meter:eq(3)').val(RC.yaw);
$('.tab-receiver .value:eq(3)').html(RC.yaw);
$('.tab-receiver meter:eq(4)').val(RC.AUX1);
$('.tab-receiver .value:eq(4)').html(RC.AUX1);
$('.tab-receiver meter:eq(5)').val(RC.AUX2);
$('.tab-receiver .value:eq(5)').html(RC.AUX2);
$('.tab-receiver meter:eq(6)').val(RC.AUX3);
$('.tab-receiver .value:eq(6)').html(RC.AUX3);
$('.tab-receiver meter:eq(7)').val(RC.AUX4);
$('.tab-receiver .value:eq(7)').html(RC.AUX4);
// push latest data to the main array
RX_plot_data[0].push([samples_i, RC.throttle]);
RX_plot_data[1].push([samples_i, RC.pitch]);
RX_plot_data[2].push([samples_i, RC.roll]);
RX_plot_data[3].push([samples_i, RC.yaw]);
RX_plot_data[4].push([samples_i, RC.AUX1]);
RX_plot_data[5].push([samples_i, RC.AUX2]);
RX_plot_data[6].push([samples_i, RC.AUX3]);
RX_plot_data[7].push([samples_i, RC.AUX4]);
// Remove old data from array
while (RX_plot_data[0].length > 300) {
RX_plot_data[0].shift();
RX_plot_data[1].shift();
RX_plot_data[2].shift();
RX_plot_data[3].shift();
RX_plot_data[4].shift();
RX_plot_data[5].shift();
RX_plot_data[6].shift();
RX_plot_data[7].shift();
};
// redraw plot
Flotr.draw(e_RX_plot, [
{data: RX_plot_data[0], label: "THROTTLE"},
{data: RX_plot_data[1], label: "PITCH"},
{data: RX_plot_data[2], label: "ROLL"},
{data: RX_plot_data[3], label: "YAW"},
{data: RX_plot_data[4], label: "AUX1"},
{data: RX_plot_data[5], label: "AUX2"},
{data: RX_plot_data[6], label: "AUX3"},
{data: RX_plot_data[7], label: "AUX4"} ], RX_plot_options);
GUI.interval_add('receiver_poll', function() {
// Update UI with latest data
$('.tab-receiver meter:eq(0)').val(RC.throttle);
$('.tab-receiver .value:eq(0)').html(RC.throttle);
samples_i++;
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
$('.tab-receiver meter:eq(1)').val(RC.pitch);
$('.tab-receiver .value:eq(1)').html(RC.pitch);
$('.tab-receiver meter:eq(2)').val(RC.roll);
$('.tab-receiver .value:eq(2)').html(RC.roll);
$('.tab-receiver meter:eq(3)').val(RC.yaw);
$('.tab-receiver .value:eq(3)').html(RC.yaw);
$('.tab-receiver meter:eq(4)').val(RC.AUX1);
$('.tab-receiver .value:eq(4)').html(RC.AUX1);
$('.tab-receiver meter:eq(5)').val(RC.AUX2);
$('.tab-receiver .value:eq(5)').html(RC.AUX2);
$('.tab-receiver meter:eq(6)').val(RC.AUX3);
$('.tab-receiver .value:eq(6)').html(RC.AUX3);
$('.tab-receiver meter:eq(7)').val(RC.AUX4);
$('.tab-receiver .value:eq(7)').html(RC.AUX4);
// push latest data to the main array
RX_plot_data[0].push([samples_i, RC.throttle]);
RX_plot_data[1].push([samples_i, RC.pitch]);
RX_plot_data[2].push([samples_i, RC.roll]);
RX_plot_data[3].push([samples_i, RC.yaw]);
RX_plot_data[4].push([samples_i, RC.AUX1]);
RX_plot_data[5].push([samples_i, RC.AUX2]);
RX_plot_data[6].push([samples_i, RC.AUX3]);
RX_plot_data[7].push([samples_i, RC.AUX4]);
// Remove old data from array
while (RX_plot_data[0].length > 300) {
RX_plot_data[0].shift();
RX_plot_data[1].shift();
RX_plot_data[2].shift();
RX_plot_data[3].shift();
RX_plot_data[4].shift();
RX_plot_data[5].shift();
RX_plot_data[6].shift();
RX_plot_data[7].shift();
};
// redraw plot
Flotr.draw(e_RX_plot, [
{data: RX_plot_data[0], label: "THROTTLE"},
{data: RX_plot_data[1], label: "PITCH"},
{data: RX_plot_data[2], label: "ROLL"},
{data: RX_plot_data[3], label: "YAW"},
{data: RX_plot_data[4], label: "AUX1"},
{data: RX_plot_data[5], label: "AUX2"},
{data: RX_plot_data[6], label: "AUX3"},
{data: RX_plot_data[7], label: "AUX4"} ], RX_plot_options);
samples_i++;
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
}, 50);
}

View file

@ -181,10 +181,10 @@ function tab_initialize_sensors() {
// and timers are re-initialized with the new settings
var rates = {
'gyro': parseInt($('.tab-sensors select').eq(0).val()),
'accel': parseInt($('.tab-sensors select').eq(1).val()),
'mag': parseInt($('.tab-sensors select').eq(2).val()),
'baro': parseInt($('.tab-sensors select').eq(3).val()),
'gyro': parseInt($('.tab-sensors select').eq(0).val()),
'accel': parseInt($('.tab-sensors select').eq(1).val()),
'mag': parseInt($('.tab-sensors select').eq(2).val()),
'baro': parseInt($('.tab-sensors select').eq(3).val()),
'debug': parseInt($('.tab-sensors select').eq(4).val())
};
@ -204,18 +204,43 @@ function tab_initialize_sensors() {
}
// timer initialization
disable_timers();
GUI.interval_kill_all(['port-update', 'port_usage', 'serial_read']);
// data pulling timers
timers.push(setInterval(sensor_status_pull, 50));
timers.push(setInterval(sensor_IMU_pull, fastest));
timers.push(setInterval(sensor_altitude_pull, rates.baro));
timers.push(setInterval(sensor_debug_pull, rates.debug));
GUI.interval_add('status_pull', function() {
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
}, 50);
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
timers.push(setInterval(sensor_process_gyro, rates.gyro));
timers.push(setInterval(sensor_process_accel, rates.accel));
timers.push(setInterval(sensor_process_mag, rates.mag));
GUI.interval_add('process_gyro', function() {
sensor_process_gyro();
}, 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
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() {
gyro_data[0].push([samples_gyro_i, SENSOR_DATA.gyroscope[0]]);
gyro_data[1].push([samples_gyro_i, SENSOR_DATA.gyroscope[1]]);