Skip to content

Commit d9f024f

Browse files
author
AJ Keller
authored
Merge pull request #158 from aj-ptw/sync-chan-set
Sync chan set
2 parents 2992d23 + d256e87 commit d9f024f

File tree

5 files changed

+274
-233
lines changed

5 files changed

+274
-233
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,12 @@ ourBoard.connect(portName)
10691069

10701070
```
10711071
1072+
#### <a name="method-sync-register-settings"></a> .syncRegisterSettings()
1073+
1074+
Syncs the internal channel settings object with a cyton, this will take about over a second because there are delays between the register reads in the firmware.
1075+
1076+
**_Returns_** a promise, fulfilled once the channel settings have been synced and reject on error.
1077+
10721078
#### <a name="method-test-signal"></a> .testSignal(signal)
10731079
10741080
Apply the internal test signal to all channels.

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.1.3
2+
3+
### Enhancements
4+
5+
* Can now sync the channel settings from the actual registers on the ADS! Call `.syncRegisterSettings()`
6+
* Bumped openbci-utilities to v0.1.4
7+
18
# 2.1.2
29

310
### Enhancements

openBCICyton.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,13 +1184,40 @@ Cyton.prototype.getSettingsForChannel = function (channelNumber) {
11841184
};
11851185

11861186
/**
1187-
* @description To print out the register settings to the console
1188-
* @returns {Promise.<T>|*}
1187+
* @description Syncs the internal channel settings object with a cyton, this will take about
1188+
* over a second because there are delays between the register reads in the firmware.
1189+
* @returns {Promise.<T>|*} Resolved once synced, rejects on error or 2 second timeout
11891190
* @author AJ Keller (@pushtheworldllc)
11901191
*/
1191-
Cyton.prototype.printRegisterSettings = function () {
1192-
return this.write(k.OBCIMiscQueryRegisterSettings).then(() => {
1193-
this.curParsingMode = k.OBCIParsingChannelSettings;
1192+
Cyton.prototype.syncRegisterSettings = function () {
1193+
// Set a timeout. Since poll times can be max of 255 seconds, we should set that as our timeout. This is
1194+
// important if the module was connected, not streaming and using the old firmware
1195+
let badCommsTimeout;
1196+
return new Promise((resolve, reject) => {
1197+
badCommsTimeout = setTimeout(() => {
1198+
reject(Error('Please make sure your radio system is up'));
1199+
}, 2500);
1200+
// Subscribe to the EOT event
1201+
this.once(k.OBCIEmitterEot, data => {
1202+
if (this.options.verbose) console.log(data.toString());
1203+
this._rawDataPacketToSample.data = data;
1204+
try {
1205+
obciUtils.syncChannelSettingsWithRawData(this._rawDataPacketToSample);
1206+
resolve();
1207+
} catch (e) {
1208+
reject(e);
1209+
}
1210+
// Remove the timeout!
1211+
clearTimeout(badCommsTimeout);
1212+
badCommsTimeout = null;
1213+
});
1214+
this.curParsingMode = k.OBCIParsingEOT;
1215+
1216+
this.write(k.OBCIMiscQueryRegisterSettings)
1217+
.catch((err) => {
1218+
clearTimeout(badCommsTimeout);
1219+
reject(err);
1220+
});
11941221
});
11951222
};
11961223

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.1.2",
3+
"version": "2.1.3",
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.1.2",
24+
"openbci-utilities": "^0.1.4",
2525
"performance-now": "^2.1.0",
2626
"safe-buffer": "^5.1.1",
2727
"serialport": "4.0.7",

0 commit comments

Comments
 (0)