Skip to content

Commit 6e04c77

Browse files
author
AJ Keller
committed
FIX: getChannelData
1 parent 0dafc93 commit 6e04c77

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Bug Fixes
44

55
* Was missing errors in constants used by ganglion and other ble projects.
6+
* Fixed getChannelData functions to support 2 channel cytons
67

78
# 0.1.4
89

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

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)