-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.js
38 lines (32 loc) · 942 Bytes
/
serve.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
const SerialPort = require('serialport')
const {Output, getOutputs} = require('easymidi')
console.log( getOutputs() )
const output = new Output('MadMapper In')
main()
async function main(){
const serial = new SerialPort(
await getArduinoDevicePath(),
{ lock: false }
)
serial.on('data', buffer => {
const buttonNum = buffer.toString()
if( buttonNum ){
sendMidi( buttonNum )
}
})
}
function sendMidi( buttonNum ){
// https://www.npmjs.com/package/easymidi#message-reference
console.log('Control Change:', buttonNum )
output.send('cc', {
controller: buttonNum,
value: 127
})
}
async function getArduinoDevicePath(){
const [{path}] = ( await SerialPort.list() ).filter(
({manufacturer}) => manufacturer && manufacturer.indexOf('Arduino') === 0
)
console.log( 'Arduino found on "', path, '" port.' )
return path
}