Skip to content

Commit 69ab127

Browse files
Seekbar more metrics (#635)
* Added selection of different values for the seekBar * fix by tbolin * fixed my js to let * typo * slowly getting rid of smells * more de-smelling * I feel dirty * getting closer * moved selector into the seekbar (like its done in the spectrum plots)
1 parent 0e9f299 commit 69ab127

File tree

5 files changed

+116
-15
lines changed

5 files changed

+116
-15
lines changed

css/main.css

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ html.has-analyser-fullscreen.has-analyser .analyser input:not(.onlyFullScreenExc
537537
display:block;
538538
}
539539

540-
#analyser {
540+
#analyser ,#log-seek-bar {
541541
z-index: 10;
542542
}
543543

@@ -647,10 +647,42 @@ html.has-analyser-fullscreen.has-analyser .analyser input:not(.onlyFullScreenExc
647647
position: absolute;
648648
}
649649

650-
.analyser, .map-container {
650+
.analyser, .map-container, .log-seek-bar {
651651
position: absolute;
652652
}
653653

654+
#log-seek-bar {
655+
width: 100%;
656+
}
657+
658+
.log-seek-bar:hover .non-shift #seekbarTypeSelect {
659+
opacity: 1;
660+
height: auto;
661+
transition: opacity 500ms ease-in;
662+
}
663+
664+
#seekbarToolbar {
665+
position: absolute;
666+
top: 8px;
667+
left: 20px;
668+
}
669+
.log-seek-bar #seekbarTypeSelect {
670+
color: #bbb;
671+
height: 0;
672+
overflow: hidden;
673+
opacity: 0;
674+
left: 5px;
675+
float: left;
676+
z-index: 9;
677+
position: absolute;
678+
font-size: 9px;
679+
}
680+
681+
.log-seek-bar #seekbarTypeSelect select {
682+
border-radius: 3px;
683+
padding: 0px 5px;
684+
}
685+
654686
.log-graph video {
655687
position:absolute;
656688
top:0;

index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,12 @@ <h4>Field values</h4>
571571
</div>
572572
</div>
573573
<!-- Log Scroll bar -->
574-
<div class="log-seek-bar">
574+
<div id="log-seek-bar" class="log-seek-bar">
575575
<canvas width="200" height="100"></canvas>
576+
<span id="seekbarToolbar" class="non-shift">
577+
<div id="seekbarType" class="seekBar-selection" data-toggle="tooltip" title="Vaue to plot">
578+
</div>
579+
</span>
576580
</div>
577581
<!-- Status Bar -->
578582
<div id="status-bar">

js/flightlog.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ function FlightLog(logData) {
141141
return {
142142
times: directory.times,
143143
avgThrottle: directory.avgThrottle,
144+
maxMotorDiff: directory.maxMotorDiff,
145+
maxRC: directory.maxRC,
144146
hasEvent: directory.hasEvent
145147
};
146148
};

js/flightlog_index.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function FlightLogIndex(logData) {
4343
times: [],
4444
offsets: [],
4545
avgThrottle: [],
46+
maxRC: [],
47+
maxMotorDiff: [],
4648
initialIMU: [],
4749
initialSlow: [],
4850
initialGPSHome: [],
@@ -57,8 +59,12 @@ function FlightLogIndex(logData) {
5759

5860
iframeCount = 0,
5961
motorFields = [],
62+
maxRCFields = [],
6063
matches,
6164
throttleTotal,
65+
rcTotal,
66+
maxMotor,
67+
minMotor,
6268
eventInThisChunk = null,
6369
parsedHeader,
6470
sawEndMarker = false;
@@ -88,11 +94,19 @@ function FlightLogIndex(logData) {
8894
lastGPS = [];
8995

9096
// Identify motor fields so they can be used to show the activity summary bar
91-
for (var j = 0; j < 8; j++) {
97+
for (let j = 0; j < 8; j++) {
9298
if (mainFrameDef.nameToIndex["motor[" + j + "]"] !== undefined) {
9399
motorFields.push(mainFrameDef.nameToIndex["motor[" + j + "]"]);
94100
}
95101
}
102+
103+
for (let j = 0; j < 3; j++) {
104+
if (mainFrameDef.nameToIndex["rcCommand[" + j + "]"] !== undefined) {
105+
maxRCFields.push(mainFrameDef.nameToIndex["rcCommand[" + j + "]"]);
106+
} else {
107+
console.log("RCField not found");
108+
}
109+
}
96110

97111
// Do we have mag fields? If not mark that data as absent
98112
if (magADC[0] === undefined) {
@@ -127,12 +141,25 @@ function FlightLogIndex(logData) {
127141

128142
if (motorFields.length) {
129143
throttleTotal = 0;
130-
for (var j = 0; j < motorFields.length; j++) {
131-
throttleTotal += frame[motorFields[j]];
144+
maxMotor = 0;
145+
minMotor = 2000;
146+
for (let mofo of motorFields) {
147+
maxMotor = Math.max(frame[mofo], maxMotor);
148+
minMotor = Math.min(frame[mofo], minMotor);
149+
throttleTotal += frame[mofo];
132150
}
133151

152+
intraIndex.maxMotorDiff.push(maxMotor - minMotor);
134153
intraIndex.avgThrottle.push(Math.round(throttleTotal / motorFields.length));
135154
}
155+
if (maxRCFields.length) {
156+
rcTotal = 0;
157+
for (let rcfo of maxRCFields) {
158+
rcTotal += Math.max(rcTotal,Math.abs(frame[rcfo]));
159+
}
160+
161+
intraIndex.maxRC.push(rcTotal);
162+
}
136163

137164
/* To enable seeking to an arbitrary point in the log without re-reading anything
138165
* that came before, we have to record the initial state of various items which aren't
@@ -234,7 +261,9 @@ function FlightLogIndex(logData) {
234261
offsets: new Array(sourceIndex.offsets.length),
235262
minTime: sourceIndex.minTime,
236263
maxTime: sourceIndex.maxTime,
237-
avgThrottle: new Array(sourceIndex.avgThrottle.length)
264+
avgThrottle: new Array(sourceIndex.avgThrottle.length),
265+
maxRC: new Array(sourceIndex.maxRC.length),
266+
maxMotorDiff: new Array(sourceIndex.maxMotorDiff.length),
238267
};
239268

240269
if (sourceIndex.times.length > 0) {
@@ -257,11 +286,14 @@ function FlightLogIndex(logData) {
257286
}
258287

259288
if (sourceIndex.avgThrottle.length > 0) {
260-
for (j = 0; j < sourceIndex.avgThrottle.length; j++) {
289+
// Assuming that avgThrottle, maxRC and maxMotorDiff Arrays are the same length
290+
// since they are build in the same loop. Just to get rid of a codesmell on Sonarcloud
291+
for (let j = 0; j < sourceIndex.avgThrottle.length; j++) {
261292
resultIndex.avgThrottle[j] = sourceIndex.avgThrottle[j] - 1000;
293+
resultIndex.maxRC[j] = sourceIndex.maxRC[j] * 20 - 1000;
294+
resultIndex.maxMotorDiff[j] = sourceIndex.maxMotorDiff[j] * 20 - 1000;
262295
}
263-
}
264-
296+
}
265297
resultIndexes[i] = resultIndex;
266298
}
267299

js/main.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function BlackboxLogViewer() {
105105
seekBar = new SeekBar(seekBarCanvas),
106106

107107
seekBarRepaintRateLimited = $.throttle(200, $.proxy(seekBar.repaint, seekBar)),
108+
seekBarMode = "avgThrottle",
108109

109110
updateValuesChartRateLimited,
110111

@@ -312,6 +313,36 @@ function BlackboxLogViewer() {
312313
}
313314
}
314315

316+
function renderSeekBarPicker(){
317+
var
318+
seekBarContainer = $(".seekBar-selection"),
319+
seekBarPicker,
320+
seekBarItems = [
321+
["avgThrottle", "Average motor throttle"],
322+
["maxRC", "Maximum stick input"],
323+
["maxMotorDiff", "Maximum motor differential"],
324+
];
325+
seekBarContainer.empty();
326+
seekBarPicker = $('<select id="seekbarTypeSelect", class="seekbarTypeSelect">');
327+
seekBarPicker.change(function() {
328+
let
329+
activity = flightLog.getActivitySummary(),
330+
displayItem = $(this).val();
331+
seekBarMode = displayItem;
332+
seekBar.setActivity(activity.times, activity[displayItem], activity.hasEvent);
333+
seekBar.repaint();
334+
});
335+
for (let item of seekBarItems) {
336+
let option;
337+
option = $("<option></option>");
338+
option.text(item[1]);
339+
option.attr("value", item[0]);
340+
seekBarPicker.append(option);
341+
}
342+
seekBarContainer.append(seekBarPicker);
343+
344+
}
345+
315346
function renderLogFileInfo(file) {
316347
$(".log-filename").text(file.name);
317348

@@ -336,7 +367,7 @@ function BlackboxLogViewer() {
336367
}
337368

338369
for (index = 0; index < logCount; index++) {
339-
var
370+
let
340371
logLabel,
341372
option, holder,
342373
error;
@@ -411,9 +442,8 @@ function BlackboxLogViewer() {
411442

412443
var
413444
activity = flightLog.getActivitySummary();
414-
415-
seekBar.setActivity(activity.times, activity.avgThrottle, activity.hasEvent);
416-
445+
446+
seekBar.setActivity(activity.times, activity[seekBarMode], activity.hasEvent);
417447
seekBar.repaint();
418448

419449
// Add flightLog to map
@@ -708,6 +738,7 @@ function BlackboxLogViewer() {
708738
}
709739

710740
renderLogFileInfo(file);
741+
renderSeekBarPicker();
711742
currentOffsetCache.log = file.name; // store the name of the loaded log file
712743
currentOffsetCache.index = null; // and clear the index
713744

@@ -2092,7 +2123,7 @@ function BlackboxLogViewer() {
20922123
}
20932124
}
20942125
if (fullPath != null) {
2095-
const filename = fullPath.replace(/^.*[\\\/]/, '');
2126+
const filename = fullPath.replace(/^.*[\\/]/, '');
20962127
const file = new File(fullPath, filename);
20972128
loadFiles([file]);
20982129
}

0 commit comments

Comments
 (0)