-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (40 loc) · 1.45 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
const inputRepresentationEmitter = require('./src/input-representation');
const { addReadyListener, updateOutput, resetOutput } = require('./src/output');
const { queueShutdown, cancelShutdown } = require('./src/system');
const createVigilanceControl = require('./src/vigilanceControl');
inputRepresentationEmitter
.on('device', ({ name }) => {
console.log(`found input device ${name}`);
})
.on('error', (err) => {
// TODO: differentiate between input disconnect errors and others
// only device disconnect (out of range?) errors seen so far
// reset the output to avoid zombie/sleepwalking based on the last known position
resetOutput();
console.error('input device error:', err);
})
.on('keyDown:start', queueShutdown)
.on('keyUp:start', cancelShutdown);
addReadyListener((err) => {
if (err) {
console.error('output device error', err);
process.exitCode = 1;
throw err;
}
// input system (bluetooth) froze? stop moving,
// but don't need to change steering or turn off lights
const vigilanceControl = createVigilanceControl({ expiryWindowMS: 300 })
.on('expired', () => {
updateOutput({
throttle: {
magnitude: 0,
},
});
});
console.log('output ready');
inputRepresentationEmitter.on('representation', (inputRepresentation) => {
updateOutput(inputRepresentation);
vigilanceControl.markTrigger();
});
console.log('input reader and output connected');
});