-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
80 lines (63 loc) · 1.65 KB
/
server.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
const io = require('socket.io')()
const nodeThinkGear = require('node-thinkgear-sockets')
const tgClient = nodeThinkGear.createClient({
enableRawOutput: true,
})
tgClient.connect()
io.on('connection', (client) => {
tgClient.on('data', (data) => {
const signal = data.poorSignalLevel
const attention = data.eSense.attention
client.emit('signalRate', signal)
client.emit('attentionRate', attention)
console.log(attention)
})
})
const port = 9090
io.listen(port)
console.log('listening on port ', port)
// Arduino server
const argv = require('minimist')(process.argv.slice(2), {
default: {
show: 1,
},
})
const five = require('johnny-five')
const port2 = 9091
const io2 = require('socket.io')()
io2.listen(port2)
const board = new five.Board()
board.on('ready', () => {
console.log('Arduino is on')
io2.sockets.on('connection', (socket) => {
let touchpad
if (argv.show === 1) {
touchpad = new five.Touchpad({
controller: 'MPR121_SHIELD',
})
}
if (argv.show === 2) {
touchpad = new five.Touchpad({
controller: 'MPR121_SHIELD',
keys: [
['!', '@', '#'],
['$', '%', '^'],
['&', '-', '+'],
['_', '=', ':'],
],
})
}
if (argv.show === 3) {
touchpad = new five.Touchpad({
controller: 'MPR121_SHIELD',
keys: ['!', '@', '#', '$', '%', '^', '&', '-', '+', '_', '=', ':'],
})
}
['press'].forEach((eventType) => {
touchpad.on(eventType, (event) => {
socket.emit('objectTouched', event.which)
console.log('Event: %s, Target: %s', eventType, event.which)
})
})
})
})