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:
parent
5e636b2920
commit
e7a02d0e21
10 changed files with 192 additions and 190 deletions
|
@ -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 = [{
|
||||
|
|
28
js/gui.js
28
js/gui.js
|
@ -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':
|
||||
|
|
|
@ -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%');
|
||||
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)
|
||||
|
||||
MSP.packet_error = 0; // reset CRC packet error counter for next session
|
||||
|
||||
// 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
16
main.js
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -3,10 +3,7 @@ function tab_initialize_gps () {
|
|||
GUI.active_tab = 'gps';
|
||||
|
||||
// enable data pulling
|
||||
timers.push(setInterval(gps_pull, 75));
|
||||
}
|
||||
|
||||
function gps_pull() {
|
||||
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');
|
||||
|
@ -30,4 +27,5 @@ function gps_pull() {
|
|||
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);
|
||||
}
|
|
@ -41,10 +41,7 @@ function tab_initialize_motor_outputs() {
|
|||
});
|
||||
|
||||
// enable Motor data pulling
|
||||
timers.push(setInterval(motorPoll, 50));
|
||||
}
|
||||
|
||||
function motorPoll() {
|
||||
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);
|
||||
|
@ -69,4 +66,5 @@ function motorPoll() {
|
|||
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);
|
||||
}
|
|
@ -228,9 +228,7 @@ function tab_initialize_pid_tuning() {
|
|||
});
|
||||
|
||||
// enable data pulling
|
||||
timers.push(setInterval(pid_data_poll, 50));
|
||||
}
|
||||
|
||||
function pid_data_poll() {
|
||||
GUI.interval_add('pid_data_poll', function() {
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
}, 50);
|
||||
}
|
|
@ -134,10 +134,7 @@ function tab_initialize_receiver() {
|
|||
});
|
||||
|
||||
// enable RC data pulling
|
||||
timers.push(setInterval(receiverPoll, 50));
|
||||
}
|
||||
|
||||
function receiverPoll() {
|
||||
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);
|
||||
|
@ -202,4 +199,5 @@ function receiverPoll() {
|
|||
// Request new data
|
||||
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
|
||||
send_message(MSP_codes.MSP_RC, MSP_codes.MSP_RC);
|
||||
}, 50);
|
||||
}
|
|
@ -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]]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue