diff --git a/eventPage.js b/eventPage.js index 85b97414..2d4d7b62 100644 --- a/eventPage.js +++ b/eventPage.js @@ -18,14 +18,14 @@ function start_app() { minWidth: 974, minHeight: 632 } - }, function(createdWindow) { - createdWindow.onClosed.addListener(function() { + }, function (createdWindow) { + createdWindow.onClosed.addListener(function () { // connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference // allowing us to automatically close the port when application shut down // 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) { @@ -53,13 +53,13 @@ function start_app() { bufView[5 + 16] = checksum; - chrome.serial.send(connectionId, bufferOut, function(sendInfo) { - chrome.serial.disconnect(connectionId, function(result) { + chrome.serial.send(connectionId, bufferOut, function (sendInfo) { + chrome.serial.disconnect(connectionId, function (result) { console.log('SERIAL: Connection closed - ' + result); }); }); } else if (connectionId > 0) { - chrome.serial.disconnect(connectionId, function(result) { + chrome.serial.disconnect(connectionId, function (result) { console.log('SERIAL: Connection closed - ' + result); }); } @@ -67,18 +67,18 @@ function start_app() { }); } -chrome.app.runtime.onLaunched.addListener(function() { +chrome.app.runtime.onLaunched.addListener(function () { start_app(); }); -chrome.runtime.onInstalled.addListener(function(details) { +chrome.runtime.onInstalled.addListener(function (details) { if (details.reason == 'update') { var previousVersionArr = details.previousVersion.split('.'); var currentVersionArr = chrome.runtime.getManifest().version.split('.'); // only fire up notification sequence when one of the major version numbers changed if (currentVersionArr[0] != previousVersionArr[0] || currentVersionArr[1] != previousVersionArr[1]) { - chrome.storage.local.get('update_notify', function(result) { + chrome.storage.local.get('update_notify', function (result) { if (typeof result.update_notify === 'undefined' || result.update_notify) { var manifest = chrome.runtime.getManifest(); var options = { @@ -90,7 +90,7 @@ chrome.runtime.onInstalled.addListener(function(details) { buttons: [{'title': chrome.i18n.getMessage('notifications_click_here_to_start_app')}] }; - chrome.notifications.create('baseflight_update', options, function(notificationId) { + chrome.notifications.create('baseflight_update', options, function (notificationId) { // empty }); } @@ -99,7 +99,7 @@ chrome.runtime.onInstalled.addListener(function(details) { } }); -chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex) { +chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) { if (notificationId == 'baseflight_update') { start_app(); } diff --git a/js/backup_restore.js b/js/backup_restore.js index 9c655aa1..72cfaa8a 100644 --- a/js/backup_restore.js +++ b/js/backup_restore.js @@ -47,7 +47,7 @@ function configuration_backup() { var now = d.getUTCFullYear() + '.' + d.getDate() + '.' + (d.getMonth() + 1) + '.' + d.getHours() + '.' + d.getMinutes(); // create or load the file - chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_mw_backup_' + now, accepts: accepts}, function(fileEntry) { + chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_mw_backup_' + now, accepts: accepts}, function (fileEntry) { if (!fileEntry) { console.log('No file selected, backup aborted.'); @@ -57,14 +57,14 @@ function configuration_backup() { chosenFileEntry = fileEntry; // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function(path) { + chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { console.log('Backup file path: ' + path); }); // change file entry from read only to read/write - chrome.fileSystem.getWritableEntry(chosenFileEntry, function(fileEntryWritable) { + chrome.fileSystem.getWritableEntry(chosenFileEntry, function (fileEntryWritable) { // check if file is writable - chrome.fileSystem.isWritableEntry(fileEntryWritable, function(isWritable) { + chrome.fileSystem.isWritableEntry(fileEntryWritable, function (isWritable) { if (isWritable) { chosenFileEntry = fileEntryWritable; @@ -83,13 +83,13 @@ function configuration_backup() { var serialized_config_object = JSON.stringify(configuration); var blob = new Blob([serialized_config_object], {type: 'text/plain'}); // first parameter for Blob needs to be an array - chosenFileEntry.createWriter(function(writer) { + chosenFileEntry.createWriter(function (writer) { writer.onerror = function (e) { console.error(e); }; var truncated = false; - writer.onwriteend = function() { + writer.onwriteend = function () { if (!truncated) { // onwriteend will be fired again when truncation is finished truncated = true; @@ -126,7 +126,7 @@ function configuration_restore() { }]; // load up the file - chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function(fileEntry) { + chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function (fileEntry) { if (!fileEntry) { console.log('No file selected, restore aborted.'); @@ -136,15 +136,15 @@ function configuration_restore() { chosenFileEntry = fileEntry; // echo/console log path specified - chrome.fileSystem.getDisplayPath(chosenFileEntry, function(path) { + chrome.fileSystem.getDisplayPath(chosenFileEntry, function (path) { console.log('Restore file path: ' + path); }); // read contents into variable - chosenFileEntry.file(function(file) { + chosenFileEntry.file(function (file) { var reader = new FileReader(); - reader.onprogress = function(e) { + reader.onprogress = function (e) { if (e.total > 1048576) { // 1 MB // dont allow reading files bigger then 1 MB console.log('File limit (1 MB) exceeded, aborting'); @@ -152,7 +152,7 @@ function configuration_restore() { } }; - reader.onloadend = function(e) { + reader.onloadend = function (e) { if (e.total != 0 && e.total == e.loaded) { console.log('Read SUCCESSFUL'); @@ -295,9 +295,9 @@ function configuration_upload() { buffer_out[21] = 0; // vbatlevel_crit (unused) // Send ove the new MISC - MSP.send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, function() { + MSP.send_message(MSP_codes.MSP_SET_MISC, buffer_out, false, function () { // Save changes to EEPROM - MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function() { + MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () { GUI.log(chrome.i18n.getMessage('eeprom_saved_ok')); }); }); diff --git a/js/data_storage.js b/js/data_storage.js index ffe498aa..aec6aafd 100644 --- a/js/data_storage.js +++ b/js/data_storage.js @@ -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, diff --git a/js/gui.js b/js/gui.js index 311511f0..95e7137a 100644 --- a/js/gui.js +++ b/js/gui.js @@ -2,7 +2,7 @@ var tabs = {}; // filled by individual tab js file -var GUI_control = function() { +var GUI_control = function () { this.auto_connect = false; this.connecting_to = false; this.connected_to = false; @@ -29,7 +29,7 @@ var GUI_control = function() { // 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) { +GUI_control.prototype.interval_add = function (name, code, interval, first) { var data = {'name': name, 'timer': undefined, 'code': code, 'interval': interval, 'fired': 0, 'paused': false}; if (first == true) { @@ -50,7 +50,7 @@ GUI_control.prototype.interval_add = function(name, code, interval, first) { }; // name = string -GUI_control.prototype.interval_remove = function(name) { +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 @@ -65,7 +65,7 @@ GUI_control.prototype.interval_remove = function(name) { }; // name = string -GUI_control.prototype.interval_pause = function(name) { +GUI_control.prototype.interval_pause = 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); @@ -79,7 +79,7 @@ GUI_control.prototype.interval_pause = function(name) { }; // name = string -GUI_control.prototype.interval_resume = function(name) { +GUI_control.prototype.interval_resume = function (name) { for (var i = 0; i < this.interval_array.length; i++) { if (this.interval_array[i].name == name && this.interval_array[i].paused) { var obj = this.interval_array[i]; @@ -101,14 +101,14 @@ GUI_control.prototype.interval_resume = function(name) { // input = array of timers thats meant to be kept, or nothing // return = returns timers killed in last call -GUI_control.prototype.interval_kill_all = function(keep_array) { +GUI_control.prototype.interval_kill_all = function (keep_array) { var self = this; var timers_killed = 0; for (var i = (this.interval_array.length - 1); i >= 0; i--) { // reverse iteration var keep = false; if (keep_array) { // only run through the array if it exists - keep_array.forEach(function(name) { + keep_array.forEach(function (name) { if (self.interval_array[i].name == name) { keep = true; } @@ -130,7 +130,7 @@ GUI_control.prototype.interval_kill_all = function(keep_array) { // name = string // code = function reference (code to be executed) // timeout = timeout in miliseconds -GUI_control.prototype.timeout_add = function(name, code, timeout) { +GUI_control.prototype.timeout_add = function (name, code, timeout) { var self = this; var data = {'name': name, 'timer': undefined, 'timeout': timeout}; @@ -149,7 +149,7 @@ GUI_control.prototype.timeout_add = function(name, code, timeout) { }; // name = string -GUI_control.prototype.timeout_remove = function(name) { +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 @@ -165,7 +165,7 @@ GUI_control.prototype.timeout_remove = function(name) { // no input paremeters // return = returns timers killed in last call -GUI_control.prototype.timeout_kill_all = function() { +GUI_control.prototype.timeout_kill_all = function () { var timers_killed = 0; for (var i = 0; i < this.timeout_array.length; i++) { @@ -180,7 +180,7 @@ GUI_control.prototype.timeout_kill_all = function() { }; // message = string -GUI_control.prototype.log = function(message) { +GUI_control.prototype.log = function (message) { var command_log = $('div#log'); var d = new Date(); var time = ((d.getHours() < 10) ? '0' + d.getHours(): d.getHours()) @@ -194,7 +194,7 @@ GUI_control.prototype.log = function(message) { // 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) { +GUI_control.prototype.tab_switch_cleanup = function (callback) { MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive GUI.interval_kill_all(); // all intervals (mostly data pulling) needs to be removed on tab switch diff --git a/js/serial_backend.js b/js/serial_backend.js index 0a9e3f87..4e66a764 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -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; } diff --git a/main.js b/main.js index 603ccb18..adafd3ba 100644 --- a/main.js +++ b/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 connect before you can view any of the tabs'); return; } @@ -264,113 +264,4 @@ function bytesToSize(bytes) { } return bytes; -} - -/* -function add_custom_spinners() { - var spinner_element = '