Skip to content

Commit 6dd3934

Browse files
author
AJ Keller
authored
Merge pull request #13 from aj-ptw/development
Development
2 parents da110e8 + 7c1180c commit 6dd3934

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.1.5
2+
3+
### Bug Fixes
4+
5+
* Was missing errors in constants used by ganglion and other ble projects.
6+
* Fixed getChannelData functions to support 2 channel cytons
7+
18
# 0.1.4
29

310
### Bug Fixes

openBCIConstants.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ const errorInvalidData = 'Invalid data - try again';
309309
const errorInvalidType = 'Invalid type - check comments for input type';
310310
const errorMissingRegisterSetting = 'Missing register setting';
311311
const errorMissingRequiredProperty = 'Missing property in JSON';
312+
const errorNobleAlreadyScanning = 'Scan already under way';
313+
const errorNobleNotAlreadyScanning = 'No scan started';
314+
const errorNobleNotInPoweredOnState = 'Please turn blue tooth on.';
312315
const errorTimeSyncIsNull = "'this.sync.curSyncObj' must not be null";
313316
const errorTimeSyncNoComma = 'Missed the time sync sent confirmation. Try sync again';
314317
const errorUndefinedOrNullInput = 'Undefined or Null Input';
@@ -422,6 +425,7 @@ const obciEmitterMessage = 'message';
422425
const obciEmitterQuery = 'query';
423426
const obciEmitterRawDataPacket = 'rawDataPacket';
424427
const obciEmitterReady = 'ready';
428+
const obciEmitterRFduino = 'rfduino';
425429
const obciEmitterSample = 'sample';
426430
const obciEmitterSynced = 'synced';
427431
const obciEmitterWifiShield = 'wifiShield';
@@ -996,6 +1000,9 @@ const constantsModule = {
9961000
OBCIErrorInvalidType: errorInvalidType,
9971001
OBCIErrorMissingRegisterSetting: errorMissingRegisterSetting,
9981002
OBCIErrorMissingRequiredProperty: errorMissingRequiredProperty,
1003+
OBCIErrorNobleAlreadyScanning: errorNobleAlreadyScanning,
1004+
OBCIErrorNobleNotAlreadyScanning: errorNobleNotAlreadyScanning,
1005+
OBCIErrorNobleNotInPoweredOnState: errorNobleNotInPoweredOnState,
9991006
OBCIErrorTimeSyncIsNull: errorTimeSyncIsNull,
10001007
OBCIErrorTimeSyncNoComma: errorTimeSyncNoComma,
10011008
OBCIErrorUndefinedOrNullInput: errorUndefinedOrNullInput,
@@ -1181,6 +1188,7 @@ const constantsModule = {
11811188
OBCIEmitterQuery: obciEmitterQuery,
11821189
OBCIEmitterRawDataPacket: obciEmitterRawDataPacket,
11831190
OBCIEmitterReady: obciEmitterReady,
1191+
OBCIEmitterRFduino: obciEmitterRFduino,
11841192
OBCIEmitterSample: obciEmitterSample,
11851193
OBCIEmitterSynced: obciEmitterSynced,
11861194
OBCIEmitterWifiShield: obciEmitterWifiShield,

openBCIUtilities.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,19 +1506,16 @@ function getChannelDataArray (o) {
15061506
if (!Array.isArray(o.channelSettings)) {
15071507
throw new Error('Error [getChannelDataArray]: Channel Settings must be an array!');
15081508
}
1509-
if (o.hasOwnProperty('protocol')) {
1510-
if (o.protocol !== k.OBCIProtocolSerial && o.protocol !== k.OBCIProtocolWifi) {
1511-
throw new Error(`Error [getChannelDataArray]: Invalid protocol must be ${k.OBCIProtocolWifi} or ${k.OBCIProtocolSerial}`);
1512-
}
1513-
} else {
1509+
if (!o.hasOwnProperty('protocol')) {
15141510
o.protocol = k.OBCIProtocolSerial;
15151511
}
15161512
let channelData = [];
15171513
// Grab the sample number from the buffer
15181514
const numChannels = o.channelSettings.length;
15191515
const sampleNumber = o.rawDataPacket[k.OBCIPacketPositionSampleNumber];
15201516
const daisy = numChannels === k.OBCINumberOfChannelsDaisy;
1521-
const channelsInPacket = numChannels > k.OBCINumberOfChannelsGanglion ? k.OBCINumberOfChannelsDefault : k.OBCINumberOfChannelsGanglion;
1517+
let channelsInPacket = k.OBCINumberOfChannelsCyton;
1518+
if (!daisy) channelsInPacket = o.channelSettings.length;
15221519
// Channel data arrays are always 8 long
15231520
for (let i = 0; i < channelsInPacket; i++) {
15241521
if (!o.channelSettings[i].hasOwnProperty('gain')) {
@@ -1548,6 +1545,10 @@ function getChannelDataArray (o) {
15481545
} else {
15491546
scaleFactor = k.OBCIGanglionScaleFactorPerCountVolts;
15501547
}
1548+
} else if (o.protocol === k.OBCIProtocolBLE) { // For cyton ble not ganglion
1549+
scaleFactor = ADS1299_VREF / o.channelSettings[i].gain / (Math.pow(2, 23) - 1);
1550+
} else {
1551+
throw new Error('Error [getChannelDataArray]: Invalid protocol must be wifi or serial');
15511552
}
15521553

15531554
// Convert the three byte signed integer and convert it

package.json

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

test/openBCIConstants-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,9 @@ describe('OpenBCIConstants', function () {
18651865
it('Event Emitter Ready', function () {
18661866
assert.equal('ready', k.OBCIEmitterReady);
18671867
});
1868+
it('Event Emitter RFduino', function () {
1869+
assert.equal('rfduino', k.OBCIEmitterRFduino);
1870+
});
18681871
it('Event Emitter Sample', function () {
18691872
assert.equal('sample', k.OBCIEmitterSample);
18701873
});
@@ -1891,6 +1894,15 @@ describe('OpenBCIConstants', function () {
18911894
it('errorMissingRequiredProperty', function () {
18921895
assert.equal(k.OBCIErrorMissingRequiredProperty, 'Missing property in JSON');
18931896
});
1897+
it('errorNobleAlreadyScanning', function () {
1898+
assert.equal(k.OBCIErrorNobleAlreadyScanning, 'Scan already under way');
1899+
});
1900+
it('errorNobleNotAlreadyScanning', function () {
1901+
assert.equal(k.OBCIErrorNobleNotAlreadyScanning, 'No scan started');
1902+
});
1903+
it('errorNobleNotInPoweredOnState', function () {
1904+
assert.equal(k.OBCIErrorNobleNotInPoweredOnState, 'Please turn blue tooth on.');
1905+
});
18941906
it('errorTimeSyncIsNull', function () {
18951907
assert.equal(k.OBCIErrorTimeSyncIsNull, "'this.sync.curSyncObj' must not be null");
18961908
});

test/openBCIUtilities-test.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,9 @@ describe('openBCIUtilities', function () {
535535
channelSetting.srb1 = true;
536536
});
537537
let data = Buffer.from(k.OBCIRegisterQueryCyton + k.OBCIRegisterQueryAccelerometerFirmwareV1);
538-
const majorFirmwareVersion = 1;
539538
openBCIUtilities.syncChannelSettingsWithRawData({
540539
channelSettings,
541-
data,
542-
majorFirmwareVersion
540+
data
543541
});
544542
expect(channelSettings).to.deep.equal(k.channelSettingsArrayInit(k.OBCINumberOfChannelsCyton));
545543
});
@@ -699,25 +697,15 @@ describe('openBCIUtilities', function () {
699697
majorFirmwareVersion
700698
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
701699
});
702-
it('majorFirmwareVersion is undefined', function () {
703-
let channelSettings = k.channelSettingsArrayInit(k.OBCINumberOfChannelsCyton);
704-
let data = Buffer.from(k.OBCIRegisterQueryCyton + k.OBCIRegisterQueryCytonDaisy + k.OBCIRegisterQueryAccelerometerFirmwareV3);
705-
expect(openBCIUtilities.syncChannelSettingsWithRawData.bind(openBCIUtilities, {
706-
channelSettings,
707-
data
708-
})).to.throw(k.OBCIErrorUndefinedOrNullInput);
709-
});
710700
it('invalid channel settings', function () {
711701
let channelSettings = [];
712702
for (let i = 0; i < k.OBCINumberOfChannelsCyton; i++) {
713703
channelSettings.push({taco: 'gordo'});
714704
}
715-
const majorFirmwareVersion = 3;
716705
let data = Buffer.from(k.OBCIRegisterQueryCyton + k.OBCIRegisterQueryAccelerometerFirmwareV3);
717706
expect(openBCIUtilities.syncChannelSettingsWithRawData.bind(openBCIUtilities, {
718707
channelSettings,
719-
data,
720-
majorFirmwareVersion
708+
data
721709
})).to.throw(k.OBCIErrorMissingRequiredProperty);
722710
});
723711
});
@@ -1768,6 +1756,22 @@ describe('openBCIUtilities', function () {
17681756
}
17691757
});
17701758
});
1759+
describe('BLE', function () {
1760+
it('should multiply each channel by the proper scale value', function () {
1761+
let chanArr = k.channelSettingsArrayInit(k.OBCINumberOfChannelsCytonBLE); // Not in daisy mode
1762+
let scaleFactor = 4.5 / 24 / (Math.pow(2, 23) - 1);
1763+
// Call the function under test
1764+
let valueArray = openBCIUtilities.getChannelDataArray({
1765+
rawDataPacket: sampleBuf,
1766+
channelSettings: chanArr,
1767+
protocol: k.OBCIProtocolBLE
1768+
});
1769+
for (let j = 0; j < k.OBCINumberOfChannelsCytonBLE; j++) {
1770+
// console.log(`channel data ${j + 1}: ${valueArray[j]} : actual ${scaleFactor * (j + 1)}`);
1771+
expect(valueArray[j]).to.be.closeTo(scaleFactor * (j + 1), 0.0001);
1772+
}
1773+
});
1774+
});
17711775
});
17721776
describe('#countADSPresent', function () {
17731777
it('should not crash on small buff', function () {

0 commit comments

Comments
 (0)