-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
344 lines (307 loc) · 13.6 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RTD Showcase</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div id="candidates-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Candidates</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<ul id="candidate-sensors" class="nav flex-column"></ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">
<img alt="Brand" src="images/rtdlogo.svg" width="20" height="20">
</a>
</div>
<a href="https://github.com/ganehag/rtd-showcase"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
</div>
</nav>
<div class="container">
<div class="card card-white">
<div class="card-block clearfix">
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="sensors">Sensor</label>
<select id="sensors" class="form-control">
<option value="">*** Resolve RTD ***</option>
</select>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="resistance-input">Resistance (Ohm)</label>
<div class="input-group mb-3">
<input id="resistance-input" class="form-control" type="number" placeholder="Ω">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-set-resistance">Set</button>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="temperature-input">Temperature (°C)</label>
<div class="input-group mb-3">
<input id="temperature-input" class="form-control" type="number" placeholder="°C">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-set-temperature">Set</button>
</div>
</div>
</div>
</div>
</div>
<!--
<div class="row">
<div class="col-sm-12">
<button id="plot-all" class="btn btn-primary">Plot all sensors</button>
</div>
</div>
-->
<div class="col-sm-12" style="margin-top: 2em;">
<div id="flotchart" style="height: 500px;"></div>
</div>
</div>
<div class="card-footer text-muted">
Created by <a href="mailto:[email protected]">Mikael Ganehag Brorsson</a>
</div>
</div>
</div>
<script src="js/underscore-min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.flot.min.js"></script>
<script src="js/jquery.flot.canvas.min.js"></script>
<script src="js/jquery.flot.resize.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/naturalSort.js"></script>
<script src="js/rtd.js"></script>
<script>
$(document).ready(function() {
var app = new RTD();
_.each(app.sensors().sort(naturalSort), function(item) {
var o = $('<option></option');
o.attr('value', item).text(item.toUpperCase().replace(/_/, ' '));
$('#sensors').append(o);
});
$.plot($('#flotchart'), []);
function formatSizeUnits(bytes) {
if (bytes >= 1000000000) {
bytes = (bytes / 1000000000).toFixed(2) + ' GOhm';
} else if (bytes >= 1000000) {
bytes = (bytes / 1000000).toFixed(2) + ' MOhm';
} else if (bytes >= 1000) {
bytes = (bytes / 1000).toFixed(2) + ' kOhm';
} else if (bytes > 1) {
bytes = bytes + ' Ohm';
} else if (bytes == 1) {
bytes = bytes + ' Ohm';
} else {
bytes = '0 Ohm';
}
return bytes;
}
function plotAllSensors(app) {
var series = _.map(app.SENSOR_LIST.input, function(sensor) {
var data = _.map(_.range(-50, 50), function(item) {
return [item, app.t2r(sensor[1], item)];
});
var max = _.max(data, function(item) {
return item[1];
})[1];
var t = {
data: data,
label: sensor[0],
yaxis: max < 300 ? 1 : max < 2000 ? 2 : max < 20e4 ? 3 : max < 5e6 ? 4 : 5
};
return t;
});
$.plot($('#flotchart'), series, {
yaxes: [{
min: 0
},
{
position: "right",
min: 0
},
{
min: 0
},
{
position: "right",
min: 0
},
{
min: 0
},
],
legend: {
show: false
},
shadowSize: 0,
yaxis: {
tickFormatter: function(item) {
return formatSizeUnits(item)
}
}
});
}
function findCandidateSensors(app) {
var inp_r = parseFloat($('#resistance-input').val()),
inp_t = parseFloat($('#temperature-input').val());
var candidates = _.sortBy(_.map(app.SENSOR_LIST, function(item, key) {
var t = app.r2t(key, inp_r);
return {
title: key,
delta: Math.abs(t - inp_t)
};
}), function(item) {
return item.delta;
});
if (candidates.length) {
var rangeVal = candidates[0].delta * 2 + 0.1;
candidates = _.filter(candidates, function(item) {
return item.delta <= rangeVal;
});
}
return candidates;
}
function getSelectedSensor() {
var selected_sensor = $('#sensors').val();
return _.first(_.filter(app.SENSOR_LIST, function(item, index) {
return index == selected_sensor;
}));
}
function recomputeEverything(app, target) {
var resistance = parseFloat($('#resistance-input').val()),
temperature = parseFloat($('#temperature-input').val()),
selected_sensor = $('#sensors').val(),
out_resistance = -Infinity,
out_temperature = -Infinity;
var job = $('#sensors').val();
if (isNaN(resistance) && isNaN(temperature)) {
return;
}
if ($('#sensors').val() != "") {
if (!isNaN(resistance)) {
out_temperature = app.r2t(job, resistance);
out_resistance = resistance;
}
if (!isNaN(temperature)) {
out_resistance = app.t2r(job, temperature);
out_temperature = temperature;
}
var series = [{
data: _.map(_.range(Math.min(-50, isNaN(temperature) ? 0 : temperature), Math.max(50, isNaN(temperature) ? 0 : temperature)), function(item) {
return [item, app.t2r(job, item)];
}),
label: ''
}, {
data: [
[out_temperature, out_resistance]
],
label: '',
points: {
show: true,
radius: 5
},
color: 'red'
}];
$.plot($('#flotchart'), series, {
yaxis: {
tickFormatter: function(item) {
return formatSizeUnits(item)
}
},
shadowSize: 0
});
switch (target) {
case 'temperature': // Calculate Temperature
if (resistance !== NaN) {
$('#temperature-input').val(out_temperature);
}
break;
case 'resistance': // Calculate Resistance
if (temperature !== NaN) {
$('#resistance-input').val(out_resistance);
}
break;
}
} else {
var cand = findCandidateSensors(app);
if (cand && cand.length) {
$('#candidate-sensors').children().remove();
_.each(cand, function(item) {
$('#candidate-sensors').append($('<li class="nav-item"><a data-sensor="' + item.title + '" href="# style="margin-right: .5em;"><span>' + item.title.toUpperCase().replace(/_/, ' ') + '</span><span class="float-right">(Δ ' + item.delta.toFixed(4) + ')</span>' + '</a></li>'));
});
$('#candidate-sensors a').click(function(e) {
e.preventDefault();
$('#sensors').val($(this).data('sensor'));
$('#candidates-modal').modal('hide');
recomputeEverything(app, 'resistance');
});
$('#candidates-modal').modal('show');
}
}
}
$('#button-set-resistance').click(function(e) {
if($('#sensors').val() != "") {
$('#temperature-input').val('');
}
recomputeEverything(app, 'temperature');
});
$('#resistance-input').keyup(function(e){
if(e.keyCode == 13) {
if($('#sensors').val() != "") {
$('#temperature-input').val('');
}
recomputeEverything(app, 'temperature');
}
});
$('#button-set-temperature').click(function(e) {
if($('#sensors').val() != "") {
$('#resistance-input').val('');
}
recomputeEverything(app, 'resistance');
});
$('#temperature-input').keyup(function(e){
if(e.keyCode == 13) {
if($('#sensors').val() != "") {
$('#resistance-input').val('');
}
recomputeEverything(app, 'resistance');
}
});
$('#sensors').change(function(e) {
recomputeEverything(app, 'resistance');
});
/*
$('#plot-all').click(function(e) {
e.preventDefault();
plotAllSensors(app);
});
*/
});
</script>
</body>
</html>