brainwaves quickstart

Esse commit está contido em:
Alex Castillo
2016-04-26 08:25:58 -04:00
commit 281ab81eaa
5 arquivos alterados com 149 adições e 2 exclusões
+3
Ver Arquivo
@@ -0,0 +1,3 @@
node_modules
.idea
.idea/vcs.xml
+30 -2
Ver Arquivo
@@ -1,2 +1,30 @@
# brainwaves-quickstart
A quickstart template for receiving and and passing data from OpenBCI to the browser
# Brainwaves Quickstart
A quickstart template for receiving and passing data from OpenBCI to the browser
### Step 1
Install the dependencies
```
npm install
```
### Step 2
Simply run the app:
```
node brainwaves
```
Or in simulated more:
```
node brainwaves simulate
```
### Step 3
Have fun
+68
Ver Arquivo
@@ -0,0 +1,68 @@
var argv = require('yargs').argv; // Yargs be a node.js library fer hearties tryin' ter parse optstrings.
var OpenBCIBoard = require('openbci-sdk');
var io = require('socket.io')(8080);
// Sockets
io.on('connection', function(socket){
console.log('A user with a brain connected');
});
var board = new OpenBCIBoard.OpenBCIBoard({
verbose: true // This is great for debugging
});
board.autoFindOpenBCIBoard()
.then(onBoardFind)
.catch(function () { // If a board is not found...
// This next part looks for a command line argument called 'simulate'
// This is specially helpful if you don't have a BCI and want to get some simulated data
if (!!(argv._[0] && argv._[0] === 'simulate')) {
board.connect(OpenBCIBoard.OpenBCIConstants.OBCISimulatorPortName)
.then(onBoardConnect);
}
});
// This function will be called when a board is found
function onBoardFind (portName) {
// The serial port's name
if (portName) {
console.log('board found', portName);
board.connect(portName)
.then(onBoardConnect);
}
}
// This function will be called when the board successfully connects
function onBoardConnect () {
board.on('ready', onBoardReady);
}
// This function will be called when the board is ready to stream data
function onBoardReady () {
board.streamStart();
board.on('sample', onSample);
}
// This function will be called every time a "sample" received from the board
// A sample is received every 4 milliseconds (holy batman!)
function onSample (sample) {
// In here we can access 'channelData' from the sample object
// 'channelData' is an array with 8 values, a value for each channel from the BCI, see example below
console.log(sample);
io.emit('brainwave', sample);
}
// This function will be called if the board is disconnected
function disconnectBoard () {
board.streamStop()
.then(function () {
board.disconnect().then(function () {
console.log('board disconnected');
process.exit();
});
});
}
process.on('SIGINT', function () {
setTimeout(disconnectBoard);
});
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<!doctype html>
<html>
<head>
<title>Brainwaves Quickstart</title>
<script src="node_modules/socket.io-client/socket.io.js"></script>
<style>
body {
background-color: #000000;
color: #ffffff;
font-size: 10px;
}
</style>
</head>
<body>
<main id="lines"></main>
<script>
var socket = io('http://localhost:8080');
var lines = document.querySelector('#lines');
socket.on('brainwave', function (brainwave) {
// Challenge: replace this next lines with an Angular repeater or a cool graph!
var line = document.createElement('pre');
line.innerHTML = 'Channel data: ' + brainwave.channelData;
lines.insertBefore(line, lines.firstChild);
});
</script>
</body>
</html>
+21
Ver Arquivo
@@ -0,0 +1,21 @@
{
"name": "brainwaves-quickstart",
"private": false,
"version": "1.0.0",
"description": "A quickstart template for receiving and passing data from OpenBCI to the browser",
"main": "brainwaves.js",
"license": "MIT",
"keywords": [
"openbci",
"brainwaves",
"EEG"
],
"author": "Alex Castillo",
"scripts": {},
"dependencies": {
"openbci-sdk": "^0.3.2",
"socket.io": "^1.4.5",
"socket.io-client": "^1.4.5",
"yargs": "^4.6.0"
}
}