Skip to content

Commit

Permalink
Merge pull request #160 from aj-ptw/channel-writing
Browse files Browse the repository at this point in the history
FIX: Sending channel setting commands might not work
  • Loading branch information
AJ Keller authored Aug 21, 2017
2 parents 3e4b9a2 + a4e0edb commit 37fc78a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 2.2.0

### Bug Fixes

* Calling sdStart and stop would change the writeOutDelay
* Timeout for v1 was set to 10 ms instead of 50 ms.
* Timeout for v2+ was set to 0 ms instead of 10 ms.

# 2.1.4

### Enhancements
Expand Down
14 changes: 13 additions & 1 deletion examples/getStreaming/getStreaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.on('ready', () => {
ourBoard.streamStart();
ourBoard.syncRegisterSettings()
.then((cs) => {
return ourBoard.streamStart();
})
.catch((err) => {
console.log('err', err);
return ourBoard.streamStart();
})
.catch((err) => {
console.log('fatal err', err);
process.exit(0);
});

ourBoard.on('sample', (sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
Expand Down
41 changes: 11 additions & 30 deletions openBCICyton.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ Cyton.prototype.write = function (dataToWrite) {

/**
* @description Should be used to send data to the board
* @param data {Buffer} - The data to write out
* @param data {Buffer | Buffer2} - The data to write out
* @returns {Promise} if signal was able to be sent
* @author AJ Keller (@pushtheworldllc)
*/
Expand Down Expand Up @@ -1277,7 +1277,12 @@ Cyton.prototype.channelSet = function (channelNumber, powerDown, gain, inputType
.then((val) => {
arrayOfCommands = val.commandArray;
this._rawDataPacketToSample.channelSettings[channelNumber - 1] = val.newChannelSettingsObject;
return this.write(arrayOfCommands);
if (this.usingAtLeastVersionTwoFirmware()) {
const buf = Buffer.from(arrayOfCommands.join(''));
return this._writeAndDrain(buf);
} else {
return this.write(arrayOfCommands);
}
}).then(resolve, reject);
});
};
Expand Down Expand Up @@ -1684,7 +1689,7 @@ Cyton.prototype.sdStart = function (recordingDuration) {
if (!this.isStreaming()) {
this.curParsingMode = k.OBCIParsingEOT;
}
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
// this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
this.write(command).then(resolve, reject);
})
.catch(err => reject(err));
Expand All @@ -1704,7 +1709,7 @@ Cyton.prototype.sdStop = function () {
if (!this.isStreaming()) {
this.curParsingMode = k.OBCIParsingEOT;
}
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
// this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
this.write(k.OBCISDLogStop).then(resolve, reject);
});
};
Expand Down Expand Up @@ -1928,10 +1933,10 @@ Cyton.prototype._processParseBufferForReset = function (dataBuffer) {
} else {
this.info.firmware = k.OBCIFirmwareV3;
}
this.writeOutDelay = k.OBCIWriteIntervalDelayMSNone;
this.writeOutDelay = k.OBCIWriteIntervalDelayMSShort;
} else {
this.info.firmware = k.OBCIFirmwareV1;
this.writeOutDelay = k.OBCIWriteIntervalDelayMSShort;
this.writeOutDelay = k.OBCIWriteIntervalDelayMSLong;
}
};

Expand Down Expand Up @@ -2302,28 +2307,4 @@ Cyton.prototype.debugSession = function () {
this.printPacketsBad();
};

/**
* @description To pretty print the info recieved on a Misc Register Query (printRegisterSettings)
* @param channelSettingsObj
*/
/* istanbul ignore next */
Cyton.prototype.debugPrintChannelSettings = function (channelSettingsObj) {
console.log('-- Channel Settings Object --');
var powerState = 'OFF';
if (channelSettingsObj.POWER_DOWN.toString().localeCompare('1')) {
powerState = 'ON';
}
console.log('---- POWER STATE: ' + powerState);
console.log('-- END --');
};

/**
* @description Quickly determine if a channel is on or off from a channelSettingObject. Most likely from a getChannelSettings call.
* @param channelSettingsObject
* @returns {boolean}
*/
Cyton.prototype.channelIsOnFromChannelSettingsObject = function (channelSettingsObject) {
return channelSettingsObject.POWER_DOWN.toString().localeCompare('1') === 1;
};

module.exports = Cyton;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openbci",
"version": "2.1.4",
"version": "2.2.0",
"description": "The official Node.js SDK for the OpenBCI Biosensor Board.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/openBCICyton-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('openbci-sdk', function () {
setTimeout(() => {
console.log.should.have.been.calledWithMatch(k.OBCIStreamStop);
done();
}, 20);
}, k.OBCIWriteIntervalDelayMSLong * 2);
});
it('outputs a packet when received', done => {
console.log.reset();
Expand Down

0 comments on commit 37fc78a

Please sign in to comment.