Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions examples/impedanceTestDaisy/impedanceTestDaisy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* This is an example from the readme.md
* On windows you should run with PowerShell not git bash.
* Install
* [nodejs](https://nodejs.org/en/)
*
* To run:
* change directory to this file `cd examples/debug`
* do `npm install`
* then `npm start`
*/
const debug = false; // Pretty print any bytes in and out... it's amazing...
const verbose = true; // Adds verbosity to functions

const Cyton = require('../../openBCICyton');
var ourBoard = new Cyton({
boardType: 'daisy',
debug: debug,
hardSet: true,
verbose: verbose,
simulate: true,
simulatorDaisyModuleAttached: true,
simulatorSampleRate: 125
});

ourBoard.on('error', (err) => {
console.log(err);
});

ourBoard.autoFindOpenBCIBoard().then(portName => {
if (portName) {
/**
* Connect to the board with portName
* Only works if one board is plugged in
* i.e. ourBoard.connect(portName).....
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.once('ready', () => {
ourBoard.streamStart();
ourBoard.impedanceTestAllChannels();
ourBoard.on('impedanceArray', impedanceArray => {
console.log(impedanceArray);
ourBoard.impedanceTestAllChannels();
});
});
});
} else {
/** Unable to auto find OpenBCI board */
console.log('Unable to auto find OpenBCI board');
}
});

function exitHandler (options, err) {
if (options.cleanup) {
if (verbose) console.log('clean');
ourBoard.removeAllListeners();
/** Do additional clean up here */
}
if (err) console.log(err.stack);
if (options.exit) {
if (verbose) console.log('exit');
ourBoard.disconnect().catch(console.log);
}
}

// do something when app is closing
process.on('exit', exitHandler.bind(null, {
cleanup: true
}));

// catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {
exit: true
}));
17 changes: 17 additions & 0 deletions examples/impedanceTestDaisy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "impedance-test-daisy",
"version": "1.0.0",
"description": "Impedance test function with daisy example",
"main": "impedanceTestDaisy.js",
"scripts": {
"start": "node impedanceTestDaisy.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"get"
],
"license": "MIT",
"dependencies": {
"openbci": "^2.0.0"
}
}
16 changes: 11 additions & 5 deletions openBCICyton.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ Cyton.prototype.impedanceTestAllChannels = function () {
let upperLimit = k.OBCINumberOfChannelsCyton;

/* istanbul ignore if */
if (this.options.daisy) {
if (this.options.boardType === k.OBCIBoardDaisy) {
upperLimit = k.OBCINumberOfChannelsDaisy;
}

Expand Down Expand Up @@ -2165,13 +2165,18 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
this.badPackets++;
this.emit(k.OBCIEmitterDroppedPacket, [this.previousSampleNumber + 1]);
} else if (this.impedanceTest.active) {
this._processImpedanceTest(sampleObject);
if (_.eq(this.getBoardType(), k.OBCIBoardDaisy)) {
this._finalizeNewSampleForDaisy(sampleObject, true);
} else {
this._processImpedanceTest(sampleObject);
this.emit(k.OBCIEmitterSample, sampleObject);
}
} else {
// With the daisy board attached, lower channels (1-8) come in packets with odd sample numbers and upper
// channels (9-16) come in packets with even sample numbers
if (_.eq(this.getBoardType(), k.OBCIBoardDaisy)) {
// Send the sample for downstream sample compaction
this._finalizeNewSampleForDaisy(sampleObject);
this._finalizeNewSampleForDaisy(sampleObject, false);
} else {
this.emit(k.OBCIEmitterSample, sampleObject);
}
Expand All @@ -2188,7 +2193,7 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
* @private
* @author AJ Keller (@pushtheworldllc)
*/
Cyton.prototype._finalizeNewSampleForDaisy = function (sampleObject) {
Cyton.prototype._finalizeNewSampleForDaisy = function (sampleObject, impedance) {
if (obciUtils.isOdd(sampleObject.sampleNumber)) {
// Check for the skipped packet condition
if (this._lowerChannelsSampleObject) {
Expand All @@ -2203,7 +2208,8 @@ Cyton.prototype._finalizeNewSampleForDaisy = function (sampleObject) {
let mergedSample = obciUtils.makeDaisySampleObject(this._lowerChannelsSampleObject, sampleObject);
// Set the _lowerChannelsSampleObject object to null
this._lowerChannelsSampleObject = null;
// Emite the new merged sample
// Emite the new merged sample and if relevant process impedance
if (impedance) this._processImpedanceTest(mergedSample);
this.emit('sample', mergedSample);
} else {
// Missed the odd packet, i.e. two evens in a row
Expand Down