Skip to content

Commit 0ec0461

Browse files
author
AJ Keller
authored
Merge pull request #151 from aj-ptw/master
Working on stabalizing daisy
2 parents 259af35 + 8971878 commit 0ec0461

File tree

5 files changed

+128
-101
lines changed

5 files changed

+128
-101
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,10 @@ Emitted when the serial connection to the board is closed.
11431143
11441144
Emitted when a packet (or packets) are dropped. Returns an array.
11451145
1146+
#### <a name="event-eot"></a> .on('eot', callback)
1147+
1148+
Emitted when there is an EOT a.k.a. '$$$' with a buffer filled with the data.
1149+
11461150
#### <a name="event-error"></a> .on('error', callback)
11471151
11481152
Emitted when there is an on the serial port.

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 2.1.0
2+
3+
### Breaking changes
4+
5+
* Significantly reduce the properties in `this.info` object to only have firmware version and number of missed packets. Code dependent on this.info should switch to using `numberOfChannels()`, and `getBoardType()` and `sampleRate()` for accurate board info!
6+
7+
### Enhancements
8+
9+
* Fixes for daisy with new board, specifically hardSet.
10+
111
# 2.0.1
212

313
### Bug Fixes

openBCICyton.js

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const Buffer = require('safe-buffer').Buffer;
102102
* @private
103103
*/
104104
var _options = {
105-
boardType: [k.OBCIBoardDefault, k.OBCIBoardDaisy, k.OBCIBoardGanglion],
105+
boardType: [k.OBCIBoardCyton, k.OBCIBoardDefault, k.OBCIBoardDaisy, k.OBCIBoardGanglion],
106106
baudRate: 115200,
107107
hardSet: false,
108108
sendCounts: false,
@@ -179,7 +179,7 @@ function Cyton (options) {
179179
* @type {RawDataToSample}
180180
* @private
181181
*/
182-
this._rawDataPacketToSample = k.rawDataToSampleObjectDefault(8);
182+
this._rawDataPacketToSample = k.rawDataToSampleObjectDefault(k.numberOfChannelsForBoardType(this.options.boardType));
183183
this._rawDataPacketToSample.scale = !this.options.sendCounts;
184184
this._rawDataPacketToSample.protocol = k.OBCIProtocolSerial;
185185
this._rawDataPacketToSample.verbose = this.options.verbose;
@@ -194,15 +194,9 @@ function Cyton (options) {
194194
// Objects
195195
this.impedanceTest = obciUtils.impedanceTestObjDefault();
196196
this.info = {
197-
boardType: this.options.boardType,
198-
sampleRate: k.OBCISampleRate250,
199197
firmware: k.OBCIFirmwareV1,
200-
numberOfChannels: k.OBCINumberOfChannelsCyton,
201198
missedPackets: 0
202199
};
203-
if (this.options.boardType === k.OBCIBoardDefault) {
204-
this.info.sampleRate = k.OBCISampleRate250;
205-
}
206200

207201
this._lowerChannelsSampleObject = null;
208202
this.serial = null;
@@ -259,7 +253,7 @@ util.inherits(Cyton, EventEmitter);
259253
Cyton.prototype.connect = function (portName) {
260254
return new Promise((resolve, reject) => {
261255
if (this.isConnected()) return reject(Error('already connected!'));
262-
256+
this.overrideInfoForBoardType(this.options.boardType);
263257
/* istanbul ignore else */
264258
if (this.options.simulate || portName === k.OBCISimulatorPortName) {
265259
this.options.simulate = true;
@@ -1044,12 +1038,12 @@ Cyton.prototype.listPorts = function () {
10441038
* @return boardType: string
10451039
*/
10461040
Cyton.prototype.getBoardType = function () {
1047-
return this.info.boardType;
1041+
return k.boardTypeForNumberOfChannels(this._rawDataPacketToSample.channelSettings.length);
10481042
};
10491043

10501044
/**
10511045
* Get the core info object.
1052-
* @return {{boardType: string, sampleRate: number, firmware: string, numberOfChannels: number, missedPackets: number}}
1046+
* @return {{firmware: string, missedPackets: number}}
10531047
*/
10541048
Cyton.prototype.getInfo = function () {
10551049
return this.info;
@@ -1063,19 +1057,14 @@ Cyton.prototype.getInfo = function () {
10631057
Cyton.prototype.overrideInfoForBoardType = function (boardType) {
10641058
switch (boardType) {
10651059
case k.OBCIBoardDaisy:
1066-
this.info.boardType = k.OBCIBoardDaisy;
1067-
this.info.numberOfChannels = k.OBCINumberOfChannelsDaisy;
1068-
this.info.sampleRate = k.OBCISampleRate125;
1069-
this.channelSettingsArray = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDaisy);
1060+
this._rawDataPacketToSample.channelSettings = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDaisy);
10701061
this.impedanceArray = obciUtils.impedanceArray(k.OBCINumberOfChannelsDaisy);
10711062
break;
1063+
case k.OBCIBoardCyton:
10721064
case k.OBCIBoardDefault:
10731065
default:
1074-
this.info.boardType = k.OBCIBoardDefault;
1075-
this.info.numberOfChannels = k.OBCINumberOfChannelsDefault;
1076-
this.info.sampleRate = k.OBCISampleRate250;
1077-
this.channelSettingsArray = k.channelSettingsArrayInit(k.OBCINumberOfChannelsDefault);
1078-
this.impedanceArray = obciUtils.impedanceArray(k.OBCINumberOfChannelsDefault);
1066+
this._rawDataPacketToSample.channelSettings = k.channelSettingsArrayInit(k.OBCINumberOfChannelsCyton);
1067+
this.impedanceArray = obciUtils.impedanceArray(k.OBCINumberOfChannelsCyton);
10791068
break;
10801069
}
10811070
};
@@ -1092,7 +1081,7 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
10921081
const eotFunc = (data) => {
10931082
switch (data.slice(0, data.length - k.OBCIParseEOT.length).toString()) {
10941083
case k.OBCIChannelMaxNumber8SuccessDaisyRemoved:
1095-
this.overrideInfoForBoardType(k.OBCIBoardDefault);
1084+
this.overrideInfoForBoardType(k.OBCIBoardCyton);
10961085
resolve('daisy removed');
10971086
break;
10981087
case k.OBCIChannelMaxNumber16DaisyAlreadyAttached:
@@ -1104,18 +1093,19 @@ Cyton.prototype.hardSetBoardType = function (boardType) {
11041093
resolve('daisy attached');
11051094
break;
11061095
case k.OBCIChannelMaxNumber16NoDaisyAttached:
1107-
this.overrideInfoForBoardType(k.OBCIBoardDefault);
1096+
this.overrideInfoForBoardType(k.OBCIBoardCyton);
11081097
reject(Error('unable to attach daisy'));
11091098
break;
11101099
case k.OBCIChannelMaxNumber8NoDaisyToRemove:
11111100
default:
1112-
this.overrideInfoForBoardType(k.OBCIBoardDefault);
1101+
this.overrideInfoForBoardType(k.OBCIBoardCyton);
11131102
resolve('no daisy to remove');
11141103
break;
11151104
}
11161105
};
1117-
if (boardType === k.OBCIBoardDefault) {
1106+
if (boardType === k.OBCIBoardCyton || boardType === k.OBCIBoardDefault) {
11181107
this.curParsingMode = k.OBCIParsingEOT;
1108+
if (this.options.verbose) console.log('Attempting to hardset board type');
11191109
this.once(k.OBCIEmitterEot, eotFunc);
11201110
this.write(k.OBCIChannelMaxNumber8)
11211111
.catch((err) => {
@@ -1228,7 +1218,7 @@ Cyton.prototype.channelSet = function (channelNumber, powerDown, gain, inputType
12281218
k.getChannelSetter(channelNumber, powerDown, gain, inputType, bias, srb2, srb1)
12291219
.then((val) => {
12301220
arrayOfCommands = val.commandArray;
1231-
this.channelSettingsArray[channelNumber - 1] = val.newChannelSettingsObject;
1221+
this._rawDataPacketToSample.channelSettings[channelNumber - 1] = val.newChannelSettingsObject;
12321222
return this.write(arrayOfCommands);
12331223
}).then(resolve, reject);
12341224
});
@@ -1318,7 +1308,7 @@ Cyton.prototype.impedanceTestContinuousStop = function () {
13181308
* @author AJ Keller (@pushtheworldllc)
13191309
*/
13201310
Cyton.prototype.impedanceTestAllChannels = function () {
1321-
var upperLimit = k.OBCINumberOfChannelsDefault;
1311+
var upperLimit = k.OBCINumberOfChannelsCyton;
13221312

13231313
/* istanbul ignore if */
13241314
if (this.options.daisy) {
@@ -1671,16 +1661,13 @@ Cyton.prototype.sampleRate = function () {
16711661
if (this.options.simulate) {
16721662
return this.options.simulatorSampleRate;
16731663
} else {
1674-
if (this.info) {
1675-
return this.info.sampleRate;
1676-
} else {
1677-
switch (this.boardType) {
1678-
case k.OBCIBoardDaisy:
1679-
return k.OBCISampleRate125;
1680-
case k.OBCIBoardDefault:
1681-
default:
1682-
return k.OBCISampleRate250;
1683-
}
1664+
switch (this.getBoardType()) {
1665+
case k.OBCIBoardDaisy:
1666+
return k.OBCISampleRate125;
1667+
case k.OBCIBoardCyton:
1668+
case k.OBCIBoardDefault:
1669+
default:
1670+
return k.OBCISampleRate250;
16841671
}
16851672
}
16861673
};
@@ -1693,17 +1680,7 @@ Cyton.prototype.sampleRate = function () {
16931680
* @author AJ Keller (@pushtheworldllc)
16941681
*/
16951682
Cyton.prototype.numberOfChannels = function () {
1696-
if (this.info) {
1697-
return this.info.numberOfChannels;
1698-
} else {
1699-
switch (this.boardType) {
1700-
case k.OBCIBoardDaisy:
1701-
return k.OBCINumberOfChannelsDaisy;
1702-
case k.OBCIBoardDefault:
1703-
default:
1704-
return k.OBCINumberOfChannelsDefault;
1705-
}
1706-
}
1683+
return this._rawDataPacketToSample.channelSettings.length;
17071684
};
17081685

17091686
/**
@@ -1883,7 +1860,7 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
18831860
if (obciUtils.countADSPresent(dataBuffer) === 2) {
18841861
this.overrideInfoForBoardType(k.OBCIBoardDaisy);
18851862
} else {
1886-
this.overrideInfoForBoardType(k.OBCIBoardDefault);
1863+
this.overrideInfoForBoardType(k.OBCIBoardCyton);
18871864
}
18881865

18891866
if (obciUtils.findV2Firmware(dataBuffer)) {
@@ -2096,7 +2073,7 @@ Cyton.prototype._finalizeNewSample = function (sampleObject) {
20962073
} else {
20972074
// With the daisy board attached, lower channels (1-8) come in packets with odd sample numbers and upper
20982075
// channels (9-16) come in packets with even sample numbers
2099-
if (this.info.boardType === k.OBCIBoardDaisy) {
2076+
if (this.getBoardType === k.OBCIBoardDaisy) {
21002077
// Send the sample for downstream sample compaction
21012078
this._finalizeNewSampleForDaisy(sampleObject);
21022079
} else {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
55
"main": "index.js",
66
"scripts": {
@@ -21,7 +21,7 @@
2121
"gaussian": "^1.0.0",
2222
"lodash": "^4.17.4",
2323
"mathjs": "^3.14.2",
24-
"openbci-utilities": "0.0.9",
24+
"openbci-utilities": "0.0.10",
2525
"performance-now": "^2.1.0",
2626
"safe-buffer": "^5.1.1",
2727
"serialport": "4.0.7",

0 commit comments

Comments
 (0)