mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 21:05:28 +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
|
||||
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;
|
||||
|
||||
if (connectionId > 0 && valid_connection) {
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
var firmware_version_accepted = 2.3;
|
||||
var CONFIGURATOR = {
|
||||
'firmwareVersionAccepted': 2.3,
|
||||
'connectionValid': false,
|
||||
'mspPassThrough': false,
|
||||
'cliActive': false,
|
||||
'cliValid': false
|
||||
};
|
||||
|
||||
var CONFIG = {
|
||||
version: 0,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var configuration_received = false;
|
||||
|
||||
$(document).ready(function() {
|
||||
$('div#port-picker a.connect').click(function() {
|
||||
if (GUI.connect_lock != true) { // GUI control overrides the user control
|
||||
|
@ -36,8 +34,8 @@ $(document).ready(function() {
|
|||
|
||||
MSP.disconnect_cleanup();
|
||||
PortUsage.reset();
|
||||
configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly)
|
||||
MSP_pass_through = false;
|
||||
CONFIGURATOR.connectionValid = false;
|
||||
CONFIGURATOR.mspPassThrough = false;
|
||||
|
||||
// unlock port select & baud
|
||||
$('div#port-picker #port').prop('disabled', false);
|
||||
|
@ -127,10 +125,10 @@ function onOpen(openInfo) {
|
|||
|
||||
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
|
||||
GUI.timeout_add('connecting', function() {
|
||||
if (!configuration_received) {
|
||||
if (!CONFIGURATOR.connectionValid) {
|
||||
GUI.log(chrome.i18n.getMessage('noConfigurationReceived'));
|
||||
|
||||
$('div#port-picker a.connect').click(); // disconnect
|
||||
|
@ -145,13 +143,13 @@ function onOpen(openInfo) {
|
|||
|
||||
GUI.log(chrome.i18n.getMessage('firmwareVersion', [CONFIG.version]));
|
||||
|
||||
if (CONFIG.version >= firmware_version_accepted) {
|
||||
configuration_received = true;
|
||||
if (CONFIG.version >= CONFIGURATOR.firmwareVersionAccepted) {
|
||||
CONFIGURATOR.connectionValid = true;
|
||||
|
||||
$('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active');
|
||||
$('#tabs li a:first').click();
|
||||
} 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
|
||||
}
|
||||
});
|
||||
|
@ -184,18 +182,18 @@ function onClosed(result) {
|
|||
}
|
||||
|
||||
function read_serial(info) {
|
||||
if (!CLI_active && !MSP_pass_through) {
|
||||
if (!CONFIGURATOR.cliActive && !CONFIGURATOR.mspPassThrough) {
|
||||
MSP.read(info);
|
||||
} else if (CLI_active) {
|
||||
handle_CLI(info);
|
||||
} else if (MSP_pass_through) { // needs to be verified, might be removed after pass_through is 100% deployed
|
||||
} else if (CONFIGURATOR.cliActive) {
|
||||
tabs.cli.read(info);
|
||||
} else if (CONFIGURATOR.mspPassThrough) {
|
||||
MSP.read(info);
|
||||
}
|
||||
}
|
||||
|
||||
function sensor_status(sensors_detected) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
111
main.js
111
main.js
|
@ -50,7 +50,7 @@ $(document).ready(function () {
|
|||
tab = $(self).parent().prop('class');
|
||||
|
||||
// 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');
|
||||
return;
|
||||
}
|
||||
|
@ -265,112 +265,3 @@ function bytesToSize(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';
|
||||
|
||||
var CLI_active = false;
|
||||
var CLI_valid = false;
|
||||
tabs.cli = {
|
||||
'validateText': "",
|
||||
'sequenceElements': 0
|
||||
};
|
||||
|
||||
tabs.cli = {};
|
||||
tabs.cli.initialize = function(callback) {
|
||||
var self = this;
|
||||
GUI.active_tab_ref = this;
|
||||
|
@ -14,7 +15,7 @@ tabs.cli.initialize = function(callback) {
|
|||
// translate to user-selected language
|
||||
localize();
|
||||
|
||||
CLI_active = true;
|
||||
CONFIGURATOR.cliActive = true;
|
||||
|
||||
// Enter CLI mode
|
||||
var bufferOut = new ArrayBuffer(1);
|
||||
|
@ -36,7 +37,7 @@ tabs.cli.initialize = function(callback) {
|
|||
|
||||
var timeout_needle = 0;
|
||||
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('');
|
||||
|
@ -78,31 +79,7 @@ tabs.cli.history.next = function() {
|
|||
return this.history[this.index - 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() {
|
||||
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) {
|
||||
tabs.cli.sendSlowly = function (out_arr, i, timeout_needle) {
|
||||
GUI.timeout_add('CLI_send_slowly', function () {
|
||||
var bufferOut = new ArrayBuffer(out_arr[i].length + 1);
|
||||
var bufView = new Uint8Array(bufferOut);
|
||||
|
@ -115,8 +92,9 @@ function send_slowly(out_arr, i, timeout_needle) {
|
|||
|
||||
serial.send(bufferOut, function (writeInfo) {});
|
||||
}, timeout_needle * 5);
|
||||
}
|
||||
};
|
||||
|
||||
tabs.cli.read = function (readInfo) {
|
||||
/* Some info about handling line feeds and carriage return
|
||||
|
||||
line feed = LF = \n = 0x0A = 10
|
||||
|
@ -127,30 +105,26 @@ function send_slowly(out_arr, i, timeout_needle) {
|
|||
Windows understands (both) CRLF
|
||||
Chrome OS currenty unknown
|
||||
*/
|
||||
|
||||
var sequence_elements = 0;
|
||||
var CLI_validate_text = "";
|
||||
function handle_CLI(readInfo) {
|
||||
var data = new Uint8Array(readInfo.data);
|
||||
var text = "";
|
||||
var data = new Uint8Array(readInfo.data),
|
||||
text = "";
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
if (CLI_valid) {
|
||||
if (data[i] == 27 || sequence_elements > 0) { // ESC + other
|
||||
sequence_elements++;
|
||||
if (CONFIGURATOR.cliValid) {
|
||||
if (data[i] == 27 || this.sequenceElements > 0) { // ESC + other
|
||||
this.sequenceElements++;
|
||||
|
||||
// delete previous space
|
||||
if (sequence_elements == 1) {
|
||||
if (this.sequenceElements == 1) {
|
||||
text = text.substring(0, text.length -1);
|
||||
}
|
||||
|
||||
// Reset
|
||||
if (sequence_elements >= 5) {
|
||||
sequence_elements = 0;
|
||||
if (this.sequenceElements >= 5) {
|
||||
this.sequenceElements = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (sequence_elements == 0) {
|
||||
if (this.sequenceElements == 0) {
|
||||
switch (data[i]) {
|
||||
case 10: // line feed
|
||||
if (GUI.operating_system != "MacOS") {
|
||||
|
@ -168,13 +142,13 @@ function handle_CLI(readInfo) {
|
|||
}
|
||||
} else {
|
||||
// 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) {
|
||||
CLI_valid = true;
|
||||
CLI_validate_text = "";
|
||||
if (!CONFIGURATOR.cliValid && this.validateText.indexOf('CLI') != -1) {
|
||||
CONFIGURATOR.cliValid = true;
|
||||
this.validateText = "";
|
||||
|
||||
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
|
||||
$('.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';
|
||||
|
||||
var MSP_pass_through = false;
|
||||
|
||||
tabs.logging = {};
|
||||
tabs.logging.initialize = function(callback) {
|
||||
GUI.active_tab_ref = this;
|
||||
|
@ -10,7 +8,7 @@ tabs.logging.initialize = function(callback) {
|
|||
|
||||
var requested_properties = [];
|
||||
|
||||
if (configuration_received) {
|
||||
if (CONFIGURATOR.connectionValid) {
|
||||
MSP.send_message(MSP_codes.MSP_RC, false, false, get_motor_data);
|
||||
|
||||
var get_motor_data = function () {
|
||||
|
@ -21,7 +19,7 @@ tabs.logging.initialize = function(callback) {
|
|||
$('#content').load("./tabs/logging.html", process_html);
|
||||
}
|
||||
} else {
|
||||
MSP_pass_through = true;
|
||||
CONFIGURATOR.mspPassThrough = true;
|
||||
|
||||
// we will initialize RC.channels array and MOTOR_DATA array manually
|
||||
RC.active_channels = 8;
|
||||
|
@ -70,7 +68,7 @@ tabs.logging.initialize = function(callback) {
|
|||
}
|
||||
|
||||
// request new
|
||||
if (!MSP_pass_through) {
|
||||
if (!CONFIGURATOR.mspPassThrough) {
|
||||
for (var i = 0; i < requested_properties.length; i++, requests++) {
|
||||
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').click(function() {
|
||||
|
@ -121,7 +119,7 @@ tabs.logging.initialize = function(callback) {
|
|||
$('a.connect').click();
|
||||
} else {
|
||||
GUI.tab_switch_cleanup(function() {
|
||||
MSP_pass_through = false;
|
||||
CONFIGURATOR.mspPassThrough = false;
|
||||
$('#tabs > ul li').removeClass('active');
|
||||
tabs.default.initialize();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue