RTL00_WEB/ExampleHTM/dygraph/ws_test_ina219.html

69 lines
1.8 KiB
HTML
Raw Normal View History

2017-06-21 00:00:20 +00:00
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="dygraph.css">
<title>Get data INA219</title>
2017-10-17 14:42:32 +00:00
<script type="text/javascript" src="dygraph.min.js"></script>
2017-06-21 00:00:20 +00:00
</head>
<body>
2017-10-17 14:42:32 +00:00
<h3 style="width:1000px; text-align: center;">Read regs U & I INA219</h3>
<div id="div_v" style="width:1000px; height:400px;"></div>
2017-06-21 00:00:20 +00:00
<script type="text/javascript">
2017-07-01 01:16:36 +00:00
var datau = [];
//var datai = [];
var gu = new Dygraph(
document.getElementById("div_v"),
datau,
2017-06-21 00:00:20 +00:00
{
2017-07-01 01:16:36 +00:00
labels: ['X', 'I', 'U'],
// drawPoints: true,
2017-10-18 21:34:22 +00:00
// rollPeriod: 10,
2017-07-01 01:16:36 +00:00
// errorBars: true,
// showRoller: true,
ylabel: 'I(mA)',
2017-10-17 14:42:32 +00:00
y2label: 'U(mV)',
2017-07-01 01:16:36 +00:00
series : {
'U': { axis: 'y2' }
}
2017-12-12 20:34:32 +00:00
// , axes: { y2: {valueRange: [3000, 3500] }}
2017-10-17 14:42:32 +00:00
// , axes: { y2: {valueRange: [3000, 3500] }, y: {valueRange: [0, 2] }}
2017-07-01 01:16:36 +00:00
});
2017-06-21 00:00:20 +00:00
var oldblkid = 0;
var rdnextflg = false;
var cur_idx = 0;
2017-07-01 01:16:36 +00:00
var sig = 10;
2017-10-17 14:42:32 +00:00
var ttout = 100;
2017-12-12 20:34:32 +00:00
var wstt;
2017-10-17 14:42:32 +00:00
function wsping() { ws.send('ina219'); wstt = setTimeout(wsping, ttout);};
2017-06-21 00:00:20 +00:00
ws = new WebSocket('ws://rtl871x0/web.cgi');
ws.binaryType = 'arraybuffer';
2017-10-17 14:42:32 +00:00
ws.onopen = function(){ws.send('user=rtl871x:supervisor'); ws.send('sys_debug=0'); wstt = setTimeout(wsping, ttout)};
2017-06-21 00:00:20 +00:00
ws.onmessage = function (event) {
if(event.data instanceof ArrayBuffer) {
2017-10-17 14:42:32 +00:00
clearTimeout(wstt);
2017-06-21 00:00:20 +00:00
var wordarray = new Int16Array(event.data);
if(wordarray.length > 2) {
var blksz = wordarray[0];
if(wordarray.length == blksz*2 + 2) {
var blkid = wordarray[1] & 0xFFFF;
if(rdnextflg) {
cur_idx += (blkid - oldblkid) & 0xFFFF;
} else rdnextflg = true;
oldblkid = blkid + blksz;
for (var i=2; i<wordarray.length; i+=2) {
2017-10-17 14:42:32 +00:00
if(cur_idx > 50000 ) datau.shift();
datau.push([cur_idx, wordarray[i+1]*0.1+0.35, wordarray[i]*0.5 ]);
2017-06-21 00:00:20 +00:00
cur_idx++;
}
2017-07-01 01:16:36 +00:00
gu.updateOptions({'file':datau});
2017-06-21 00:00:20 +00:00
}
}
2017-10-17 14:42:32 +00:00
wstt = setTimeout(wsping, ttout);
2017-06-21 00:00:20 +00:00
}
}
</script>
</body>
</html>