1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-16 21:05:30 +03:00

Change lexical scope logging and help

This commit is contained in:
Mark Haslinghuis 2020-12-08 18:47:54 +01:00
parent 317f937fd5
commit d2f3860400
3 changed files with 69 additions and 75 deletions

View file

@ -2,8 +2,7 @@
TABS.help = {}; TABS.help = {};
TABS.help.initialize = function (callback) { TABS.help.initialize = function (callback) {
var self = this;
if (GUI.active_tab != 'help') { if (GUI.active_tab != 'help') {
GUI.active_tab = 'help'; GUI.active_tab = 'help';
} }

View file

@ -2,27 +2,26 @@
TABS.logging = {}; TABS.logging = {};
TABS.logging.initialize = function (callback) { TABS.logging.initialize = function (callback) {
var self = this;
if (GUI.active_tab != 'logging') { if (GUI.active_tab != 'logging') {
GUI.active_tab = 'logging'; GUI.active_tab = 'logging';
} }
var requested_properties = [], let requestedProperties = [];
samples = 0, let samples = 0;
requests = 0, let requests = 0;
log_buffer = []; let logBuffer = [];
if (CONFIGURATOR.connectionValid) { if (CONFIGURATOR.connectionValid) {
var get_motor_data = function () { const getMotorData = function () {
MSP.send_message(MSPCodes.MSP_MOTOR, false, false, load_html); MSP.send_message(MSPCodes.MSP_MOTOR, false, false, loadHtml);
} }
var load_html = function () { const loadHtml = function () {
$('#content').load("./tabs/logging.html", process_html); $('#content').load("./tabs/logging.html", process_html);
} }
MSP.send_message(MSPCodes.MSP_RC, false, false, get_motor_data); MSP.send_message(MSPCodes.MSP_RC, false, false, getMotorData);
} }
function process_html() { function process_html() {
@ -35,44 +34,44 @@ TABS.logging.initialize = function (callback) {
$('a.logging').click(function () { $('a.logging').click(function () {
if (GUI.connected_to) { if (GUI.connected_to) {
if (fileEntry != null) { if (fileEntry != null) {
var clicks = $(this).data('clicks'); const clicks = $(this).data('clicks');
if (!clicks) { if (!clicks) {
// reset some variables before start // reset some variables before start
samples = 0; samples = 0;
requests = 0; requests = 0;
log_buffer = []; logBuffer = [];
requested_properties = []; requestedProperties = [];
$('.properties input:checked').each(function () { $('.properties input:checked').each(function () {
requested_properties.push($(this).prop('name')); requestedProperties.push($(this).prop('name'));
}); });
if (requested_properties.length) { if (requestedProperties.length) {
// print header for the csv file // print header for the csv file
print_head(); print_head();
var log_data_poll = function () { const logDataPoll = function () {
if (requests) { if (requests) {
// save current data (only after everything is initialized) // save current data (only after everything is initialized)
crunch_data(); crunch_data();
} }
// request new // request new
for (var i = 0; i < requested_properties.length; i++, requests++) { for (let i = 0; i < requestedProperties.length; i++, requests++) {
MSP.send_message(MSPCodes[requested_properties[i]]); MSP.send_message(MSPCodes[requestedProperties[i]]);
} }
} }
GUI.interval_add('log_data_poll', log_data_poll, parseInt($('select.speed').val()), true); // refresh rate goes here GUI.interval_add('log_data_poll', logDataPoll, parseInt($('select.speed').val()), true); // refresh rate goes here
GUI.interval_add('write_data', function write_data() { GUI.interval_add('write_data', function write_data() {
if (log_buffer.length) { // only execute when there is actual data to write if (logBuffer.length) { // only execute when there is actual data to write
if (fileWriter.readyState == 0 || fileWriter.readyState == 2) { if (fileWriter.readyState == 0 || fileWriter.readyState == 2) {
append_to_file(log_buffer.join('\n')); append_to_file(logBuffer.join('\n'));
$('.samples').text(samples += log_buffer.length); $('.samples').text(samples += logBuffer.length);
log_buffer = []; logBuffer = [];
} else { } else {
console.log('IO having trouble keeping up with the data flow'); console.log('IO having trouble keeping up with the data flow');
} }
@ -81,7 +80,7 @@ TABS.logging.initialize = function (callback) {
$('.speed').prop('disabled', true); $('.speed').prop('disabled', true);
$(this).text(i18n.getMessage('loggingStop')); $(this).text(i18n.getMessage('loggingStop'));
$(this).data("clicks", !clicks); $(this).data("clicks", clicks !== true);
} else { } else {
GUI.log(i18n.getMessage('loggingErrorOneProperty')); GUI.log(i18n.getMessage('loggingErrorOneProperty'));
} }
@ -113,10 +112,10 @@ TABS.logging.initialize = function (callback) {
} }
function print_head() { function print_head() {
var head = "timestamp"; let head = "timestamp";
for (var i = 0; i < requested_properties.length; i++) { for (let i = 0; i < requestedProperties.length; i++) {
switch (requested_properties[i]) { switch (requestedProperties[i]) {
case 'MSP_RAW_IMU': case 'MSP_RAW_IMU':
head += ',' + 'gyroscopeX'; head += ',' + 'gyroscopeX';
head += ',' + 'gyroscopeY'; head += ',' + 'gyroscopeY';
@ -154,17 +153,17 @@ TABS.logging.initialize = function (callback) {
head += ',' + 'rssi'; head += ',' + 'rssi';
break; break;
case 'MSP_RC': case 'MSP_RC':
for (var chan = 0; chan < FC.RC.active_channels; chan++) { for (let chan = 0; chan < FC.RC.active_channels; chan++) {
head += ',' + 'RC' + chan; head += ',' + 'RC' + chan;
} }
break; break;
case 'MSP_MOTOR': case 'MSP_MOTOR':
for (var motor = 0; motor < FC.MOTOR_DATA.length; motor++) { for (let motor = 0; motor < FC.MOTOR_DATA.length; motor++) {
head += ',' + 'Motor' + motor; head += ',' + 'Motor' + motor;
} }
break; break;
case 'MSP_DEBUG': case 'MSP_DEBUG':
for (var debug = 0; debug < FC.SENSOR_DATA.debug.length; debug++) { for (let debug = 0; debug < FC.SENSOR_DATA.debug.length; debug++) {
head += ',' + 'Debug' + debug; head += ',' + 'Debug' + debug;
} }
break; break;
@ -175,10 +174,10 @@ TABS.logging.initialize = function (callback) {
} }
function crunch_data() { function crunch_data() {
var sample = millitime(); let sample = millitime();
for (var i = 0; i < requested_properties.length; i++) { for (let i = 0; i < requestedProperties.length; i++) {
switch (requested_properties[i]) { switch (requestedProperties[i]) {
case 'MSP_RAW_IMU': case 'MSP_RAW_IMU':
sample += ',' + FC.SENSOR_DATA.gyroscope; sample += ',' + FC.SENSOR_DATA.gyroscope;
sample += ',' + FC.SENSOR_DATA.accelerometer; sample += ',' + FC.SENSOR_DATA.accelerometer;
@ -208,7 +207,7 @@ TABS.logging.initialize = function (callback) {
sample += ',' + FC.ANALOG.rssi; sample += ',' + FC.ANALOG.rssi;
break; break;
case 'MSP_RC': case 'MSP_RC':
for (var chan = 0; chan < FC.RC.active_channels; chan++) { for (let chan = 0; chan < FC.RC.active_channels; chan++) {
sample += ',' + FC.RC.channels[chan]; sample += ',' + FC.RC.channels[chan];
} }
break; break;
@ -221,21 +220,21 @@ TABS.logging.initialize = function (callback) {
} }
} }
log_buffer.push(sample); logBuffer.push(sample);
} }
// IO related methods // IO related methods
var fileEntry = null, let fileEntry = null;
fileWriter = null; let fileWriter = null;
function prepare_file() { function prepare_file() {
const prefix = 'log';
var prefix = 'log'; const suffix = 'csv';
var suffix = 'csv';
var filename = generateFilename(prefix, suffix); const filename = generateFilename(prefix, suffix);
var accepts = [{ const accepts = [{
description: suffix.toUpperCase() + ' files', extensions: [suffix], description: suffix.toUpperCase() + ' files', extensions: [suffix],
}]; }];

View file

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var let sdcardTimer;
sdcardTimer;
TABS.onboard_logging = { TABS.onboard_logging = {
blockSize: 128, blockSize: 128,
@ -12,9 +11,8 @@ TABS.onboard_logging = {
VCP_BLOCK_SIZE: 4096 VCP_BLOCK_SIZE: 4096
}; };
TABS.onboard_logging.initialize = function (callback) { TABS.onboard_logging.initialize = function (callback) {
var const self = this;
self = this, let saveCancelled, eraseCancelled;
saveCancelled, eraseCancelled;
if (GUI.active_tab !== 'onboard_logging') { if (GUI.active_tab !== 'onboard_logging') {
GUI.active_tab = 'onboard_logging'; GUI.active_tab = 'onboard_logging';
@ -60,9 +58,8 @@ TABS.onboard_logging.initialize = function (callback) {
// translate to user-selected language // translate to user-selected language
i18n.localizePage(); i18n.localizePage();
var const dataflashPresent = FC.DATAFLASH.totalSize > 0;
dataflashPresent = FC.DATAFLASH.totalSize > 0, let blackboxSupport;
blackboxSupport;
/* /*
* Pre-1.11.0 firmware supported DATAFLASH API (on targets with SPI flash) but not the BLACKBOX config API. * Pre-1.11.0 firmware supported DATAFLASH API (on targets with SPI flash) but not the BLACKBOX config API.
@ -98,9 +95,9 @@ TABS.onboard_logging.initialize = function (callback) {
$('.tab-onboard_logging a.save-flash-dismiss').click(dismiss_saving_dialog); $('.tab-onboard_logging a.save-flash-dismiss').click(dismiss_saving_dialog);
} }
var deviceSelect = $(".blackboxDevice select"); const deviceSelect = $(".blackboxDevice select");
var loggingRatesSelect = $(".blackboxRate select"); const loggingRatesSelect = $(".blackboxRate select");
var debugModeSelect = $(".blackboxDebugMode select"); const debugModeSelect = $(".blackboxDebugMode select");
if (FC.BLACKBOX.supported) { if (FC.BLACKBOX.supported) {
$(".tab-onboard_logging a.save-settings").click(function() { $(".tab-onboard_logging a.save-settings").click(function() {
@ -109,7 +106,7 @@ TABS.onboard_logging.initialize = function (callback) {
} else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) { } else if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
FC.BLACKBOX.blackboxPDenom = parseInt(loggingRatesSelect.val(), 10); FC.BLACKBOX.blackboxPDenom = parseInt(loggingRatesSelect.val(), 10);
} else { } else {
var rate = loggingRatesSelect.val().split('/'); const rate = loggingRatesSelect.val().split('/');
FC.BLACKBOX.blackboxRateNum = parseInt(rate[0], 10); FC.BLACKBOX.blackboxRateNum = parseInt(rate[0], 10);
FC.BLACKBOX.blackboxRateDenom = parseInt(rate[1], 10); FC.BLACKBOX.blackboxRateDenom = parseInt(rate[1], 10);
} }
@ -143,7 +140,7 @@ TABS.onboard_logging.initialize = function (callback) {
$('a.onboardLoggingRebootMsc').click(function () { $('a.onboardLoggingRebootMsc').click(function () {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc'); analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'RebootMsc');
var buffer = []; const buffer = [];
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_41)) {
if (GUI.operating_system === "Linux") { if (GUI.operating_system === "Linux") {
// Reboot into MSC using UTC time offset instead of user timezone // Reboot into MSC using UTC time offset instead of user timezone
@ -259,8 +256,8 @@ TABS.onboard_logging.initialize = function (callback) {
for (let i = 0; i < loggingRates.length; i++) { for (let i = 0; i < loggingRates.length; i++) {
var loggingRate = Math.round(pidRate / loggingRates[i].denom); let loggingRate = Math.round(pidRate / loggingRates[i].denom);
var loggingRateUnit = " Hz"; let loggingRateUnit = " Hz";
if (loggingRate !== Infinity) { if (loggingRate !== Infinity) {
if (gcd(loggingRate, 1000) === 1000) { if (gcd(loggingRate, 1000) === 1000) {
loggingRate /= 1000; loggingRate /= 1000;
@ -276,7 +273,7 @@ TABS.onboard_logging.initialize = function (callback) {
} }
function populateDebugModes(debugModeSelect) { function populateDebugModes(debugModeSelect) {
var debugModes = []; let debugModes = [];
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_42)) {
$('.blackboxDebugMode').show(); $('.blackboxDebugMode').show();
@ -384,9 +381,8 @@ TABS.onboard_logging.initialize = function (callback) {
return Math.round(kilobytes) + "kB"; return Math.round(kilobytes) + "kB";
} }
var const megabytes = kilobytes / 1024;
megabytes = kilobytes / 1024, let gigabytes;
gigabytes;
if (megabytes < 900) { if (megabytes < 900) {
return megabytes.toFixed(1) + "MB"; return megabytes.toFixed(1) + "MB";
@ -420,7 +416,7 @@ TABS.onboard_logging.initialize = function (callback) {
} }
function update_html() { function update_html() {
var dataflashPresent = FC.DATAFLASH.totalSize > 0; const dataflashPresent = FC.DATAFLASH.totalSize > 0;
update_bar_width($(".tab-onboard_logging .dataflash-used"), FC.DATAFLASH.usedSize, FC.DATAFLASH.totalSize, i18n.getMessage('dataflashUsedSpace'), false); update_bar_width($(".tab-onboard_logging .dataflash-used"), FC.DATAFLASH.usedSize, FC.DATAFLASH.totalSize, i18n.getMessage('dataflashUsedSpace'), false);
update_bar_width($(".tab-onboard_logging .dataflash-free"), FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize, FC.DATAFLASH.totalSize, i18n.getMessage('dataflashFreeSpace'), false); update_bar_width($(".tab-onboard_logging .dataflash-free"), FC.DATAFLASH.totalSize - FC.DATAFLASH.usedSize, FC.DATAFLASH.totalSize, i18n.getMessage('dataflashFreeSpace'), false);
@ -436,7 +432,7 @@ TABS.onboard_logging.initialize = function (callback) {
.toggleClass("sdcard-ready", FC.SDCARD.state === MSP.SDCARD_STATE_READY); .toggleClass("sdcard-ready", FC.SDCARD.state === MSP.SDCARD_STATE_READY);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) { if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_40)) {
var mscIsReady = dataflashPresent || (FC.SDCARD.state === MSP.SDCARD_STATE_READY); const mscIsReady = dataflashPresent || (FC.SDCARD.state === MSP.SDCARD_STATE_READY);
$(".tab-onboard_logging") $(".tab-onboard_logging")
.toggleClass("msc-not-ready", !mscIsReady); .toggleClass("msc-not-ready", !mscIsReady);
@ -447,7 +443,7 @@ TABS.onboard_logging.initialize = function (callback) {
} }
} }
var loggingStatus let loggingStatus;
switch (FC.SDCARD.state) { switch (FC.SDCARD.state) {
case MSP.SDCARD_STATE_NOT_PRESENT: case MSP.SDCARD_STATE_NOT_PRESENT:
$(".sdcard-status").text(i18n.getMessage('sdcardStatusNoCard')); $(".sdcard-status").text(i18n.getMessage('sdcardStatusNoCard'));
@ -512,7 +508,7 @@ TABS.onboard_logging.initialize = function (callback) {
function mark_saving_dialog_done(startTime, totalBytes, totalBytesCompressed) { function mark_saving_dialog_done(startTime, totalBytes, totalBytesCompressed) {
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SaveDataflash'); analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'SaveDataflash');
var totalTime = (new Date().getTime() - startTime) / 1000; const totalTime = (new Date().getTime() - startTime) / 1000;
console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's (' console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's ('
+ (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.blockSize + '.'); + (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.blockSize + '.');
if (!isNaN(totalBytesCompressed)) { if (!isNaN(totalBytesCompressed)) {
@ -546,11 +542,11 @@ TABS.onboard_logging.initialize = function (callback) {
// Begin by refreshing the occupied size in case it changed while the tab was open // Begin by refreshing the occupied size in case it changed while the tab was open
flash_update_summary(function() { flash_update_summary(function() {
var maxBytes = FC.DATAFLASH.usedSize; const maxBytes = FC.DATAFLASH.usedSize;
prepare_file(function(fileWriter) { prepare_file(function(fileWriter) {
var nextAddress = 0; let nextAddress = 0;
var totalBytesCompressed = 0; let totalBytesCompressed = 0;
show_saving_dialog(); show_saving_dialog();
@ -567,7 +563,7 @@ TABS.onboard_logging.initialize = function (callback) {
$(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100); $(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100);
var blob = new Blob([chunkDataView]); const blob = new Blob([chunkDataView]);
fileWriter.onwriteend = function(e) { fileWriter.onwriteend = function(e) {
if (saveCancelled || nextAddress >= maxBytes) { if (saveCancelled || nextAddress >= maxBytes) {
@ -596,7 +592,7 @@ TABS.onboard_logging.initialize = function (callback) {
} }
} }
var startTime = new Date().getTime(); const startTime = new Date().getTime();
// Fetch the initial block // Fetch the initial block
mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead);
}); });
@ -606,14 +602,14 @@ TABS.onboard_logging.initialize = function (callback) {
function prepare_file(onComplete) { function prepare_file(onComplete) {
var prefix = 'BLACKBOX_LOG'; const prefix = 'BLACKBOX_LOG';
var suffix = 'BBL'; const suffix = 'BBL';
var filename = generateFilename(prefix, suffix); const filename = generateFilename(prefix, suffix);
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename,
accepts: [{description: suffix.toUpperCase() + ' files', extensions: [suffix]}]}, function(fileEntry) { accepts: [{description: suffix.toUpperCase() + ' files', extensions: [suffix]}]}, function(fileEntry) {
var error = chrome.runtime.lastError; const error = chrome.runtime.lastError;
if (error) { if (error) {
console.error(error.message); console.error(error.message);