mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +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() {
|
||||
// request configuration data (one by one)
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var firmware_version_accepted = 2.3;
|
||||
|
||||
var CONFIG = {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var tabs = {}; // filled by individual tab js file
|
||||
|
||||
var GUI_control = function() {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
function localize() {
|
||||
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
|
||||
var MSP_codes = {
|
||||
MSP_IDENT: 100,
|
||||
|
@ -55,7 +57,7 @@ var MSP_codes = {
|
|||
|
||||
var MSP = {
|
||||
state: 0,
|
||||
message_status: 1,
|
||||
message_direction: 1,
|
||||
code: 0,
|
||||
message_length_expected: 0,
|
||||
message_length_received: 0,
|
||||
|
@ -101,9 +103,9 @@ MSP.read = function(readInfo) {
|
|||
break;
|
||||
case 2: // direction (should be >)
|
||||
if (data[i] == 62) { // >
|
||||
message_status = 1;
|
||||
} else { // unknown
|
||||
message_status = 0;
|
||||
this.message_direction = 1;
|
||||
} else { // <
|
||||
this.message_direction = 0;
|
||||
}
|
||||
|
||||
this.state++;
|
||||
|
@ -158,6 +160,7 @@ MSP.read = function(readInfo) {
|
|||
};
|
||||
|
||||
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)
|
||||
|
||||
switch (code) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
function port_handler() {
|
||||
this.main_timeout_reference;
|
||||
this.initial_ports = false;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var PortUsage = {
|
||||
previous_received: 0,
|
||||
previous_sent: 0,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
function request_delay_balancer(refresh_period) {
|
||||
this.balance_to = refresh_period;
|
||||
this.request_t = 0;
|
||||
|
|
16
js/serial.js
16
js/serial.js
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var serial = {
|
||||
connectionId: -1,
|
||||
bitrate: 0,
|
||||
|
@ -25,10 +27,6 @@ var serial = {
|
|||
console.error(info);
|
||||
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() {
|
||||
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;
|
||||
case 'timeout':
|
||||
// TODO
|
||||
|
@ -125,9 +127,6 @@ var serial = {
|
|||
var self = this;
|
||||
self.output_buffer.push({'data': data, 'callback': callback});
|
||||
|
||||
if (!self.transmitting) {
|
||||
self.transmitting = true;
|
||||
|
||||
function sending() {
|
||||
// store inside separate variables in case array gets destroyed
|
||||
var data = self.output_buffer[0].data;
|
||||
|
@ -152,6 +151,9 @@ var serial = {
|
|||
});
|
||||
};
|
||||
|
||||
if (!self.transmitting) {
|
||||
self.transmitting = true;
|
||||
|
||||
sending();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var configuration_received = false;
|
||||
|
||||
$(document).ready(function() {
|
||||
|
@ -44,7 +46,7 @@ $(document).ready(function() {
|
|||
$(this).text(chrome.i18n.getMessage('connect'));
|
||||
$(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
|
||||
|
||||
// detach listeners and remove element data
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var usbDevices = {
|
||||
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
|
||||
// This object is used to pass variables between active page and background page
|
||||
var backgroundPage;
|
||||
chrome.runtime.getBackgroundPage(function (result) {
|
||||
backgroundPage = result;
|
||||
backgroundPage.app_window = window;
|
||||
|
@ -12,6 +15,7 @@ var googleAnalyticsConfig = false;
|
|||
googleAnalyticsService.getConfig().addCallback(function (config) {
|
||||
googleAnalyticsConfig = config;
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
googleAnalytics.sendAppView('Application Started');
|
||||
|
||||
|
@ -42,9 +46,8 @@ $(document).ready(function() {
|
|||
var ui_tabs = $('#tabs > ul');
|
||||
$('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
|
||||
var self = this;
|
||||
var index = $(self).parent().index();
|
||||
var tab = $(self).parent().prop('class');
|
||||
var self = this,
|
||||
tab = $(self).parent().prop('class');
|
||||
|
||||
// if there is no active connection, return
|
||||
if (!configuration_received && tab != 'tab_logging') {
|
||||
|
@ -68,6 +71,10 @@ $(document).ready(function() {
|
|||
// display loading screen
|
||||
$('#cache .data-loading').clone().appendTo(content);
|
||||
|
||||
function content_ready() {
|
||||
GUI.tab_switch_in_progress = false;
|
||||
}
|
||||
|
||||
switch (tab) {
|
||||
case 'tab_initial_setup':
|
||||
tabs.initial_setup.initialize(content_ready);
|
||||
|
@ -100,10 +107,6 @@ $(document).ready(function() {
|
|||
tabs.logging.initialize(content_ready);
|
||||
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
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
@ -167,8 +170,8 @@ $(document).ready(function() {
|
|||
|
||||
// listen to all input change events and adjust the value within limits if necessary
|
||||
$("#content").on('focus', 'input[type="number"]', function () {
|
||||
var element = $(this);
|
||||
var val = element.val();
|
||||
var element = $(this),
|
||||
val = element.val();
|
||||
|
||||
if (!isNaN(val)) {
|
||||
element.data('previousValue', parseFloat(val));
|
||||
|
@ -185,24 +188,31 @@ $(document).ready(function() {
|
|||
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 () {
|
||||
var element = $(this);
|
||||
var min = parseFloat(element.prop('min'));
|
||||
var max = parseFloat(element.prop('max'));
|
||||
var step = parseFloat(element.prop('step'));
|
||||
var val = parseFloat(element.val());
|
||||
var element = $(this),
|
||||
min = parseFloat(element.prop('min')),
|
||||
max = parseFloat(element.prop('max')),
|
||||
step = parseFloat(element.prop('step')),
|
||||
val = parseFloat(element.val()),
|
||||
decimal_places;
|
||||
|
||||
// only adjust minimal end if bound is set
|
||||
if (element.prop('min')) {
|
||||
if (val < min) element.val(min);
|
||||
if (val < min) {
|
||||
element.val(min);
|
||||
}
|
||||
}
|
||||
|
||||
// only adjust maximal end if bound is set
|
||||
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
|
||||
|
@ -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 (!isNaN(step) && step % 1 !== 0) {
|
||||
var decimal_places = String(step).split('.')[1].length;
|
||||
decimal_places = String(step).split('.')[1].length;
|
||||
|
||||
if (val % 1 === 0) {
|
||||
element.val(val.toFixed(decimal_places));
|
||||
|
@ -243,10 +253,17 @@ function millitime() {
|
|||
}
|
||||
|
||||
function bytesToSize(bytes) {
|
||||
if (bytes < 1024) return bytes + ' Bytes';
|
||||
else if (bytes < 1048576) return(bytes / 1024).toFixed(3) + ' KB';
|
||||
else if (bytes < 1073741824) return(bytes / 1048576).toFixed(3) + ' MB';
|
||||
else return (bytes / 1073741824).toFixed(3) + ' GB';
|
||||
if (bytes < 1024) {
|
||||
bytes = bytes + ' Bytes';
|
||||
} else if (bytes < 1048576) {
|
||||
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