-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
116 lines (98 loc) · 1.77 KB
/
index.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
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
let device = require('./device');
let blessed = require('blessed');
let screen = blessed.screen({
smartCSR: true
});
screen.title = 'OpenPrepPad';
let container = blessed.box({
top: 'center',
left: 'center',
width: 50,
height: 17,
border: {
type: 'line'
},
style: {
bg: 'cyan-bg'
}
})
let box = blessed.BigText({
top: 0,
right: 0,
width: 'shrink',
height: 'shrink',
tags: true,
style: {
fg: 'white'
}
});
container.append(box);
screen.append(container);
let statusLine = blessed.Text({
bottom: 0,
width: '100%',
height: 'shrink',
content: 'Connecting...',
style: {
fg: 'white',
bg: 'blue'
}
});
screen.append(statusLine);
let helpBox = blessed.box({
top: 0,
left: 0,
width: 'shrink',
height: 'shrink',
content: 'q - Quit\nz - Zero/Tare'
});
screen.append(helpBox);
let dataTable = blessed.Table({
bottom: 1,
right: 0,
width: 19,
height: 'shrink',
border: {
type: 'line'
},
data: [
[ 'Accel', 'Value' ],
[ 'X', '-1' ],
[ 'Y', '-1' ],
[ 'Z', '-1' ]
]
});
screen.append(dataTable);
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
process.exit(0);
});
screen.key(['z'], function(ch, key) {
device.button$.onNext('');
});
// Focus our element.
box.focus();
// Render the screen.
screen.render();
device.weight$.subscribe(w => {
box.setContent(w+'g');
screen.render();
})
device.connStatus$.subscribe(s => {
if(s.state == 'connected') {
statusLine.setContent('Connected to Prep Pad '+s.serial);
}
else {
statusLine.setContent('Connecting...');
}
screen.render();
})
device.accel$.subscribe(s => {
let data = [
[ 'Accel', 'Value' ],
[ 'X', ''+s[0] ],
[ 'Y', ''+s[1] ],
[ 'Z', ''+s[2] ]
]
dataTable.setData(data);
screen.render();
})