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

demo works

parent 5962d1eb
......@@ -8,5 +8,8 @@
"start": "node server.js"
},
"author": "mfs",
"license": "ISC"
"license": "ISC",
"dependencies": {
"nodejs-websocket": "^1.2.0"
}
}
......@@ -15,7 +15,11 @@ function connectToSerialPort () {
process.exit(0);
}
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.
});
teensySerialPort.on("open", serialPortOnOpen);
......
......@@ -18,10 +18,14 @@
</head>
<style type="text/css">
body {
background: #000;
}
#wave {
width: 100%;
height: 200px;
height: 100px;
margin-bottom: 30px;
position: absolute;
top: 10%;
......@@ -29,14 +33,14 @@
#eegWave {
width: 100%;
height: 200px;
height: 100px;
margin-bottom: 30px;
position: absolute;
top: 60%;
}
h1 {
color: #000;
color: #fff;
}
</style>
......@@ -172,13 +176,13 @@ RefreshFrame = function () {
velocity = 127;
note = MIDI.pianoKeyOffset + i;
sendLightData(relaySocket, "red", note*2.5);
sendLightData(relaySocket, "red", Math.min(note, 255));
MIDI.noteOn(instrument, note, velocity, delay);
lastSound[i] = ms;
data.push(Math.cos(i/25) - 0.2 + r*0.3);
data.push(Math.cos(note));
waveform.update({
data: data
});
......@@ -188,31 +192,32 @@ RefreshFrame = function () {
};
var MIDI_INITIALIZED = false;
var socket = io(EEG_SOCKET_SERVER);
socket.on('connection', function() {
socket.on('get-EEG', function (data) {
data = JSON.parse(data);
if (data.attention > 0 && data.meditation > 0) {
RefreshFrame();
var min_nbrPoints = 48;
var max_nbrPoints = 96;
var min_data = 0;
var max_data = 100;
nbrPoints = min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (data.attention - min_data)) / (max_data - min_data);
eegData.push(Math.cos(data.attention - 0.2 + 0.3));
eegWaveform.update({
data: eegData
});
} else {
eegData.push(Math.cos(90));
eegWaveform.update({
data: eegData
});
console.log('Connecting...')
}
});
socket.on('get-EEG', function (data) {
eeg_data = JSON.parse(data);
if (MIDI_INITIALIZED &&
eeg_data.attention > 0 && eeg_data.meditation > 0) {
var min_nbrPoints = 48;
var max_nbrPoints = 96;
var min_data = 0;
var max_data = 100;
nbrPoints = Math.round(min_nbrPoints + ((max_nbrPoints - min_nbrPoints) * (eeg_data.attention - min_data)) / (max_data - min_data));
RefreshFrame();
eegData.push(Math.cos(eeg_data.attention));
eegWaveform.update({
data: eegData
});
} else {
eegData.push(Math.cos(90));
eegWaveform.update({
data: eegData
});
console.log('Connecting...')
}
});
......@@ -234,6 +239,7 @@ window.onload = function () {
MIDI.programChange(3, 104);
MIDI.programChange(4, 1);
MIDI_INITIALIZED = true;
// setInterval(RefreshFrame, 200);
},
callbackPCM: function (pcmBuffer) {
......
Markdown is supported
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