function Brain(serial, rxPin, baud) {
  uartOptions = {bytesize: 8, parity:'none', stopbits:1, rx: rxPin};
  this.buf = '';
  //this.dataHandlers = [];
  this.serial = serial;
  this.serial.setup(baud, uartOptions);
  var serialDataHandler = (function(that){return (function(data){that.tgamReceive(data);});})(this);
  this.serial.on('data', serialDataHandler);
}
/*
Brain.js
========

This module interfaces the NeuroSky ThinkGear ASIC module (TGAM) for use with Espruino.

The module returns the following information:
- signal quality
- attention value
- meditation value
- EEG power band values for the following brain waves as 24 bit unsigned integers:
  delta, theta, low-alpha, high-alpha, low-beta, high-beta, low-gamma, mid-gamma
  
Currently only "normal output mode" of the TGAM is supported. When interfacing a TGAM
in "raw output mode", Brain.js should still correctly parse all received packets and
return the above values but ignore the raw data.

Usage:

1) Wire TGAM board to Espruino board
  | TGAM pin   | Espruino pin
  | ---------- | ------------
  | -          | GND
  | +          | 3.3
  | T          | Any Serial RX pin, for example A3

2) Write some code
   function processBrainData(data) {console.log(data.field, data.value);}  // event handler that just dumps data
   brain = require('Brain').connect(Serial2, A3, 9600);                    // initialize Brain module
   brain.on('data', processBrainData);                                     // hook up event handler

Disclaimer: use at your own risk.

Useful links:
TGAM Datasheet: http://www.seeedstudio.com/document/pdf/TGAM%20Datasheet.pdf
TGAM Protocol: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol
*/
Brain.js
This module interfaces the NeuroSky ThinkGear ASIC module (TGAM) for use with Espruino.



Currently only "normal output mode" of the TGAM is supported. When interfacing a TGAM
in "raw output mode", Brain.js should still correctly parse all received packets and
return the above values but ignore the raw data.







use at your own risk.


Brain . js This module interfaces the NeuroSky ThinkGear ASIC module ( TGAM ) for use with Espruino . Currently only " normal output mode " of the TGAM is supported . When interfacing a TGAM in " raw output mode " Brain . js should still correctly parse all received packets and return the above values but ignore the raw data . use at your own risk .
function Brain(serial, rxPin, baud) {
  uartOptions = {bytesize: 8, parity:'none', stopbits:1, rx: rxPin};
  this.buf = '';
  this.serial = serial;
  this.serial.setup(baud, uartOptions);
  var serialDataHandler = (function(that){return (function(data){that.tgamReceive(data);});})(this);
  this.serial.on('data', serialDataHandler);
}
function Brain ( serial , rxPin , baud ) { uartOptions = { bytesize : 8 , parity : 'none' , stopbits : 1 , rx : rxPin } ; this . buf = '' ; this . serial = serial ; this . serial . setup ( baud , uartOptions ) ; var serialDataHandler = ( function ( that ) { return ( function ( data ) { that . tgamReceive ( data ) ; } ) ; } ) ( this ) ; this . serial . on ( 'data' , serialDataHandler ) ; }
Brain.js
This module interfaces the NeuroSky ThinkGear ASIC module (TGAM) for use with Espruino.
Brain . js This module interfaces the NeuroSky ThinkGear ASIC module ( TGAM ) for use with Espruino .
//this.dataHandlers = [];