-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhrmon.js
executable file
·50 lines (40 loc) · 965 Bytes
/
hrmon.js
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
#!/usr/bin/node
const fs = require('fs');
const blessed = require('blessed');
const contrib = require('blessed-contrib');
const screen = blessed.screen();
const line = contrib.line({
style:
{
line: "green",
text: "yellow",
baseline: "black"
},
xLabelPadding: 3,
xPadding: 5,
showLegend: true,
wholeNumbersOnly: true
});
const data = {
title: "Heart Rate",
x: [0],
y: [0]
};
screen.append(line);
line.setData([data]);
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
return process.exit(0);
});
const fd = fs.openSync('/dev/hr', 'r');
function readHeartRate() {
fs.read(fd, Buffer.alloc(1), 0, 1, 0,
(err, bytesRead, buffer) => {
const heart_rate = buffer.readUInt8(0);
data.x.push(1);
data.y.push(heart_rate);
line.setData([data]);
screen.render();
});
}
readHeartRate();
setInterval(readHeartRate, 500);