mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
turning on strict mode for various js files
This commit is contained in:
parent
01769559cc
commit
d9c315338d
12 changed files with 140 additions and 98 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function configuration_backup() {
|
function configuration_backup() {
|
||||||
// request configuration data (one by one)
|
// request configuration data (one by one)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var firmware_version_accepted = 2.3;
|
var firmware_version_accepted = 2.3;
|
||||||
|
|
||||||
var CONFIG = {
|
var CONFIG = {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var tabs = {}; // filled by individual tab js file
|
var tabs = {}; // filled by individual tab js file
|
||||||
|
|
||||||
var GUI_control = function() {
|
var GUI_control = function() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function localize() {
|
function localize() {
|
||||||
var localized = 0;
|
var localized = 0;
|
||||||
|
|
||||||
|
|
11
js/msp.js
11
js/msp.js
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
// MSP_codes needs to be re-integrated inside MSP object
|
// MSP_codes needs to be re-integrated inside MSP object
|
||||||
var MSP_codes = {
|
var MSP_codes = {
|
||||||
MSP_IDENT: 100,
|
MSP_IDENT: 100,
|
||||||
|
@ -55,7 +57,7 @@ var MSP_codes = {
|
||||||
|
|
||||||
var MSP = {
|
var MSP = {
|
||||||
state: 0,
|
state: 0,
|
||||||
message_status: 1,
|
message_direction: 1,
|
||||||
code: 0,
|
code: 0,
|
||||||
message_length_expected: 0,
|
message_length_expected: 0,
|
||||||
message_length_received: 0,
|
message_length_received: 0,
|
||||||
|
@ -101,9 +103,9 @@ MSP.read = function(readInfo) {
|
||||||
break;
|
break;
|
||||||
case 2: // direction (should be >)
|
case 2: // direction (should be >)
|
||||||
if (data[i] == 62) { // >
|
if (data[i] == 62) { // >
|
||||||
message_status = 1;
|
this.message_direction = 1;
|
||||||
} else { // unknown
|
} else { // <
|
||||||
message_status = 0;
|
this.message_direction = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state++;
|
this.state++;
|
||||||
|
@ -158,6 +160,7 @@ MSP.read = function(readInfo) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MSP.process_data = function(code, message_buffer, message_length) {
|
MSP.process_data = function(code, message_buffer, message_length) {
|
||||||
|
'use strict';
|
||||||
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function port_handler() {
|
function port_handler() {
|
||||||
this.main_timeout_reference;
|
this.main_timeout_reference;
|
||||||
this.initial_ports = false;
|
this.initial_ports = false;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var PortUsage = {
|
var PortUsage = {
|
||||||
previous_received: 0,
|
previous_received: 0,
|
||||||
previous_sent: 0,
|
previous_sent: 0,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
function request_delay_balancer(refresh_period) {
|
function request_delay_balancer(refresh_period) {
|
||||||
this.balance_to = refresh_period;
|
this.balance_to = refresh_period;
|
||||||
this.request_t = 0;
|
this.request_t = 0;
|
||||||
|
|
16
js/serial.js
16
js/serial.js
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var serial = {
|
var serial = {
|
||||||
connectionId: -1,
|
connectionId: -1,
|
||||||
bitrate: 0,
|
bitrate: 0,
|
||||||
|
@ -25,10 +27,6 @@ var serial = {
|
||||||
console.error(info);
|
console.error(info);
|
||||||
googleAnalytics.sendException('Serial: ' + info.error, false);
|
googleAnalytics.sendException('Serial: ' + info.error, false);
|
||||||
|
|
||||||
switch (info.error) {
|
|
||||||
case 'system_error': // we might be able to recover from this one
|
|
||||||
chrome.serial.setPaused(self.connectionId, false, get_status);
|
|
||||||
|
|
||||||
function get_status() {
|
function get_status() {
|
||||||
self.getInfo(crunch_status);
|
self.getInfo(crunch_status);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +47,10 @@ var serial = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (info.error) {
|
||||||
|
case 'system_error': // we might be able to recover from this one
|
||||||
|
chrome.serial.setPaused(self.connectionId, false, get_status);
|
||||||
break;
|
break;
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -125,9 +127,6 @@ var serial = {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.output_buffer.push({'data': data, 'callback': callback});
|
self.output_buffer.push({'data': data, 'callback': callback});
|
||||||
|
|
||||||
if (!self.transmitting) {
|
|
||||||
self.transmitting = true;
|
|
||||||
|
|
||||||
function sending() {
|
function sending() {
|
||||||
// store inside separate variables in case array gets destroyed
|
// store inside separate variables in case array gets destroyed
|
||||||
var data = self.output_buffer[0].data;
|
var data = self.output_buffer[0].data;
|
||||||
|
@ -152,6 +151,9 @@ var serial = {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!self.transmitting) {
|
||||||
|
self.transmitting = true;
|
||||||
|
|
||||||
sending();
|
sending();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var configuration_received = false;
|
var configuration_received = false;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
@ -44,7 +46,7 @@ $(document).ready(function() {
|
||||||
$(this).text(chrome.i18n.getMessage('connect'));
|
$(this).text(chrome.i18n.getMessage('connect'));
|
||||||
$(this).removeClass('active');
|
$(this).removeClass('active');
|
||||||
|
|
||||||
sensor_status(sensors_detected = 0); // reset active sensor indicators
|
sensor_status(0); // reset active sensor indicators
|
||||||
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
$('#tabs > ul li').removeClass('active'); // de-select any selected tabs
|
||||||
|
|
||||||
// detach listeners and remove element data
|
// detach listeners and remove element data
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var usbDevices = {
|
var usbDevices = {
|
||||||
STM32DFU: {'vendorId': 1155, 'productId': 57105}
|
STM32DFU: {'vendorId': 1155, 'productId': 57105}
|
||||||
};
|
};
|
||||||
|
@ -27,6 +29,8 @@ function check_usb_permissions(callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) callback();
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
63
main.js
63
main.js
|
@ -1,5 +1,8 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
// Get access to the background window object
|
// Get access to the background window object
|
||||||
// This object is used to pass variables between active page and background page
|
// This object is used to pass variables between active page and background page
|
||||||
|
var backgroundPage;
|
||||||
chrome.runtime.getBackgroundPage(function (result) {
|
chrome.runtime.getBackgroundPage(function (result) {
|
||||||
backgroundPage = result;
|
backgroundPage = result;
|
||||||
backgroundPage.app_window = window;
|
backgroundPage.app_window = window;
|
||||||
|
@ -12,6 +15,7 @@ var googleAnalyticsConfig = false;
|
||||||
googleAnalyticsService.getConfig().addCallback(function (config) {
|
googleAnalyticsService.getConfig().addCallback(function (config) {
|
||||||
googleAnalyticsConfig = config;
|
googleAnalyticsConfig = config;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
googleAnalytics.sendAppView('Application Started');
|
googleAnalytics.sendAppView('Application Started');
|
||||||
|
|
||||||
|
@ -42,9 +46,8 @@ $(document).ready(function() {
|
||||||
var ui_tabs = $('#tabs > ul');
|
var ui_tabs = $('#tabs > ul');
|
||||||
$('a', ui_tabs).click(function () {
|
$('a', ui_tabs).click(function () {
|
||||||
if ($(this).parent().hasClass('active') == false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active
|
if ($(this).parent().hasClass('active') == false && !GUI.tab_switch_in_progress) { // only initialize when the tab isn't already active
|
||||||
var self = this;
|
var self = this,
|
||||||
var index = $(self).parent().index();
|
tab = $(self).parent().prop('class');
|
||||||
var 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 (!configuration_received && tab != 'tab_logging') {
|
||||||
|
@ -68,6 +71,10 @@ $(document).ready(function() {
|
||||||
// display loading screen
|
// display loading screen
|
||||||
$('#cache .data-loading').clone().appendTo(content);
|
$('#cache .data-loading').clone().appendTo(content);
|
||||||
|
|
||||||
|
function content_ready() {
|
||||||
|
GUI.tab_switch_in_progress = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (tab) {
|
switch (tab) {
|
||||||
case 'tab_initial_setup':
|
case 'tab_initial_setup':
|
||||||
tabs.initial_setup.initialize(content_ready);
|
tabs.initial_setup.initialize(content_ready);
|
||||||
|
@ -100,10 +107,6 @@ $(document).ready(function() {
|
||||||
tabs.logging.initialize(content_ready);
|
tabs.logging.initialize(content_ready);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
function content_ready() {
|
|
||||||
GUI.tab_switch_in_progress = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -126,7 +129,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// if notifications are enabled, or wasn't set, check the notifications checkbox
|
// if notifications are enabled, or wasn't set, check the notifications checkbox
|
||||||
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) {
|
if (result.update_notify === 'undefined' || result.update_notify) {
|
||||||
$('div.notifications input').prop('checked', true);
|
$('div.notifications input').prop('checked', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -167,8 +170,8 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// listen to all input change events and adjust the value within limits if necessary
|
// listen to all input change events and adjust the value within limits if necessary
|
||||||
$("#content").on('focus', 'input[type="number"]', function () {
|
$("#content").on('focus', 'input[type="number"]', function () {
|
||||||
var element = $(this);
|
var element = $(this),
|
||||||
var val = element.val();
|
val = element.val();
|
||||||
|
|
||||||
if (!isNaN(val)) {
|
if (!isNaN(val)) {
|
||||||
element.data('previousValue', parseFloat(val));
|
element.data('previousValue', parseFloat(val));
|
||||||
|
@ -185,24 +188,31 @@ $(document).ready(function() {
|
||||||
37, 38, 39, 40, 13 // arrows and enter
|
37, 38, 39, 40, 13 // arrows and enter
|
||||||
];
|
];
|
||||||
|
|
||||||
if (whitelist.indexOf(e.keyCode) == -1) e.preventDefault();
|
if (whitelist.indexOf(e.keyCode) == -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#content").on('change', 'input[type="number"]', function () {
|
$("#content").on('change', 'input[type="number"]', function () {
|
||||||
var element = $(this);
|
var element = $(this),
|
||||||
var min = parseFloat(element.prop('min'));
|
min = parseFloat(element.prop('min')),
|
||||||
var max = parseFloat(element.prop('max'));
|
max = parseFloat(element.prop('max')),
|
||||||
var step = parseFloat(element.prop('step'));
|
step = parseFloat(element.prop('step')),
|
||||||
var val = parseFloat(element.val());
|
val = parseFloat(element.val()),
|
||||||
|
decimal_places;
|
||||||
|
|
||||||
// only adjust minimal end if bound is set
|
// only adjust minimal end if bound is set
|
||||||
if (element.prop('min')) {
|
if (element.prop('min')) {
|
||||||
if (val < min) element.val(min);
|
if (val < min) {
|
||||||
|
element.val(min);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// only adjust maximal end if bound is set
|
// only adjust maximal end if bound is set
|
||||||
if (element.prop('max')) {
|
if (element.prop('max')) {
|
||||||
if (val > max) element.val(max);
|
if (val > max) {
|
||||||
|
element.val(max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if entered value is illegal use previous value instead
|
// if entered value is illegal use previous value instead
|
||||||
|
@ -219,7 +229,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
// if step is set and is float and value is int, convert to float, keep decimal places in float according to step *experimental*
|
// if step is set and is float and value is int, convert to float, keep decimal places in float according to step *experimental*
|
||||||
if (!isNaN(step) && step % 1 !== 0) {
|
if (!isNaN(step) && step % 1 !== 0) {
|
||||||
var decimal_places = String(step).split('.')[1].length;
|
decimal_places = String(step).split('.')[1].length;
|
||||||
|
|
||||||
if (val % 1 === 0) {
|
if (val % 1 === 0) {
|
||||||
element.val(val.toFixed(decimal_places));
|
element.val(val.toFixed(decimal_places));
|
||||||
|
@ -243,10 +253,17 @@ function millitime() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bytesToSize(bytes) {
|
function bytesToSize(bytes) {
|
||||||
if (bytes < 1024) return bytes + ' Bytes';
|
if (bytes < 1024) {
|
||||||
else if (bytes < 1048576) return(bytes / 1024).toFixed(3) + ' KB';
|
bytes = bytes + ' Bytes';
|
||||||
else if (bytes < 1073741824) return(bytes / 1048576).toFixed(3) + ' MB';
|
} else if (bytes < 1048576) {
|
||||||
else return (bytes / 1073741824).toFixed(3) + ' GB';
|
bytes = (bytes / 1024).toFixed(3) + ' KB';
|
||||||
|
} else if (bytes < 1073741824) {
|
||||||
|
bytes = (bytes / 1048576).toFixed(3) + ' MB';
|
||||||
|
} else {
|
||||||
|
bytes = (bytes / 1073741824).toFixed(3) + ' GB';
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue