-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
378 lines (352 loc) · 17.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=.7" />
<title>piObdDashboard</title>
</head>
<body id="dashboardBody">
<div id="homePage" class="container-fluid">
<script src="/js/jquery.min.js"></script>
<script src="/js/plotly-latest.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/css/bootstrap-theme.min.css" />
<link rel="stylesheet" type="text/css" href="/css/index.css" />
<script src="/js/socket.io.min.js"></script>
<ul class="nav justify-content-start">
<h6 class="nav-item ml-auto">Runtime:</h6>
<h6 class="nav-item ml-auto" id="runTimeField">--</h6>
<h6 class="nav-item ml-auto">Idle:</h6>
<h6 class="nav-item ml-auto" id="idleTimeField">--</h6>
<li class="nav-item ml-auto"><a id="sensorDumpButton" class="nav-link">Sensor Dump</a></li>
<li class="nav-item ml-auto"><a id="homeButton" class="nav-link">Home</a></li>
</ul>
<div class="container-fluid">
<div class="row">
<table class="telemetry-table">
<tbody>
<tr>
<td>
<h4 class="pad-left">MPH</h4>
<h1 class="mph pad-right" id="speedField" onclick="toggleFullScreen(document.body)">--</h1>
</td>
<td>
<table>
<tbody>
<tr>
<td>
<h4>RPM</h4>
</td>
</tr>
<tr>
<td>
<h1 class="rpm rpmCell" id="rpmField">--</h1>
</td>
</tr>
<tr>
<td class="pad-top">
<h3 id="throttleField">--</h3>
</td>
<td class="col-sm-4">
<h3 id="cabinTempField">--</h3>
</td>
<td class="col-sm-4">
<h3 id="cabinHumidityField">--</h3>
</td>
</tr>
<tr>
<td>
<h6>% Throttle</h6>
</td>
<td class="col-sm-4">
<h6 id="cabinTempHeader">Cabin Temp</h6>
</td>
<td class="col-sm-4">
<h6>% Humidity</h6>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="wrapper">
<script></script>
<div id="speedChart"></div>
<script>
function toggleFullScreen(elem) {
// ## The below if statement seems to work better ## if ((document.fullScreenElement && document.fullScreenElement !== null) || (document.msfullscreenElement && document.msfullscreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) {
if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
if (elem.requestFullScreen) {
elem.requestFullScreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullScreen) {
elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
function secondsToHHMMSS(seconds) {
var date = new Date(null);
date.setSeconds(seconds);
return date.toISOString().substr(11, 8);
}
var degreeSymbol = String.fromCharCode(176);
var degreeMetric = "F";
$("#cabinTempHeader").text("Cabin Temp " + degreeSymbol + degreeMetric);
var startTime = new Date($.now());
var x_max = 1000; //max number of data points per plot
var fontSize = 20;
var defaultColor = '#00ba00';
var plotBackgroundColor = '#000000';
var plotHeight = 300;
var plotLeftMargin = 35;
var plotRightMargin = 10;
var plotBottomMargin = 25;
var plotTopMargin = 10;
var padding = 1; //spacing between graph and labels
var numXTicks = 5; //max number of x labels per graph
var tickAngle = 0;
var lineWidth = 1;
var config = { responsive: true }
var graphInterval = 4;
var curInterval = 0;
var speedLayout = {
autosize: true,
height: plotHeight,
margin: {
l: plotLeftMargin,
r: plotRightMargin,
b: plotBottomMargin,
t: plotTopMargin,
pad: padding
},
xaxis: {
<!--tickformat: "%I:%M" -->
tickangle: tickAngle,
nticks: numXTicks,
gridcolor: defaultColor
},
yaxis: {
<!-- rangemode:'tozero' -->
gridcolor: defaultColor
},
font: {
size: fontSize,
color: defaultColor
},
paper_bgcolor: plotBackgroundColor,
plot_bgcolor: plotBackgroundColor
};
Plotly.react('speedChart', [{
x: [startTime],
y: [0],
type: 'line',
line: {
color: defaultColor,
width: lineWidth
},
fill: 'tozeroy'
}], speedLayout, config);
function updateSpeedChart(speed, time) {
var speedingSpeed = 85;
var warningSpeed = 80;
var parsedSpeed = parseInt(speed);
curInterval += 1;
$("#speedField").text(speed);
//update the graphs for every 4 data points.
if (curInterval == graphInterval) {
var speedTrace = {
x: [
[time]
],
y: [
[speed]
]
}
Plotly.extendTraces('speedChart', speedTrace, [0], x_max);
curInterval = 0;
}
}
</script>
</div>
<div class="wrapper">
<div id="rpmChart"></div>
<script>
var rpmGraphInterval = 4;
var rpmCurInterval = 0;
var rpmLayout = {
autosize: true,
height: plotHeight,
margin: {
l: plotLeftMargin,
r: plotRightMargin,
b: plotBottomMargin,
t: plotTopMargin,
pad: padding
},
xaxis: {
<!--tickformat: "%I:%M" -->
tickangle: tickAngle,
nticks: numXTicks,
gridcolor: defaultColor
},
yaxis: {
gridcolor: defaultColor
},
font: {
size: fontSize,
color: defaultColor
},
paper_bgcolor: plotBackgroundColor,
plot_bgcolor: plotBackgroundColor
};
Plotly.react('rpmChart', [{
x: [startTime],
y: [0],
type: 'line',
line: {
color: defaultColor,
width: lineWidth
},
fill: 'tozeroy'
}], rpmLayout, config);
function updateRpmChart(rpm, time) {
var highRpm = 6500;
var mediumRpm = 4000;
var parsedRpm = parseInt(rpm);
$("#rpmField").text(rpm);
if(parsedRpm >= highRpm) {
$("#rpmField").css('color', 'red');
} else if(parsedRpm >= mediumRpm && parsedRpm < highRpm) {
$("#rpmField").css('color', 'yellow');
} else {
$("#rpmField").css('color', defaultColor);
}
rpmCurInterval += 1;
if (rpmCurInterval == rpmGraphInterval) {
var scaledRpm = (rpm / 1000).toFixed(3);
var rpmTrace = {
x: [
[time]
],
y: [
[scaledRpm]
]
}
Plotly.extendTraces('rpmChart', rpmTrace, [0], x_max);
rpmCurInterval = 0;
}
}
</script>
</div>
<script>
function updateRunTimeFields(runTime, idleTime) {
$("#runTimeField").text(secondsToHHMMSS(runTime));
$("#idleTimeField").text(secondsToHHMMSS(Math.round(idleTime)));
}
function updateCabinTempHumidity(temp, humidity) {
$("#cabinTempField").text(temp);
$("#cabinHumidityField").text(humidity);
}
var socket = io();
if (socket != null) {
$("#statusField").text = "Connected";
}
socket.on("data", function (msg) {
var currentTime = new Date($.now());
var carData = $.parseJSON(msg);
var speed = parseInt(carData["speed"]);
var rpm = parseInt(carData["rpm"]);
var throttle = parseInt(carData["throttle"]);
var runTime = parseInt(carData["runTime"]);
var idleTime = parseInt(carData["idleTime"]); //approximation based on update interval defined in obdDash.py
$("#throttleField").text(throttle);
updateRunTimeFields(runTime, idleTime);
updateSpeedChart(speed, currentTime);
updateRpmChart(rpm, currentTime);
});
socket.on("cabinTempHumidity", function (msg) {
var data = $.parseJSON(msg);
var temp = data["temp"];
var humidity = data["humidity"];
updateCabinTempHumidity(temp, humidity);
});
</script>
<div id="dtcContainer" class="container-fluid">
<table id="myTable" class="table" data-toggle="table" data-mobile-responsive="true" data-pagination="true">
<thead>
<tr>
<th>Error Code (DTC)</th>
<th>Description</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
var tbody = $("#myTable").children("tbody");
var table = tbody.length ? tbody : $("#myTable");
//this should only get called when there is a change in DTC(s). That logic
//is handled in piObd.py. We clear the table and add the codes + descriptions
socket.on("dtcData", function (faultCodes) {
table.empty();
for (var i = 0; i < faultCodes.length; i++) {
var codeDescArray = faultCodes[i];
var code = codeDescArray[0];
var description = codeDescArray[1];
table.append("<tr id=" + code + "><td>" + code + "</td><td>" + description + "</td></tr>");
}
});
</script>
</div>
<div hidden id="sensorDumpPage" class="container-fluid">
<div class="container">
<button id="testButton">test</button>
<table id="sensorDumpTable" class="table" data-toggle="table" data-mobile-responsive="true" data-pagination="true">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Response Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
$("#testButton").click(function () {
socket.emit("sensorDumpRequest");
});
var sensorDumpBody = $("#sensorDumpTable").children("tbody");
var sensorDumpTable = sensorDumpBody.length ? sensorDumpBody : $("#sensorDumpTable");
socket.on("sensorDumpData", function (sensorDumpData) {
sensorDumpTable.empty();
console.log(sensorDumpData);
for (var i = 0; i < sensorDumpData.length; i++) {
var entry = sensorDumpData[i];
var name = entry["Name"];
var description = entry["Description"];
var value = entry["Value"];
sensorDumpTable.append("<tr id=" + name + "><td>" + name + "</td><td>" + value + "</td><td>" + description + "</td></tr>");
}
});
</script>
</div>
</body>
</html>