Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>ECG Monitor</title>
  6. </head>
  7. <body>
  8. <section>
  9. <div id="canvasesdiv" style="position:relative; width:30000px; height:1000px">
  10. <canvas id="layer1"
  11. style="z-index: 1;
  12. position:absolute;
  13. left:0px;
  14. top:0px;
  15. " height="1000px" width="30000px">
  16. This text is displayed if your browser does not support HTML5 Canvas.
  17. </canvas>
  18. <canvas id="layer2"
  19. style="z-index: 2;
  20. position:absolute;
  21. left:0px;
  22. top:0px;
  23. " height="1000px" width="30000px">
  24. This text is displayed if your browser does not support HTML5 Canvas.
  25. </canvas>
  26. <canvas id="layer3"
  27. style="z-index: 3;
  28. position:absolute;
  29. left:0px;
  30. top:0px;
  31. " height="1000px" width="30000px">
  32. This text is displayed if your browser does not support HTML5 Canvas.
  33. </canvas>
  34. </div>
  35. <script type="text/javascript">
  36.  
  37.  
  38.  
  39. var layer1;
  40. var layer2;
  41. var layer3;
  42. var ctx1;
  43. var ctx2;
  44. var ctx3;
  45.  
  46. var x = 30000;
  47. var y = 1000;
  48. var dx = 2;
  49. var dy = 4;
  50. var WIDTH = 30000;
  51. var HEIGHT = 1000;
  52. var city = new Image();
  53.  
  54. var tong= 0.00;
  55.  
  56. var w = 30000,
  57. h = 1000,
  58. speed = 1,
  59. scanBarWidth = 10,
  60. i=0,
  61. //data = EcgData[0].split(','),
  62. color='#000000';
  63. var px = 0;
  64. var opx = 0;
  65. var py = h/2;
  66. var opy = py;
  67.  
  68. function init() {
  69. city.src ="tong30_5.png";
  70. layer1 = document.getElementById("layer1");
  71. ctx1 = layer1.getContext("2d");
  72. layer2 = document.getElementById("layer2");
  73. ctx2 = layer2.getContext("2d");
  74. layer3 = document.getElementById("layer3");
  75. ctx3 = layer3.getContext("2d");
  76. //setInterval(drawAll, 1);
  77.  
  78. ctx3.strokeStyle = color;
  79. ctx3.lineWidth = 2;
  80. ctx3.setTransform(1,0,0,-1,0,h);
  81. }
  82.  
  83. function drawAll() {
  84. draw1();
  85.  
  86. }
  87.  
  88. function draw1() {
  89. ctx1.clearRect(0, 0, WIDTH, HEIGHT);
  90. ctx1.fillStyle = "#FAF7F8";
  91. ctx1.beginPath();
  92. ctx1.rect(0,0,WIDTH,HEIGHT);
  93. ctx1.closePath();
  94. ctx1.fill();
  95. ctx1.fillStyle = "#444444";
  96. ctx1.beginPath();
  97. ctx1.arc(x, y, 10, 0, Math.PI*2, true);
  98. ctx1.closePath();
  99. ctx1.fill();
  100.  
  101. if (x + dx > WIDTH || x + dx < 0)
  102. dx = -dx;
  103. if (y + dy > HEIGHT || y + dy < 0)
  104. dy = -dy;
  105.  
  106. x += dx;
  107. y += dy;
  108. }
  109.  
  110. function draw2() {
  111. ctx2.clearRect(0, 0, 30000, 1000);
  112. ctx2.drawImage(city, 0, 0);
  113. }
  114.  
  115. function draw3() {
  116. drawWave();
  117. }
  118.  
  119.  
  120.  
  121. function drawWave() {
  122. px += speed;
  123. ctx3.clearRect( px,0, scanBarWidth, h);
  124. ctx3.beginPath();
  125. ctx3.moveTo( opx, opy);
  126. ctx3.lineJoin= 'round';
  127. //py=((tong+tong2)/2);
  128. py=(tong2);
  129. ctx3.lineTo(px, py);
  130. ctx3.stroke();
  131. opx = px;
  132. opy = py;
  133. if (opx > w) {px = opx = -speed;}
  134.  
  135.  
  136. //requestAnimationFrame(drawWave);
  137. }
  138.  
  139. let dat
  140. var tong2;
  141. var STNS = 3;
  142. const SerialPort = require('serialport');
  143. let port = new SerialPort('COM5', {
  144. baudRate: 1000000,
  145. parser: SerialPort.parsers.readline('\r\n')
  146. })
  147.  
  148. port.on('data', function (data) {
  149. if(STNS==0){
  150. dat = data;
  151. tong = parseFloat(dat);
  152. tong = tong*200;
  153. STNS =1;
  154. }else if(STNS==1){
  155. dat = data;
  156. tong2 = parseFloat(dat);
  157. tong2 = tong2*200;
  158. //STNS =0;
  159. console.log((tong+tong2)/2);
  160.  
  161. draw3();
  162. }
  163.  
  164. })
  165.  
  166. init();
  167. setInterval(function(){
  168. draw2();
  169. STNS =1;
  170. }, 10000);
  171. </script>
  172. </section>
  173. </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement