openbci-ganglion
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -0,3 +1,11 @@ | ||
# 0.1.1 | ||
### New Features | ||
* Add function for starting, `.accelStart()`, and stopping, `.accelStop()`, accelerometer. | ||
### Bug Fixes | ||
* Impedance was outputting on verbose instead of debug. | ||
# 0.1.0 | ||
Initial release |
@@ -14,2 +14,5 @@ const Ganglion = require('../../index').Ganglion; | ||
const impedance = false; | ||
const accel = false; | ||
ganglion.once(k.OBCIEmitterGanglionFound, (peripheral) => { | ||
@@ -20,10 +23,7 @@ ganglion.searchStop().catch(errorFunc); | ||
/** Work with sample */ | ||
// console.log(sample.sampleNumber); | ||
// for (var i = 0; i < ganglion.numberOfChannels(); i++) { | ||
// console.log("Channel " + (i + 1) + ": " + sample.channelData[i].toFixed(8) + " Volts."); | ||
// } | ||
console.log(sample.sampleNumber); | ||
}); | ||
ganglion.on('droppedPackets', (data) => { | ||
// console.log('droppedPackets:', data); | ||
ganglion.on('droppedPacket', (data) => { | ||
console.log('droppedPacket:', data); | ||
}); | ||
@@ -35,9 +35,28 @@ | ||
let lastVal = 0; | ||
ganglion.on('accelerometer', (accelData) => { | ||
// Use accel array [0, 0, 0] | ||
// console.log(`z: ${accelData[2]}`); | ||
if (accelData[2] - lastVal > 1) { | ||
console.log(`Diff: ${accelData[2] - lastVal}`); | ||
} | ||
lastVal = accelData[2]; | ||
// console.log(`counter: ${accelData[2]}`); | ||
}); | ||
ganglion.on('impedance', (impedanceObj) => { | ||
console.log(`channel ${impedanceObj.channelNumber} has impedance ${impedanceObj.impedanceValue}`); | ||
}); | ||
ganglion.once('ready', () => { | ||
ganglion.streamStart().catch(errorFunc); | ||
if (accel) { | ||
ganglion.accelStart() | ||
.then(() => { | ||
return ganglion.streamStart(); | ||
}) | ||
.catch(errorFunc); | ||
} else if (impedance) { | ||
ganglion.impedanceStart().catch(errorFunc); | ||
} else { | ||
ganglion.streamStart().catch(errorFunc); | ||
} | ||
console.log('ready'); | ||
@@ -55,2 +74,14 @@ }); | ||
// console.log(connectedPeripheral) | ||
if (impedance) { | ||
ganglion.impedanceStop(); | ||
} | ||
if (ganglion.isSearching()) { | ||
ganglion.searchStop(); | ||
} | ||
if (accel) { | ||
ganglion.accelStop() | ||
.then(() => { | ||
return ganglion.streamStop(); | ||
}); | ||
} | ||
ganglion.manualDisconnect = true; | ||
@@ -57,0 +88,0 @@ ganglion.disconnect(); |
@@ -70,2 +70,6 @@ /** | ||
/** Accel enable/disable commands */ | ||
const obciAccelStart = 'n'; | ||
const obciAccelStop = 'N'; | ||
/** Errors */ | ||
@@ -311,2 +315,5 @@ const errorNobleAlreadyScanning = 'Scan already under way'; | ||
OBCISampleRate200: obciSampleRate200, | ||
/** Accel enable/disable commands */ | ||
OBCIAccelStart: obciAccelStart, | ||
OBCIAccelStop: obciAccelStop, | ||
/** Errors */ | ||
@@ -313,0 +320,0 @@ OBCIEmitterAccelerometer: obciEmitterAccelerometer, |
@@ -137,2 +137,19 @@ 'use strict'; | ||
/** | ||
* Used to enable the accelerometer. Will result in accelerometer packets arriving 10 times a second. | ||
* Note that the accelerometer is enabled by default. | ||
* @return {Promise} | ||
*/ | ||
Ganglion.prototype.accelStart = function () { | ||
return this.write(k.OBCIAccelStart); | ||
}; | ||
/** | ||
* Used to disable the accelerometer. Prevents accelerometer data packets from arriving. | ||
* @return {Promise} | ||
*/ | ||
Ganglion.prototype.accelStop = function () { | ||
return this.write(k.OBCIAccelStop); | ||
}; | ||
/** | ||
* Used to start a scan if power is on. Useful if a connection is dropped. | ||
@@ -899,4 +916,4 @@ */ | ||
this._droppedPacketCounter++; | ||
this.emit(k.OBCIEmitterDroppedPacket, [parseInt(data[0]) - 1]); | ||
// if (this.options.verbose) console.error('\t>>>PACKET DROP<<< ' + this._packetCounter + ' ' + this.lastDroppedPacket + ' ' + this._droppedPacketCounter); | ||
// this.emit(k.OBCIEmitterDroppedPacket, [parseInt(data[0]) - 1]); | ||
if (this.options.verbose) console.error('\t>>>PACKET DROP<<< ' + this._packetCounter + ' ' + this.lastDroppedPacket + ' ' + this._droppedPacketCounter); | ||
} | ||
@@ -936,3 +953,3 @@ | ||
Ganglion.prototype._processImpedanceData = function (data) { | ||
if (this.options.verbose) openBCIUtils.debugBytes('Impedance <<< ', data); | ||
if (this.options.debug) openBCIUtils.debugBytes('Impedance <<< ', data); | ||
const byteId = parseInt(data[0]); | ||
@@ -939,0 +956,0 @@ let channelNumber; |
{ | ||
"name": "openbci-ganglion", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "The official Node.js SDK for the OpenBCI Ganglion Biosensor Board.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -173,23 +173,2 @@ [![Join the chat at https://gitter.im/OpenBCI/OpenBCI_NodeJS](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OpenBCI/OpenBCI_NodeJS?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
Auto-finding boards | ||
------------------- | ||
You must have the OpenBCI board connected to the PC before trying to automatically find it. | ||
If a port is not automatically found, then call [`.listPorts()`](#method-list-ports) to get a list of all serial ports this would be a good place to present a drop down picker list to the user, so they may manually select the serial port name. | ||
```js | ||
const Ganglion = require('openbci-ganglion').Ganglion; | ||
const ourBoard = new Ganglion(); | ||
ourBoard.autoFindOpenBCIBoard().then(portName => { | ||
if(portName) { | ||
/** | ||
* Connect to the board with portName | ||
* i.e. ourBoard.connect(portName)..... | ||
*/ | ||
} else { | ||
/**Unable to auto find OpenBCI board*/ | ||
} | ||
}); | ||
``` | ||
See Reference Guide for a complete list of impedance tests. | ||
@@ -228,4 +207,20 @@ | ||
#### <a name="method-auto-reconnectd"></a> .autoReconnect() | ||
#### <a name="method-accel-start"></a> .accelStart() | ||
Used to enable the accelerometer. Will result in accelerometer packets arriving 10 times a second. | ||
**Note that the accelerometer is enabled by default.** | ||
**_Returns_** {Promise} - fulfilled once the command was sent to the board. | ||
#### <a name="method-accel-stop"></a> .accelStop() | ||
Used to disable the accelerometer. Prevents accelerometer data packets from arriving. | ||
**Note that the accelerometer is enabled by default.** | ||
**_Returns_** {Promise} - fulfilled once the command was sent to the board. | ||
#### <a name="method-auto-reconnect"></a> .autoReconnect() | ||
Used to start a scan if power is on. Useful if a connection is dropped. | ||
@@ -232,0 +227,0 @@ |
89028
1815
562