-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
295 lines (259 loc) · 6.95 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
<html>
<head>
<script src="js/jquery-1.11.1.min.js"></script>
<style>
body {
width: 800px;
height: 480px;
background-color: black;
color: white;
// border: 1px solid green;
margin: 0px;
border: 0px;
padding: 0px;
font-size: 25px;
font-family: arial;
overflow: hidden;
}
canvas {
display:inline-block;
background-color: #444444;
}
#time {
font-size:50px;
text-align:center;
}
#voltage, #current, #temperature {
position:relative;
}
#voltage div {
position:absolute;
right:2px;
top:-6px;
font-size:42px;
text-align:right;
}
#current div {
position:absolute;
right:2px;
top:25%;
font-size:46px;
text-align:right
}
#temperature div {
position:absolute;
right:2px;
top:-6px;
font-size:42px;
text-align:right
}
.spacer {
height:15px;
}
</style>
<script>
var seriesLength = 1000;
var allSeries = {};
// All times measured in seconds since start of page
var startTime = new Date().getTime() / 1000.0;
function now() {
return new Date().getTime() / 1000.0 - startTime;
}
function Series(maxLength) {
this.maxLength = maxLength;
this.times = new Float32Array(new ArrayBuffer(this.maxLength * 4));
this.vals = new Float32Array(new ArrayBuffer(this.maxLength * 4));
this.length = 0;
}
Series.prototype.addSample = function(time,val) {
if (this.length < this.maxLength) {
this.length += 1;
}
for (var i = this.length - 1; i >= 1; i--) {
this.times[i] = this.times[i - 1];
this.vals[i] = this.vals[i - 1];
}
this.times[0] = time;
this.vals[0] = val;
}
function ingestData(data) {
for (var key in data) {
if (key != 'time') {
if (!(key in allSeries)) {
allSeries[key] = new Series(1000);
}
allSeries[key].addSample(data.time - startTime, data[key]);
}
}
redraw();
}
function getData() {
$.ajax({
url: 'http://localhost:8002/get.json',
error: function() {
setTimeout(getData, 1000);
},
success: function(data) {
ingestData(data);
getData();
}
});
}
function drawSeries(canvas, series, settings) {
var width= $(canvas).width();
var height= $(canvas).height();
ctx = canvas.getContext('2d');
ctx.strokeStyle="#ffffff";
var recentWidth = 20;
var recentSeconds = 5;
var nowTime = now();
function projectX(i) {
var foo = width - recentWidth - (nowTime - series.times[i]) * settings.timeScale;
return foo;
}
function projectY(i) {
return (settings.max - series.vals[i]) * height / (settings.max - settings.min);
}
if (series.length > 0 && (nowTime - series.times[0]) < recentSeconds) {
// Draw bar
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(width, projectY(0));
ctx.lineTo(width - recentWidth, projectY(0));
ctx.stroke();
}
ctx.lineWidth = 1;
ctx.beginPath();
var max_line_gap = 2;
for (i = 0; i < series.length; i++) {
if (i == 0 || (series.times[i] - series.times[i - 1]) > max_line_gap) {
ctx.moveTo(projectX(i), projectY(i));
}
ctx.lineTo(projectX(i)+1, projectY(i));
}
ctx.stroke();
}
function drawVoltage() {
var canvas = $('#voltage canvas')[0];
var width= $(canvas).width();
var height= $(canvas).height();
ctx = canvas.getContext('2d');
var settings = {min: 2.3, max: 3.7, timeScale: 1.0};
function projectY(v) {
return (settings.max - v) * height / (settings.max - settings.min);
}
// Draw canvas background
ctx.fillStyle='#660000';
ctx.fillRect(0, projectY(2.5), width, projectY(2.3) - projectY(2.5));
ctx.fillStyle='#666600';
ctx.fillRect(0, projectY(2.7), width, projectY(2.5) - projectY(2.7));
ctx.fillStyle='#006600';
ctx.fillRect(0, projectY(3.6), width, projectY(2.7) - projectY(3.6));
ctx.fillStyle='#660000';
ctx.fillRect(0, projectY(3.7), width, projectY(3.6) - projectY(3.7));
// Draw series
drawSeries(canvas, allSeries['minCellVoltage'], settings);
drawSeries(canvas, allSeries['avgCellVoltage'], settings);
drawSeries(canvas, allSeries['maxCellVoltage'], settings);
// Draw voltage text
$('#voltage div').html(
allSeries['maxCellVoltage'].vals[0].toFixed(2) + 'V<br>' +
allSeries['avgCellVoltage'].vals[0].toFixed(2) + 'V<br>' +
allSeries['minCellVoltage'].vals[0].toFixed(2) + 'V');
}
function drawCurrent() {
var canvas = $('#current canvas')[0];
var width= $(canvas).width();
var height= $(canvas).height();
ctx = canvas.getContext('2d');
var settings = {min: -100, max: 600, timeScale: 1.0};
function projectY(v) {
return (settings.max - v) * height / (settings.max - settings.min);
}
// Draw canvas background
ctx.fillStyle='#666666';
ctx.fillRect(0, projectY(0), width, projectY(-100) - projectY(0));
ctx.fillStyle='#006600';
ctx.fillRect(0, projectY(30), width, projectY(0) - projectY(30));
ctx.fillStyle='#666600';
ctx.fillRect(0, projectY(600), width, projectY(30) - projectY(600));
// Draw series
drawSeries(canvas, allSeries['loadCurrentAmps'], settings);
// Draw text
$('#current div').html(allSeries['loadCurrentAmps'].vals[0].toFixed(0) + 'A');
}
function drawTemperature() {
var canvas = $('#temperature canvas')[0];
var width= $(canvas).width();
var height= $(canvas).height();
ctx = canvas.getContext('2d');
var settings = {min: -20, max: 60, timeScale: 1.0};
function projectY(v) {
return (settings.max - v) * height / (settings.max - settings.min);
}
// Draw canvas background
ctx.fillStyle='#666600';
ctx.fillRect(0, projectY(0), width, projectY(-20) - projectY(0));
ctx.fillStyle='#006600';
ctx.fillRect(0, projectY(45), width, projectY(0) - projectY(45));
ctx.fillStyle='#666600';
ctx.fillRect(0, projectY(55), width, projectY(45) - projectY(55));
ctx.fillStyle='#660000';
ctx.fillRect(0, projectY(60), width, projectY(55) - projectY(60));
// Draw series
drawSeries(canvas, allSeries['minCellBoardTempC'], settings);
drawSeries(canvas, allSeries['avgCellBoardTempC'], settings);
drawSeries(canvas, allSeries['maxCellBoardTempC'], settings);
// Draw text
$('#temperature div').html(
formatTemp(allSeries['maxCellBoardTempC'].vals[0]) + '<br>' +
formatTemp(allSeries['avgCellBoardTempC'].vals[0]) + '<br>' +
formatTemp(allSeries['minCellBoardTempC'].vals[0]));
}
function formatTemp(c) {
return Math.round(c * 9 / 5 + 32) + 'F';
}
function drawTime() {
function pad(number) {
var r = String(number);
if (r.length === 1) {
r = '0' + r;
}
return r;
}
var time = new Date();
$('#time').text(
pad(time.getHours()) + ":" +
pad(time.getMinutes()) + ":" +
pad(time.getSeconds()));
}
function redraw() {
drawTime();
drawVoltage();
drawCurrent();
drawTemperature();
}
function init() {
getData();
}
$(init)
</script>
</head>
<body>
<div id="time">3:00</div>
<div id="voltage" width=100%>
<canvas width=680 height=130></canvas>
<div></div>
</div>
<div class="spacer"></div>
<div id="current" width=100%>
<canvas width=680 height=130></canvas>
<div></div>
</div>
<div class="spacer"></div>
<div id="temperature" width=100%>
<canvas width=680 height=130></canvas>
<div></div>
</div>
</body>
</html>