mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 13:25:30 +03:00
implementing GUI object with active_tab tracking
This commit is contained in:
parent
9ed0ebc4d6
commit
36604ca724
12 changed files with 148 additions and 0 deletions
136
js/gui.js
136
js/gui.js
|
@ -0,0 +1,136 @@
|
|||
var GUI_control = function() {
|
||||
this.active_tab;
|
||||
|
||||
this.interval_array = [];
|
||||
this.timeout_array = [];
|
||||
};
|
||||
|
||||
// Timer managing methods
|
||||
|
||||
// name = string
|
||||
// code = function reference (code to be executed)
|
||||
// interval = time interval in miliseconds
|
||||
// first = true/false if code should be ran initially before next timer interval hits
|
||||
GUI_control.prototype.interval_add = function(name, code, interval, first) {
|
||||
var data = {'name': name, 'timer': undefined, 'interval': interval, 'fired' : 0};
|
||||
|
||||
if (first == true) {
|
||||
code(); // execute code
|
||||
|
||||
data.fired++; // increment counter
|
||||
}
|
||||
|
||||
data.timer = setInterval(function() {
|
||||
code(); // execute code
|
||||
|
||||
data.fired++; // increment counter
|
||||
}, interval);
|
||||
|
||||
this.interval_array.push(data); // push to primary interval array
|
||||
};
|
||||
|
||||
// name = string
|
||||
GUI_control.prototype.interval_remove = function(name) {
|
||||
for (var i = 0; i < this.interval_array.length; i++) {
|
||||
if (this.interval_array[i].name == name) {
|
||||
clearInterval(this.interval_array[i].timer); // stop timer
|
||||
|
||||
this.interval_array.splice(i, 1); // remove element/object from array
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// input = array of timers thats meant to be kept
|
||||
// return = returns timers killed in last call
|
||||
GUI_control.prototype.interval_kill_all = function(keep_array) {
|
||||
var timers_killed = 0;
|
||||
|
||||
for (var i = (this.interval_array.length - 1); i >= 0; i--) { // reverse iteration
|
||||
var self = this;
|
||||
|
||||
var keep = false;
|
||||
keep_array.forEach(function(name) {
|
||||
if (self.interval_array[i].name == name) {
|
||||
keep = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!keep) {
|
||||
clearInterval(this.interval_array[i].timer); // stop timer
|
||||
this.interval_array[i].timer = undefined; // set timer property to undefined (mostly for debug purposes, but it doesn't hurt to have it here)
|
||||
|
||||
this.interval_array.splice(i, 1); // remove element/object from array
|
||||
|
||||
timers_killed++;
|
||||
}
|
||||
}
|
||||
|
||||
return timers_killed;
|
||||
};
|
||||
|
||||
// name = string
|
||||
// code = function reference (code to be executed)
|
||||
// timeout = timeout in miliseconds
|
||||
GUI_control.prototype.timeout_add = function(name, code, timeout) {
|
||||
var self = this;
|
||||
// start timer with "cleaning" callback
|
||||
var timer = setTimeout(function() {
|
||||
code(); // execute code
|
||||
|
||||
self.timeout_remove(name); // cleanup
|
||||
}, timeout);
|
||||
|
||||
this.timeout_array.push({'name': name, 'timer': timer, 'timeout': timeout}); // push to primary timeout array
|
||||
};
|
||||
|
||||
// name = string
|
||||
GUI_control.prototype.timeout_remove = function(name) {
|
||||
for (var i = 0; i < this.timeout_array.length; i++) {
|
||||
if (this.timeout_array[i].name == name) {
|
||||
clearTimeout(this.timeout_array[i].timer); // stop timer
|
||||
|
||||
this.timeout_array.splice(i, 1); // remove element/object from array
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// no input paremeters
|
||||
// return = returns timers killed in last call
|
||||
GUI_control.prototype.timeout_kill_all = function() {
|
||||
var timers_killed = 0;
|
||||
|
||||
for (var i = 0; i < this.timeout_array.length; i++) {
|
||||
clearTimeout(this.timeout_array[i].timer); // stop timer
|
||||
|
||||
timers_killed++;
|
||||
}
|
||||
|
||||
this.timeout_array = []; // drop objects
|
||||
|
||||
return timers_killed;
|
||||
};
|
||||
|
||||
// Method is called every time a valid tab change event is received
|
||||
// callback = code to run when cleanup is finished
|
||||
// default switch doesn't require callback to be set
|
||||
GUI_control.prototype.tab_switch_cleanup = function(callback) {
|
||||
switch (this.active_tab) {
|
||||
case 'cli':
|
||||
break;
|
||||
default:
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// initialize object into GUI variable
|
||||
var GUI = new GUI_control();
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_about() {
|
||||
ga_tracker.sendAppView('About Page');
|
||||
GUI.active_tab = 'about';
|
||||
|
||||
// enable data pulling
|
||||
timers.push(setInterval(about_data_poll, 50));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_auxiliary_configuration() {
|
||||
ga_tracker.sendAppView('Auxiliary Configuration');
|
||||
GUI.active_tab = 'auxiliary_configuration';
|
||||
|
||||
// generate table from the supplied AUX names and AUX data
|
||||
for (var i = 0; i < AUX_CONFIG.length; i++) {
|
||||
|
|
|
@ -23,6 +23,7 @@ cli_history = new CliHistory();
|
|||
|
||||
function tab_initialize_cli() {
|
||||
ga_tracker.sendAppView('CLI Page');
|
||||
GUI.active_tab = 'cli';
|
||||
|
||||
CLI_active = true;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
function tab_initialize_default() {
|
||||
$('#content').load("./tabs/default.html", function() {
|
||||
GUI.active_tab = 'default';
|
||||
|
||||
// load changelog content
|
||||
$('div.changelog.configurator .wrapper').load('./changelog.html');
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_gps () {
|
||||
ga_tracker.sendAppView('GPS Page');
|
||||
GUI.active_tab = 'gps';
|
||||
|
||||
// enable data pulling
|
||||
timers.push(setInterval(gps_pull, 75));
|
||||
|
|
|
@ -2,6 +2,7 @@ var yaw_fix = 0.0;
|
|||
|
||||
function tab_initialize_initial_setup() {
|
||||
ga_tracker.sendAppView('Initial Setup');
|
||||
GUI.active_tab = 'initial_setup';
|
||||
|
||||
// Fill in the accel trimms from CONFIG object
|
||||
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_motor_outputs() {
|
||||
ga_tracker.sendAppView('Motor Outputs Page');
|
||||
GUI.active_tab = 'motor_outputs';
|
||||
|
||||
// enable Motor data pulling
|
||||
timers.push(setInterval(motorPoll, 50));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_pid_tuning() {
|
||||
ga_tracker.sendAppView('PID Tuning');
|
||||
GUI.active_tab = 'pid_tuning';
|
||||
|
||||
// Fill in the data from PIDs array
|
||||
var needle = 0;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var samples_i;
|
||||
function tab_initialize_receiver() {
|
||||
ga_tracker.sendAppView('Receiver Page');
|
||||
GUI.active_tab = 'receiver';
|
||||
|
||||
// fill in data from RC_tuning
|
||||
$('.tunings .throttle input[name="mid"]').val(RC_tuning.throttle_MID.toFixed(2));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_sensors() {
|
||||
ga_tracker.sendAppView('Sensor Page');
|
||||
GUI.active_tab = 'sensors';
|
||||
|
||||
// Setup variables
|
||||
samples_gyro_i = 300;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
function tab_initialize_servos() {
|
||||
ga_tracker.sendAppView('Servos');
|
||||
GUI.active_tab = 'servos';
|
||||
|
||||
var model = $('div.tab-servos strong.model');
|
||||
var servos = [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue