Skip to content

Commit 37fc78a

Browse files
author
AJ Keller
authored
Merge pull request #160 from aj-ptw/channel-writing
FIX: Sending channel setting commands might not work
2 parents 3e4b9a2 + a4e0edb commit 37fc78a

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.2.0
2+
3+
### Bug Fixes
4+
5+
* Calling sdStart and stop would change the writeOutDelay
6+
* Timeout for v1 was set to 10 ms instead of 50 ms.
7+
* Timeout for v2+ was set to 0 ms instead of 10 ms.
8+
19
# 2.1.4
210

311
### Enhancements

examples/getStreaming/getStreaming.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
2828
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
2929
.then(() => {
3030
ourBoard.on('ready', () => {
31-
ourBoard.streamStart();
31+
ourBoard.syncRegisterSettings()
32+
.then((cs) => {
33+
return ourBoard.streamStart();
34+
})
35+
.catch((err) => {
36+
console.log('err', err);
37+
return ourBoard.streamStart();
38+
})
39+
.catch((err) => {
40+
console.log('fatal err', err);
41+
process.exit(0);
42+
});
43+
3244
ourBoard.on('sample', (sample) => {
3345
/** Work with sample */
3446
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {

openBCICyton.js

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ Cyton.prototype.write = function (dataToWrite) {
545545

546546
/**
547547
* @description Should be used to send data to the board
548-
* @param data {Buffer} - The data to write out
548+
* @param data {Buffer | Buffer2} - The data to write out
549549
* @returns {Promise} if signal was able to be sent
550550
* @author AJ Keller (@pushtheworldllc)
551551
*/
@@ -1277,7 +1277,12 @@ Cyton.prototype.channelSet = function (channelNumber, powerDown, gain, inputType
12771277
.then((val) => {
12781278
arrayOfCommands = val.commandArray;
12791279
this._rawDataPacketToSample.channelSettings[channelNumber - 1] = val.newChannelSettingsObject;
1280-
return this.write(arrayOfCommands);
1280+
if (this.usingAtLeastVersionTwoFirmware()) {
1281+
const buf = Buffer.from(arrayOfCommands.join(''));
1282+
return this._writeAndDrain(buf);
1283+
} else {
1284+
return this.write(arrayOfCommands);
1285+
}
12811286
}).then(resolve, reject);
12821287
});
12831288
};
@@ -1684,7 +1689,7 @@ Cyton.prototype.sdStart = function (recordingDuration) {
16841689
if (!this.isStreaming()) {
16851690
this.curParsingMode = k.OBCIParsingEOT;
16861691
}
1687-
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
1692+
// this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
16881693
this.write(command).then(resolve, reject);
16891694
})
16901695
.catch(err => reject(err));
@@ -1704,7 +1709,7 @@ Cyton.prototype.sdStop = function () {
17041709
if (!this.isStreaming()) {
17051710
this.curParsingMode = k.OBCIParsingEOT;
17061711
}
1707-
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
1712+
// this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
17081713
this.write(k.OBCISDLogStop).then(resolve, reject);
17091714
});
17101715
};
@@ -1928,10 +1933,10 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
19281933
} else {
19291934
this.info.firmware = k.OBCIFirmwareV3;
19301935
}
1931-
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
1936+
this.writeOutDelay = k.OBCIWriteIntervalDelayMSShort;
19321937
} else {
19331938
this.info.firmware = k.OBCIFirmwareV1;
1934-
this.writeOutDelay = k.OBCIWriteIntervalDelayMSShort;
1939+
this.writeOutDelay = k.OBCIWriteIntervalDelayMSLong;
19351940
}
19361941
};
19371942

@@ -2302,28 +2307,4 @@ Cyton.prototype.debugSession = function () {
23022307
this.printPacketsBad();
23032308
};
23042309

2305-
/**
2306-
* @description To pretty print the info recieved on a Misc Register Query (printRegisterSettings)
2307-
* @param channelSettingsObj
2308-
*/
2309-
/* istanbul ignore next */
2310-
Cyton.prototype.debugPrintChannelSettings = function (channelSettingsObj) {
2311-
console.log('-- Channel Settings Object --');
2312-
var powerState = 'OFF';
2313-
if (channelSettingsObj.POWER_DOWN.toString().localeCompare('1')) {
2314-
powerState = 'ON';
2315-
}
2316-
console.log('---- POWER STATE: ' + powerState);
2317-
console.log('-- END --');
2318-
};
2319-
2320-
/**
2321-
* @description Quickly determine if a channel is on or off from a channelSettingObject. Most likely from a getChannelSettings call.
2322-
* @param channelSettingsObject
2323-
* @returns {boolean}
2324-
*/
2325-
Cyton.prototype.channelIsOnFromChannelSettingsObject = function (channelSettingsObject) {
2326-
return channelSettingsObject.POWER_DOWN.toString().localeCompare('1') === 1;
2327-
};
2328-
23292310
module.exports = Cyton;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openbci",
3-
"version": "2.1.4",
3+
"version": "2.2.0",
44
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
55
"main": "index.js",
66
"scripts": {

test/openBCICyton-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ describe('openbci-sdk', function () {
553553
setTimeout(() => {
554554
console.log.should.have.been.calledWithMatch(k.OBCIStreamStop);
555555
done();
556-
}, 20);
556+
}, k.OBCIWriteIntervalDelayMSLong * 2);
557557
});
558558
it('outputs a packet when received', done => {
559559
console.log.reset();

0 commit comments

Comments
 (0)