-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (34 loc) · 1.12 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
import SystemInformation from './system-information.js';
import CorneKeyboard from './corne-keyboard.js';
import CorneOledFormatter from './corne-oled-formatter.js';
const POLL_INTERVAL = 1000;
const keyboard = new CorneKeyboard();
function exitHandler() {
console.log('Closing keyboard');
keyboard.close();
process.exit();
}
function errorHandler(err) {
console.error('Error');
console.error(err);
keyboard.close();
process.exit();
}
process.on('exit', exitHandler);
process.on('SIGINT', exitHandler);
process.on('SIGQUIT', exitHandler);
process.on('uncaughtException', errorHandler);
console.log('Opening keyboard');
keyboard.open();
const systemInformation = new SystemInformation();
const oledFormatter = new CorneOledFormatter();
setInterval(async () => {
console.log('Getting stats');
const stats = await systemInformation.getStats();
console.log('Formatting stats');
const oledLines = oledFormatter.formatSystemInformation(stats);
console.log('Sending stats');
keyboard.sendText(0, oledLines[0]);
keyboard.sendText(1, oledLines[1]);
console.log('Done');
}, POLL_INTERVAL);