mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 05:45:31 +03:00
lots of work on removing global variables
This commit is contained in:
parent
377853b58a
commit
ec44b77ff2
8 changed files with 156 additions and 265 deletions
|
@ -25,7 +25,7 @@ function start_app() {
|
||||||
|
|
||||||
// save connectionId in separate variable before app_window is destroyed
|
// save connectionId in separate variable before app_window is destroyed
|
||||||
var connectionId = app_window.serial.connectionId;
|
var connectionId = app_window.serial.connectionId;
|
||||||
var valid_connection = app_window.configuration_received;
|
var valid_connection = app_window.CONFIGURATOR.connectionValid;
|
||||||
var mincommand = app_window.MISC.mincommand;
|
var mincommand = app_window.MISC.mincommand;
|
||||||
|
|
||||||
if (connectionId > 0 && valid_connection) {
|
if (connectionId > 0 && valid_connection) {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var firmware_version_accepted = 2.3;
|
var CONFIGURATOR = {
|
||||||
|
'firmwareVersionAccepted': 2.3,
|
||||||
|
'connectionValid': false,
|
||||||
|
'mspPassThrough': false,
|
||||||
|
'cliActive': false,
|
||||||
|
'cliValid': false
|
||||||
|
};
|
||||||
|
|
||||||
var CONFIG = {
|
var CONFIG = {
|
||||||
version: 0,
|
version: 0,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var configuration_received = false;
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('div#port-picker a.connect').click(function() {
|
$('div#port-picker a.connect').click(function() {
|
||||||
if (GUI.connect_lock != true) { // GUI control overrides the user control
|
if (GUI.connect_lock != true) { // GUI control overrides the user control
|
||||||
|
@ -36,8 +34,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
MSP.disconnect_cleanup();
|
MSP.disconnect_cleanup();
|
||||||
PortUsage.reset();
|
PortUsage.reset();
|
||||||
configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly)
|
CONFIGURATOR.connectionValid = false;
|
||||||
MSP_pass_through = false;
|
CONFIGURATOR.mspPassThrough = false;
|
||||||
|
|
||||||
// unlock port select & baud
|
// unlock port select & baud
|
||||||
$('div#port-picker #port').prop('disabled', false);
|
$('div#port-picker #port').prop('disabled', false);
|
||||||
|
@ -127,10 +125,10 @@ function onOpen(openInfo) {
|
||||||
|
|
||||||
serial.onReceive.addListener(read_serial);
|
serial.onReceive.addListener(read_serial);
|
||||||
|
|
||||||
if (!MSP_pass_through) {
|
if (!CONFIGURATOR.mspPassThrough) {
|
||||||
// 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() {
|
||||||
if (!configuration_received) {
|
if (!CONFIGURATOR.connectionValid) {
|
||||||
GUI.log(chrome.i18n.getMessage('noConfigurationReceived'));
|
GUI.log(chrome.i18n.getMessage('noConfigurationReceived'));
|
||||||
|
|
||||||
$('div#port-picker a.connect').click(); // disconnect
|
$('div#port-picker a.connect').click(); // disconnect
|
||||||
|
@ -145,13 +143,13 @@ function onOpen(openInfo) {
|
||||||
|
|
||||||
GUI.log(chrome.i18n.getMessage('firmwareVersion', [CONFIG.version]));
|
GUI.log(chrome.i18n.getMessage('firmwareVersion', [CONFIG.version]));
|
||||||
|
|
||||||
if (CONFIG.version >= firmware_version_accepted) {
|
if (CONFIG.version >= CONFIGURATOR.firmwareVersionAccepted) {
|
||||||
configuration_received = true;
|
CONFIGURATOR.connectionValid = true;
|
||||||
|
|
||||||
$('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active');
|
$('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active');
|
||||||
$('#tabs li a:first').click();
|
$('#tabs li a:first').click();
|
||||||
} else {
|
} else {
|
||||||
GUI.log(chrome.i18n.getMessage('firmwareVersionNotSupported', [firmware_version_accepted]));
|
GUI.log(chrome.i18n.getMessage('firmwareVersionNotSupported', [CONFIGURATOR.firmwareVersionAccepted]));
|
||||||
$('div#port-picker a.connect').click(); // disconnect
|
$('div#port-picker a.connect').click(); // disconnect
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -184,18 +182,18 @@ function onClosed(result) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_serial(info) {
|
function read_serial(info) {
|
||||||
if (!CLI_active && !MSP_pass_through) {
|
if (!CONFIGURATOR.cliActive && !CONFIGURATOR.mspPassThrough) {
|
||||||
MSP.read(info);
|
MSP.read(info);
|
||||||
} else if (CLI_active) {
|
} else if (CONFIGURATOR.cliActive) {
|
||||||
handle_CLI(info);
|
tabs.cli.read(info);
|
||||||
} else if (MSP_pass_through) { // needs to be verified, might be removed after pass_through is 100% deployed
|
} else if (CONFIGURATOR.mspPassThrough) {
|
||||||
MSP.read(info);
|
MSP.read(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sensor_status(sensors_detected) {
|
function sensor_status(sensors_detected) {
|
||||||
// initialize variable (if it wasn't)
|
// initialize variable (if it wasn't)
|
||||||
if (typeof sensor_status.previous_sensors_detected == 'undefined') {
|
if (sensor_status.previous_sensors_detected === 'undefined') {
|
||||||
sensor_status.previous_sensors_detected = 0;
|
sensor_status.previous_sensors_detected = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
111
main.js
111
main.js
|
@ -50,7 +50,7 @@ $(document).ready(function () {
|
||||||
tab = $(self).parent().prop('class');
|
tab = $(self).parent().prop('class');
|
||||||
|
|
||||||
// if there is no active connection, return
|
// if there is no active connection, return
|
||||||
if (!configuration_received && tab != 'tab_logging') {
|
if (!CONFIGURATOR.connectionValid && tab != 'tab_logging') {
|
||||||
GUI.log('You need to <strong>connect</strong> before you can view any of the tabs');
|
GUI.log('You need to <strong>connect</strong> before you can view any of the tabs');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -265,112 +265,3 @@ function bytesToSize(bytes) {
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
function add_custom_spinners() {
|
|
||||||
var spinner_element = '<div class="spinner"><div class="up"></div><div class="down"></div></div>';
|
|
||||||
|
|
||||||
$('input[type="number"]').each(function() {
|
|
||||||
var input = $(this);
|
|
||||||
|
|
||||||
// only add new spinner if one doesn't already exist
|
|
||||||
if (!input.next().hasClass('spinner')) {
|
|
||||||
var isInt = true;
|
|
||||||
if (input.prop('step') == '') {
|
|
||||||
isInt = true;
|
|
||||||
} else {
|
|
||||||
if (input.prop('step').indexOf('.') == -1) {
|
|
||||||
isInt = true;
|
|
||||||
} else {
|
|
||||||
isInt = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// make space for spinner
|
|
||||||
input.width(input.width() - 16);
|
|
||||||
|
|
||||||
// add spinner
|
|
||||||
input.after(spinner_element);
|
|
||||||
|
|
||||||
// get spinner refference
|
|
||||||
var spinner = input.next();
|
|
||||||
|
|
||||||
// bind UI hooks to spinner
|
|
||||||
$('.up', spinner).click(function() {
|
|
||||||
up();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mousedown(function() {
|
|
||||||
GUI.timeout_add('spinner', function() {
|
|
||||||
GUI.interval_add('spinner', function() {
|
|
||||||
up();
|
|
||||||
}, 100, true);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mouseup(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.up', spinner).mouseleave(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$('.down', spinner).click(function() {
|
|
||||||
down();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mousedown(function() {
|
|
||||||
GUI.timeout_add('spinner', function() {
|
|
||||||
GUI.interval_add('spinner', function() {
|
|
||||||
down();
|
|
||||||
}, 100, true);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mouseup(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.down', spinner).mouseleave(function() {
|
|
||||||
GUI.timeout_remove('spinner');
|
|
||||||
GUI.interval_remove('spinner');
|
|
||||||
});
|
|
||||||
|
|
||||||
var up = function() {
|
|
||||||
if (isInt) {
|
|
||||||
var current_value = parseInt(input.val());
|
|
||||||
input.val(current_value + 1);
|
|
||||||
} else {
|
|
||||||
var current_value = parseFloat(input.val());
|
|
||||||
var step = parseFloat(input.prop('step'));
|
|
||||||
var step_decimals = input.prop('step').length - 2;
|
|
||||||
|
|
||||||
input.val((current_value + step).toFixed(step_decimals));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.change();
|
|
||||||
};
|
|
||||||
|
|
||||||
var down = function() {
|
|
||||||
if (isInt) {
|
|
||||||
var current_value = parseInt(input.val());
|
|
||||||
input.val(current_value - 1);
|
|
||||||
} else {
|
|
||||||
var current_value = parseFloat(input.val());
|
|
||||||
var step = parseFloat(input.prop('step'));
|
|
||||||
var step_decimals = input.prop('step').length - 2;
|
|
||||||
|
|
||||||
input.val((current_value - step).toFixed(step_decimals));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.change();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
96
tabs/cli.js
96
tabs/cli.js
|
@ -1,9 +1,10 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var CLI_active = false;
|
tabs.cli = {
|
||||||
var CLI_valid = false;
|
'validateText': "",
|
||||||
|
'sequenceElements': 0
|
||||||
|
};
|
||||||
|
|
||||||
tabs.cli = {};
|
|
||||||
tabs.cli.initialize = function(callback) {
|
tabs.cli.initialize = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
GUI.active_tab_ref = this;
|
GUI.active_tab_ref = this;
|
||||||
|
@ -14,7 +15,7 @@ tabs.cli.initialize = function(callback) {
|
||||||
// translate to user-selected language
|
// translate to user-selected language
|
||||||
localize();
|
localize();
|
||||||
|
|
||||||
CLI_active = true;
|
CONFIGURATOR.cliActive = true;
|
||||||
|
|
||||||
// Enter CLI mode
|
// Enter CLI mode
|
||||||
var bufferOut = new ArrayBuffer(1);
|
var bufferOut = new ArrayBuffer(1);
|
||||||
|
@ -36,7 +37,7 @@ tabs.cli.initialize = function(callback) {
|
||||||
|
|
||||||
var timeout_needle = 0;
|
var timeout_needle = 0;
|
||||||
for (var i = 0; i < out_arr.length; i++) {
|
for (var i = 0; i < out_arr.length; i++) {
|
||||||
send_slowly(out_arr, i, timeout_needle++);
|
self.sendSlowly(out_arr, i, timeout_needle++);
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea.val('');
|
textarea.val('');
|
||||||
|
@ -78,31 +79,7 @@ tabs.cli.history.next = function() {
|
||||||
return this.history[this.index - 1];
|
return this.history[this.index - 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
tabs.cli.cleanup = function(callback) {
|
tabs.cli.sendSlowly = function (out_arr, i, timeout_needle) {
|
||||||
var bufferOut = new ArrayBuffer(5);
|
|
||||||
var bufView = new Uint8Array(bufferOut);
|
|
||||||
|
|
||||||
bufView[0] = 0x65; // e
|
|
||||||
bufView[1] = 0x78; // x
|
|
||||||
bufView[2] = 0x69; // i
|
|
||||||
bufView[3] = 0x74; // t
|
|
||||||
bufView[4] = 0x0D; // enter
|
|
||||||
|
|
||||||
serial.send(bufferOut, function(writeInfo) {
|
|
||||||
// we could handle this "nicely", but this will do for now
|
|
||||||
// (another approach is however much more complicated):
|
|
||||||
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
|
|
||||||
// we could probably implement this someday
|
|
||||||
GUI.timeout_add('waiting_for_bootup', function() {
|
|
||||||
CLI_active = false;
|
|
||||||
CLI_valid = false;
|
|
||||||
|
|
||||||
if (callback) callback();
|
|
||||||
}, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function send_slowly(out_arr, i, timeout_needle) {
|
|
||||||
GUI.timeout_add('CLI_send_slowly', 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);
|
||||||
|
@ -115,8 +92,9 @@ function send_slowly(out_arr, i, timeout_needle) {
|
||||||
|
|
||||||
serial.send(bufferOut, function (writeInfo) {});
|
serial.send(bufferOut, function (writeInfo) {});
|
||||||
}, timeout_needle * 5);
|
}, timeout_needle * 5);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
tabs.cli.read = function (readInfo) {
|
||||||
/* Some info about handling line feeds and carriage return
|
/* Some info about handling line feeds and carriage return
|
||||||
|
|
||||||
line feed = LF = \n = 0x0A = 10
|
line feed = LF = \n = 0x0A = 10
|
||||||
|
@ -127,30 +105,26 @@ function send_slowly(out_arr, i, timeout_needle) {
|
||||||
Windows understands (both) CRLF
|
Windows understands (both) CRLF
|
||||||
Chrome OS currenty unknown
|
Chrome OS currenty unknown
|
||||||
*/
|
*/
|
||||||
|
var data = new Uint8Array(readInfo.data),
|
||||||
var sequence_elements = 0;
|
text = "";
|
||||||
var CLI_validate_text = "";
|
|
||||||
function handle_CLI(readInfo) {
|
|
||||||
var data = new Uint8Array(readInfo.data);
|
|
||||||
var text = "";
|
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
if (CLI_valid) {
|
if (CONFIGURATOR.cliValid) {
|
||||||
if (data[i] == 27 || sequence_elements > 0) { // ESC + other
|
if (data[i] == 27 || this.sequenceElements > 0) { // ESC + other
|
||||||
sequence_elements++;
|
this.sequenceElements++;
|
||||||
|
|
||||||
// delete previous space
|
// delete previous space
|
||||||
if (sequence_elements == 1) {
|
if (this.sequenceElements == 1) {
|
||||||
text = text.substring(0, text.length -1);
|
text = text.substring(0, text.length -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
if (sequence_elements >= 5) {
|
if (this.sequenceElements >= 5) {
|
||||||
sequence_elements = 0;
|
this.sequenceElements = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sequence_elements == 0) {
|
if (this.sequenceElements == 0) {
|
||||||
switch (data[i]) {
|
switch (data[i]) {
|
||||||
case 10: // line feed
|
case 10: // line feed
|
||||||
if (GUI.operating_system != "MacOS") {
|
if (GUI.operating_system != "MacOS") {
|
||||||
|
@ -168,13 +142,13 @@ function handle_CLI(readInfo) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// try to catch part of valid CLI enter message
|
// try to catch part of valid CLI enter message
|
||||||
CLI_validate_text += String.fromCharCode(data[i]);
|
this.validateText += String.fromCharCode(data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CLI_valid && CLI_validate_text.indexOf('CLI') != -1) {
|
if (!CONFIGURATOR.cliValid && this.validateText.indexOf('CLI') != -1) {
|
||||||
CLI_valid = true;
|
CONFIGURATOR.cliValid = true;
|
||||||
CLI_validate_text = "";
|
this.validateText = "";
|
||||||
|
|
||||||
text = "Entering CLI Mode, type 'exit' to return, or 'help'<br /><br /># ";
|
text = "Entering CLI Mode, type 'exit' to return, or 'help'<br /><br /># ";
|
||||||
}
|
}
|
||||||
|
@ -184,4 +158,28 @@ function handle_CLI(readInfo) {
|
||||||
|
|
||||||
// there seems to be some sort of initial rendering glitch in 33+, we will force redraw/refill
|
// there seems to be some sort of initial rendering glitch in 33+, we will force redraw/refill
|
||||||
$('.tab-cli .window .wrapper').css('webkitTransform', 'scale(1)');
|
$('.tab-cli .window .wrapper').css('webkitTransform', 'scale(1)');
|
||||||
}
|
};
|
||||||
|
|
||||||
|
tabs.cli.cleanup = function(callback) {
|
||||||
|
var bufferOut = new ArrayBuffer(5);
|
||||||
|
var bufView = new Uint8Array(bufferOut);
|
||||||
|
|
||||||
|
bufView[0] = 0x65; // e
|
||||||
|
bufView[1] = 0x78; // x
|
||||||
|
bufView[2] = 0x69; // i
|
||||||
|
bufView[3] = 0x74; // t
|
||||||
|
bufView[4] = 0x0D; // enter
|
||||||
|
|
||||||
|
serial.send(bufferOut, function(writeInfo) {
|
||||||
|
// we could handle this "nicely", but this will do for now
|
||||||
|
// (another approach is however much more complicated):
|
||||||
|
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
|
||||||
|
// we could probably implement this someday
|
||||||
|
GUI.timeout_add('waiting_for_bootup', function() {
|
||||||
|
CONFIGURATOR.cliActive = false;
|
||||||
|
CONFIGURATOR.cliValid = false;
|
||||||
|
|
||||||
|
if (callback) callback();
|
||||||
|
}, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
|
||||||
|
});
|
||||||
|
};
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var MSP_pass_through = false;
|
|
||||||
|
|
||||||
tabs.logging = {};
|
tabs.logging = {};
|
||||||
tabs.logging.initialize = function(callback) {
|
tabs.logging.initialize = function(callback) {
|
||||||
GUI.active_tab_ref = this;
|
GUI.active_tab_ref = this;
|
||||||
|
@ -10,7 +8,7 @@ tabs.logging.initialize = function(callback) {
|
||||||
|
|
||||||
var requested_properties = [];
|
var requested_properties = [];
|
||||||
|
|
||||||
if (configuration_received) {
|
if (CONFIGURATOR.connectionValid) {
|
||||||
MSP.send_message(MSP_codes.MSP_RC, false, false, get_motor_data);
|
MSP.send_message(MSP_codes.MSP_RC, false, false, get_motor_data);
|
||||||
|
|
||||||
var get_motor_data = function () {
|
var get_motor_data = function () {
|
||||||
|
@ -21,7 +19,7 @@ tabs.logging.initialize = function(callback) {
|
||||||
$('#content').load("./tabs/logging.html", process_html);
|
$('#content').load("./tabs/logging.html", process_html);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MSP_pass_through = true;
|
CONFIGURATOR.mspPassThrough = true;
|
||||||
|
|
||||||
// we will initialize RC.channels array and MOTOR_DATA array manually
|
// we will initialize RC.channels array and MOTOR_DATA array manually
|
||||||
RC.active_channels = 8;
|
RC.active_channels = 8;
|
||||||
|
@ -70,7 +68,7 @@ tabs.logging.initialize = function(callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// request new
|
// request new
|
||||||
if (!MSP_pass_through) {
|
if (!CONFIGURATOR.mspPassThrough) {
|
||||||
for (var i = 0; i < requested_properties.length; i++, requests++) {
|
for (var i = 0; i < requested_properties.length; i++, requests++) {
|
||||||
MSP.send_message(MSP_codes[requested_properties[i]]);
|
MSP.send_message(MSP_codes[requested_properties[i]]);
|
||||||
}
|
}
|
||||||
|
@ -113,7 +111,7 @@ tabs.logging.initialize = function(callback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (MSP_pass_through) {
|
if (CONFIGURATOR.mspPassThrough) {
|
||||||
$('a.back').show();
|
$('a.back').show();
|
||||||
|
|
||||||
$('a.back').click(function() {
|
$('a.back').click(function() {
|
||||||
|
@ -121,7 +119,7 @@ tabs.logging.initialize = function(callback) {
|
||||||
$('a.connect').click();
|
$('a.connect').click();
|
||||||
} else {
|
} else {
|
||||||
GUI.tab_switch_cleanup(function() {
|
GUI.tab_switch_cleanup(function() {
|
||||||
MSP_pass_through = false;
|
CONFIGURATOR.mspPassThrough = false;
|
||||||
$('#tabs > ul li').removeClass('active');
|
$('#tabs > ul li').removeClass('active');
|
||||||
tabs.default.initialize();
|
tabs.default.initialize();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue