RTL00_WEB_VS/RTLGDB/WEBFiles/dygraph/ws_test_ina219d.html

65 lines
1.6 KiB
HTML
Raw Normal View History

2017-11-28 19:31:40 +00:00
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="dygraph.css">
<title>Get data INA219</title>
<script type="text/javascript" src="dygraph.js"></script>
</head>
<body>
<h3 style="width:800px; text-align: center;">U & I (INA219)</h3>
<div id="div_v" style="width:800px; height:400px;"></div>
<script type="text/javascript">
var datau = [];
//var datai = [];
var gu = new Dygraph(
document.getElementById("div_v"),
datau,
{
showRangeSelector: true,
labels: ['X', 'U', 'I'],
// drawPoints: true,
rollPeriod: 5,
// errorBars: true,
// showRoller: true,
ylabel: 'U(mV)',
y2label: 'I(mA)',
series : {
'I': { axis: 'y2' }
}
// , axes: { y: {valueRange: [4500, 5500] }, y2: {valueRange: [75, 125] }}
});
var oldblkid = 0;
var rdnextflg = false;
var cur_idx = 0;
var sig = 10;
ws = new WebSocket('ws://rtl871x0/web.cgi');
ws.binaryType = 'arraybuffer';
ws.onopen = function(){ws.send('ina219'); ws.send('pr=0')};
ws.onmessage = function (event) {
if(event.data instanceof ArrayBuffer) {
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) {
if(cur_idx > 50000 ) datau.shift();
datau.push([cur_idx, wordarray[i]*0.5, wordarray[i+1]*0.1]);
cur_idx++;
}
gu.updateOptions({'file':datau});
}
}
ws.send("ina219");
}
}
</script>
</body>
</html>