Commit 64a0eb5a authored by Karan Goel's avatar Karan Goel
Browse files

demo works

parent 5962d1eb
...@@ -8,5 +8,8 @@ ...@@ -8,5 +8,8 @@
"start": "node server.js" "start": "node server.js"
}, },
"author": "mfs", "author": "mfs",
"license": "ISC" "license": "ISC",
"dependencies": {
"nodejs-websocket": "^1.2.0"
}
} }
...@@ -15,7 +15,11 @@ function connectToSerialPort () { ...@@ -15,7 +15,11 @@ function connectToSerialPort () {
process.exit(0); process.exit(0);
} }
console.log("Connect to Teensy via serial port attempt: #" + serialPortReconnectAttempt); console.log("Connect to Teensy via serial port attempt: #" + serialPortReconnectAttempt);
teensySerialPort = new SerialPort("/dev/ttyACM0", { // teensySerialPort = new SerialPort("/dev/ttyACM0", {
// baudRate : 115200 // USB full-speed.
// });
// WINDOWS
teensySerialPort = new SerialPort("COM7", {
baudRate : 115200 // USB full-speed. baudRate : 115200 // USB full-speed.
}); });
teensySerialPort.on("open", serialPortOnOpen); teensySerialPort.on("open", serialPortOnOpen);
......
...@@ -18,10 +18,14 @@ ...@@ -18,10 +18,14 @@
</head> </head>
<style type="text/css"> <style type="text/css">
body {
background: #000;
}
#wave { #wave {
width: 100%; width: 100%;
height: 200px; height: 100px;
margin-bottom: 30px; margin-bottom: 30px;
position: absolute; position: absolute;
top: 10%; top: 10%;
...@@ -29,14 +33,14 @@ ...@@ -29,14 +33,14 @@
#eegWave { #eegWave {
width: 100%; width: 100%;
height: 200px; height: 100px;
margin-bottom: 30px; margin-bottom: 30px;
position: absolute; position: absolute;
top: 60%; top: 60%;
} }
h1 { h1 {
color: #000; color: #fff;
} }
</style> </style>
...@@ -172,13 +176,13 @@ RefreshFrame = function () { ...@@ -172,13 +176,13 @@ RefreshFrame = function () {
velocity = 127; velocity = 127;
note = MIDI.pianoKeyOffset + i; note = MIDI.pianoKeyOffset + i;
sendLightData(relaySocket, "red", note*2.5); sendLightData(relaySocket, "red", Math.min(note, 255));
MIDI.noteOn(instrument, note, velocity, delay); MIDI.noteOn(instrument, note, velocity, delay);
lastSound[i] = ms; lastSound[i] = ms;
data.push(Math.cos(i/25) - 0.2 + r*0.3); data.push(Math.cos(note));
waveform.update({ waveform.update({
data: data data: data
}); });
...@@ -188,31 +192,32 @@ RefreshFrame = function () { ...@@ -188,31 +192,32 @@ RefreshFrame = function () {
}; };
var MIDI_INITIALIZED = false;
var socket = io(EEG_SOCKET_SERVER); var socket = io(EEG_SOCKET_SERVER);
socket.on('connection', function() { socket.on('get-EEG', function (data) {
socket.on('get-EEG', function (data) { eeg_data = JSON.parse(data);
data = JSON.parse(data);
if (MIDI_INITIALIZED &&
if (data.attention > 0 && data.meditation > 0) { eeg_data.attention > 0 && eeg_data.meditation > 0) {
RefreshFrame(); var min_nbrPoints = 48;
var min_nbrPoints = 48; var max_nbrPoints = 96;
var max_nbrPoints = 96; var min_data = 0;
var min_data = 0; var max_data = 100;
var max_data = 100;
nbrPoints = min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (data.attention - min_data)) / (max_data - min_data); nbrPoints = Math.round(min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (eeg_data.attention - min_data)) / (max_data - min_data));
eegData.push(Math.cos(data.attention - 0.2 + 0.3)); RefreshFrame();
eegWaveform.update({ eegData.push(Math.cos(eeg_data.attention));
data: eegData eegWaveform.update({
}); data: eegData
} else { });
eegData.push(Math.cos(90)); } else {
eegWaveform.update({ eegData.push(Math.cos(90));
data: eegData eegWaveform.update({
}); data: eegData
console.log('Connecting...') });
} console.log('Connecting...')
}); }
}); });
...@@ -234,6 +239,7 @@ window.onload = function () { ...@@ -234,6 +239,7 @@ window.onload = function () {
MIDI.programChange(3, 104); MIDI.programChange(3, 104);
MIDI.programChange(4, 1); MIDI.programChange(4, 1);
MIDI_INITIALIZED = true;
// setInterval(RefreshFrame, 200); // setInterval(RefreshFrame, 200);
}, },
callbackPCM: function (pcmBuffer) { callbackPCM: function (pcmBuffer) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment