From f6c78e460e71dbac75a61071c1656e73c00a092b Mon Sep 17 00:00:00 2001 From: VolkerGoeschl Date: Fri, 31 Mar 2023 13:48:48 +0200 Subject: [PATCH 1/9] Added selection of different values for the seekBar --- index.html | 4 ++++ js/flightlog.js | 2 ++ js/flightlog_index.js | 42 ++++++++++++++++++++++++++++++++++++++++-- js/main.js | 40 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 838931b2..ca51fde6 100644 --- a/index.html +++ b/index.html @@ -454,6 +454,10 @@

Log sync

Workspace

+
  • +

    Seekbar mode

    +
    +
  • diff --git a/js/flightlog.js b/js/flightlog.js index 8eef811a..866a4cd8 100644 --- a/js/flightlog.js +++ b/js/flightlog.js @@ -141,6 +141,8 @@ function FlightLog(logData) { return { times: directory.times, avgThrottle: directory.avgThrottle, + maxMotorDiff: directory.maxMotorDiff, + maxRC: directory.maxRC, hasEvent: directory.hasEvent }; }; diff --git a/js/flightlog_index.js b/js/flightlog_index.js index b42f531e..c11b87cc 100644 --- a/js/flightlog_index.js +++ b/js/flightlog_index.js @@ -43,6 +43,8 @@ function FlightLogIndex(logData) { times: [], offsets: [], avgThrottle: [], + maxRC: [], + maxMotorDiff: [], initialIMU: [], initialSlow: [], initialGPSHome: [], @@ -57,8 +59,12 @@ function FlightLogIndex(logData) { iframeCount = 0, motorFields = [], + maxRCFields = [], matches, throttleTotal, + rcTotal, + maxMotor, + minMotor, eventInThisChunk = null, parsedHeader, sawEndMarker = false; @@ -93,6 +99,14 @@ function FlightLogIndex(logData) { motorFields.push(mainFrameDef.nameToIndex["motor[" + j + "]"]); } } + + for (var j = 0; j < 3; j++) { + if (mainFrameDef.nameToIndex["rcCommand[" + j + "]"] !== undefined) { + maxRCFields.push(mainFrameDef.nameToIndex["rcCommand[" + j + "]"]); + } else { + console.log("RCField not found"); + } + } // Do we have mag fields? If not mark that data as absent if (magADC[0] === undefined) { @@ -127,12 +141,25 @@ function FlightLogIndex(logData) { if (motorFields.length) { throttleTotal = 0; + maxMotor = 0; + minMotor = 2000; for (var j = 0; j < motorFields.length; j++) { + maxMotor = Math.max(frame[motorFields[j]], maxMotor); + minMotor = Math.min(frame[motorFields[j]], minMotor); throttleTotal += frame[motorFields[j]]; } + intraIndex.maxMotorDiff.push(maxMotor - minMotor); intraIndex.avgThrottle.push(Math.round(throttleTotal / motorFields.length)); } + if (maxRCFields.length) { + rcTotal = 0; + for (var j = 0; j < maxRCFields.length; j++) { + rcTotal += Math.max(rcTotal,Math.abs(frame[maxRCFields[j]])); + } + + intraIndex.maxRC.push(rcTotal); + } /* To enable seeking to an arbitrary point in the log without re-reading anything * that came before, we have to record the initial state of various items which aren't @@ -234,7 +261,9 @@ function FlightLogIndex(logData) { offsets: new Array(sourceIndex.offsets.length), minTime: sourceIndex.minTime, maxTime: sourceIndex.maxTime, - avgThrottle: new Array(sourceIndex.avgThrottle.length) + avgThrottle: new Array(sourceIndex.avgThrottle.length), + maxRC: new Array(sourceIndex.maxRC.length), + maxMotorDiff: new Array(sourceIndex.maxMotorDiff.length) }; if (sourceIndex.times.length > 0) { @@ -261,7 +290,16 @@ function FlightLogIndex(logData) { resultIndex.avgThrottle[j] = sourceIndex.avgThrottle[j] - 1000; } } - + if (sourceIndex.maxRC.length > 0) { + for (j = 0; j < sourceIndex.maxRC.length; j++) { + resultIndex.maxRC[j] = sourceIndex.maxRC[j] * 20 - 1000; + } + } + if (sourceIndex.maxMotorDiff.length > 0) { + for (j = 0; j < sourceIndex.maxRC.length; j++) { + resultIndex.maxMotorDiff[j] = sourceIndex.maxMotorDiff[j] * 20 - 1000; + } + } resultIndexes[i] = resultIndex; } diff --git a/js/main.js b/js/main.js index e3d489c7..fdabb9ba 100644 --- a/js/main.js +++ b/js/main.js @@ -105,6 +105,7 @@ function BlackboxLogViewer() { seekBar = new SeekBar(seekBarCanvas), seekBarRepaintRateLimited = $.throttle(200, $.proxy(seekBar.repaint, seekBar)), + seekBarMode = "avgThrottle", updateValuesChartRateLimited, @@ -314,6 +315,39 @@ function BlackboxLogViewer() { } } + function renderSeekBarPicker(){ + var + seekBarContainer = $(".seekBar-selection"), + seekBarPicker, + item, + seekBarItems = [ + ["avgThrottle", "Average motor throttle"], + ["maxRC", "Maximum stick input"], + ["maxMotorDiff", "Maximum motor differential"] + ]; + seekBarContainer.empty(); + seekBarPicker = $(''); seekBarPicker.change(function() { - var + let activity = flightLog.getActivitySummary(), displayItem = $(this).val(); seekBarMode = displayItem; @@ -336,9 +335,7 @@ function BlackboxLogViewer() { seekBar.repaint(); }); for (let item = 0; item < seekBarItems.length; item++ ) { - var - logLabel, - option, holder; + var option; option = $(""); option.text(seekBarItems[item][1]); option.attr("value", seekBarItems[item][0]); @@ -372,7 +369,7 @@ function BlackboxLogViewer() { } for (index = 0; index < logCount; index++) { - var + let logLabel, option, holder, error; From 2e6a2469a9f5c3bf55adff4f578403a2bd6c88ff Mon Sep 17 00:00:00 2001 From: VolkerGoeschl Date: Sat, 1 Apr 2023 10:17:28 +0100 Subject: [PATCH 6/9] more de-smelling --- js/flightlog_index.js | 2 +- js/main.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/flightlog_index.js b/js/flightlog_index.js index 312aca14..a0048419 100644 --- a/js/flightlog_index.js +++ b/js/flightlog_index.js @@ -263,7 +263,7 @@ function FlightLogIndex(logData) { maxTime: sourceIndex.maxTime, avgThrottle: new Array(sourceIndex.avgThrottle.length), maxRC: new Array(sourceIndex.maxRC.length), - maxMotorDiff: new Array(sourceIndex.maxMotorDiff.length) + maxMotorDiff: new Array(sourceIndex.maxMotorDiff.length), }; if (sourceIndex.times.length > 0) { diff --git a/js/main.js b/js/main.js index 287f8e1f..15a8b0bd 100644 --- a/js/main.js +++ b/js/main.js @@ -335,7 +335,7 @@ function BlackboxLogViewer() { seekBar.repaint(); }); for (let item = 0; item < seekBarItems.length; item++ ) { - var option; + let option; option = $(""); option.text(seekBarItems[item][1]); option.attr("value", seekBarItems[item][0]); @@ -2125,7 +2125,7 @@ function BlackboxLogViewer() { } } if (fullPath != null) { - const filename = fullPath.replace(/^.*[\\\/]/, ''); + const filename = fullPath.replace(/^.*[\\/]/, ''); const file = new File(fullPath, filename); loadFiles([file]); } From 13d850f0d3d2f54237f8d4a1531315d41343f070 Mon Sep 17 00:00:00 2001 From: VolkerGoeschl Date: Sat, 1 Apr 2023 10:30:42 +0100 Subject: [PATCH 7/9] I feel dirty --- js/flightlog_index.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/js/flightlog_index.js b/js/flightlog_index.js index a0048419..e52e0d5b 100644 --- a/js/flightlog_index.js +++ b/js/flightlog_index.js @@ -286,20 +286,14 @@ function FlightLogIndex(logData) { } if (sourceIndex.avgThrottle.length > 0) { + // Assuming that avgThrottle, maxRC and maxMotorDiff Arrays are the same length + // since they are build in the same loop. Just to get rid of a codesmell on Sonarcloud for (let j = 0; j < sourceIndex.avgThrottle.length; j++) { resultIndex.avgThrottle[j] = sourceIndex.avgThrottle[j] - 1000; - } - } - if (sourceIndex.maxRC.length > 0) { - for (let j = 0; j < sourceIndex.maxRC.length; j++) { resultIndex.maxRC[j] = sourceIndex.maxRC[j] * 20 - 1000; - } - } - if (sourceIndex.maxMotorDiff.length > 0) { - for (let j = 0; j < sourceIndex.maxMotorDiff.length; j++) { resultIndex.maxMotorDiff[j] = sourceIndex.maxMotorDiff[j] * 20 - 1000; } - } + } resultIndexes[i] = resultIndex; } From 00274f120d67abdbea336fd2fe13c48a11912d8a Mon Sep 17 00:00:00 2001 From: VolkerGoeschl Date: Sat, 1 Apr 2023 10:46:30 +0100 Subject: [PATCH 8/9] getting closer --- js/flightlog_index.js | 12 ++++++------ js/main.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/js/flightlog_index.js b/js/flightlog_index.js index e52e0d5b..1287aa5b 100644 --- a/js/flightlog_index.js +++ b/js/flightlog_index.js @@ -143,10 +143,10 @@ function FlightLogIndex(logData) { throttleTotal = 0; maxMotor = 0; minMotor = 2000; - for (let j = 0; j < motorFields.length; j++) { - maxMotor = Math.max(frame[motorFields[j]], maxMotor); - minMotor = Math.min(frame[motorFields[j]], minMotor); - throttleTotal += frame[motorFields[j]]; + for (let mofo of motorFields) { + maxMotor = Math.max(frame[mofo], maxMotor); + minMotor = Math.min(frame[mofo], minMotor); + throttleTotal += frame[mofo]; } intraIndex.maxMotorDiff.push(maxMotor - minMotor); @@ -154,8 +154,8 @@ function FlightLogIndex(logData) { } if (maxRCFields.length) { rcTotal = 0; - for (let j = 0; j < maxRCFields.length; j++) { - rcTotal += Math.max(rcTotal,Math.abs(frame[maxRCFields[j]])); + for (let rcfo of maxRCFields) { + rcTotal += Math.max(rcTotal,Math.abs(frame[rcfo])); } intraIndex.maxRC.push(rcTotal); diff --git a/js/main.js b/js/main.js index 15a8b0bd..7dd571d7 100644 --- a/js/main.js +++ b/js/main.js @@ -322,7 +322,7 @@ function BlackboxLogViewer() { seekBarItems = [ ["avgThrottle", "Average motor throttle"], ["maxRC", "Maximum stick input"], - ["maxMotorDiff", "Maximum motor differential"] + ["maxMotorDiff", "Maximum motor differential"], ]; seekBarContainer.empty(); seekBarPicker = $(''); + seekBarPicker = $('