Skip to content

Commit

Permalink
Merge pull request #10 from aj-ptw/bump-utils
Browse files Browse the repository at this point in the history
Bump utils
  • Loading branch information
AJ Keller committed Mar 21, 2018
2 parents 1365f43 + fff571f commit a2bd45b
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 483 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js
node_js:
- "4.8.4"
- "6.11.1"
- "7.10.1"
- "8.1.4"
- "6"
- "7"
- "8"
- "9"
env:
- CXX=g++-4.8
addons:
Expand Down
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,7 @@ const ourBoard = new Cyton();
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.on('ready',() => {
ourBoard.streamStart();
ourBoard.on('sample',(sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log("Channel " + (i + 1) + ": " + sample.channelData[i].toFixed(8) + " Volts.");
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
});
});
});
```
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.1.0

Bumping the minor version of openbci-utilities allows this module to move forward

### Breaking Changes

* Drop support for node 4 because of new OpenBCI utilities
* Connect will now automatically call `softReset` and resolve once it's complete.

# 1.0.8

Bump serial port to 1.0.8
Expand Down
46 changes: 22 additions & 24 deletions examples/getStreaming/getStreaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,29 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.on('ready', () => {
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++) {
console.log(`Channel ${(i + 1)}: ${sample.channelData[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
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++) {
console.log(`Channel ${(i + 1)}: ${sample.channelData[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 8: -0.00001875 Volts."
}
});
});
} else {
Expand Down
24 changes: 11 additions & 13 deletions examples/getStreamingDaisy/getStreamingDaisy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.once('ready', () => {
ourBoard.streamStart();
ourBoard.on('sample', (sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log(`Channel ${(i + 1)}: ${sample.channelDataCounts[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 16: -0.00001875 Volts."
}
});
ourBoard.streamStart();
ourBoard.on('sample', (sample) => {
/** Work with sample */
for (let i = 0; i < ourBoard.numberOfChannels(); i++) {
console.log(`Channel ${(i + 1)}: ${sample.channelDataCounts[i].toFixed(8)} Volts.`);
// prints to the console
// "Channel 1: 0.00001987 Volts."
// "Channel 2: 0.00002255 Volts."
// ...
// "Channel 16: -0.00001875 Volts."
}
});
});
} else {
Expand Down
90 changes: 44 additions & 46 deletions examples/impedance/impedance.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,57 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
*/
ourBoard.connect(portName) // Port name is a serial port name, see `.listPorts()`
.then(() => {
ourBoard.on('ready', () => {
ourBoard.streamStart();
ourBoard.on('sample', (sample) => {
if (startedImpedance === false) {
startedImpedance = true;
k.getImpedanceSetter(1, false, true)
.then((commands) => {
return ourBoard.write(commands);
})
.then(() => {
console.log('wrote commands to board');
})
.catch((err) => {
console.log('errr', err);
});
}
/** Work with sample */
const chan1ValInVolts = sample.channelData[0];
ourBoard.streamStart();
ourBoard.on('sample', (sample) => {
if (startedImpedance === false) {
startedImpedance = true;
k.getImpedanceSetter(1, false, true)
.then((commands) => {
return ourBoard.write(commands);
})
.then(() => {
console.log('wrote commands to board');
})
.catch((err) => {
console.log('errr', err);
});
}
/** Work with sample */
const chan1ValInVolts = sample.channelData[0];

// const impedance = chan1ValInVolts / k.OBCILeadOffDriveInAmps;
// const impedance = chan1ValInVolts / k.OBCILeadOffDriveInAmps;

// console.log(`impedance:\t${impedance} kOhms`);
iBuffer.push(chan1ValInVolts);
count++;
if (count >= window) {
let max = 0.0; // sumSquared
for (let i = 0; i < window; i++) {
if (iBuffer[i] > max) {
max = iBuffer[i];
}
// sumSquared += iBuffer[i] * iBuffer[i];
// console.log(`impedance:\t${impedance} kOhms`);
iBuffer.push(chan1ValInVolts);
count++;
if (count >= window) {
let max = 0.0; // sumSquared
for (let i = 0; i < window; i++) {
if (iBuffer[i] > max) {
max = iBuffer[i];
}
let min = 0.0;
for (let i = 0; i < window; i++) {
if (iBuffer[i] < min) {
min = iBuffer[i];
}
// sumSquared += iBuffer[i] * iBuffer[i];
// sumSquared += iBuffer[i] * iBuffer[i];
}
let min = 0.0;
for (let i = 0; i < window; i++) {
if (iBuffer[i] < min) {
min = iBuffer[i];
}
const vP2P = max - min; // peak to peak
// sumSquared += iBuffer[i] * iBuffer[i];
}
const vP2P = max - min; // peak to peak

console.log(`impedance: \t${vP2P / 2 / k.OBCILeadOffDriveInAmps}`);
// console.log(`impedance: ${vRms/k.OBCILeadOffDriveInAmps}`);
console.log(`impedance: \t${vP2P / 2 / k.OBCILeadOffDriveInAmps}`);
// console.log(`impedance: ${vRms/k.OBCILeadOffDriveInAmps}`);

// const mean_squared = sumSquared / window;
// const root_mean_squared = Math.sqrt(mean_squared);
// console.log(`impedance: ${root_mean_squared/k.OBCILeadOffDriveInAmps}`);
// const mean_squared = sumSquared / window;
// const root_mean_squared = Math.sqrt(mean_squared);
// console.log(`impedance: ${root_mean_squared/k.OBCILeadOffDriveInAmps}`);

count = 0;
iBuffer = [];
}
// console.log(`uV:\t${chan1ValInVolts/(10*6)}\nimpedance:\t${impedance}`);
});
count = 0;
iBuffer = [];
}
// console.log(`uV:\t${chan1ValInVolts/(10*6)}\nimpedance:\t${impedance}`);
});
});
} else {
Expand Down
38 changes: 18 additions & 20 deletions examples/labstreaminglayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,24 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
// Call to connect
ourBoard.connect(portName)
.then(() => {
ourBoard.on('ready', () => {
// Get the sample rate after 'ready'
numChans = ourBoard.numberOfChannels();
if (numChans === 16) {
ourBoard.overrideInfoForBoardType('daisy');
}

// Find out if you can even time sync, you must be using v2 and this is only accurate after a `.softReset()` call which is called internally on `.connect()`. We parse the `.softReset()` response for the presence of firmware version 2 properties.
timeSyncPossible = ourBoard.usingAtLeastVersionTwoFirmware();

sendToPython({'numChans': numChans, 'sampleRate': ourBoard.sampleRate()});
if (timeSyncPossible) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
} else {
console.log('not able to time sync');
}
});
// Get the sample rate after 'ready'
numChans = ourBoard.numberOfChannels();
if (numChans === 16) {
ourBoard.overrideInfoForBoardType('daisy');
}

// Find out if you can even time sync, you must be using v2 and this is only accurate after a `.softReset()` call which is called internally on `.connect()`. We parse the `.softReset()` response for the presence of firmware version 2 properties.
timeSyncPossible = ourBoard.usingAtLeastVersionTwoFirmware();

sendToPython({'numChans': numChans, 'sampleRate': ourBoard.sampleRate()});
if (timeSyncPossible) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
} else {
console.log('not able to time sync');
}
})
.catch(err => {
console.log(`connect: ${err}`);
Expand Down
26 changes: 12 additions & 14 deletions examples/python/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,18 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
// Call to connect
ourBoard.connect(portName)
.then(() => {
ourBoard.once('ready', () => {
// Find out if you can even time sync, you must be using v2 and this is only accurate after a `.softReset()` call which is called internally on `.connect()`. We parse the `.softReset()` response for the presence of firmware version 2 properties.
timeSyncPossible = ourBoard.usingAtLeastVersionTwoFirmware();
console.log(`timeSyncPossible: ${timeSyncPossible}`);

if (timeSyncPossible) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
} else {
console.log('not able to time sync');
}
});
// Find out if you can even time sync, you must be using v2 and this is only accurate after a `.softReset()` call which is called internally on `.connect()`. We parse the `.softReset()` response for the presence of firmware version 2 properties.
timeSyncPossible = ourBoard.usingAtLeastVersionTwoFirmware();
console.log(`timeSyncPossible: ${timeSyncPossible}`);

if (timeSyncPossible) {
ourBoard.streamStart()
.catch(err => {
console.log(`stream start: ${err}`);
});
} else {
console.log('not able to time sync');
}
})
.catch(err => {
console.log(`connect: ${err}`);
Expand Down
3 changes: 2 additions & 1 deletion examples/timeSync/timeSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ourBoard.autoFindOpenBCIBoard().then(portName => {
// Call to connect
ourBoard.connect(portName).then(() => {
console.log(`connected`);
readyFunc();
})
.catch(err => {
console.log(`connect: ${err}`);
Expand Down Expand Up @@ -88,7 +89,7 @@ const sampleFunc = sample => {
};

// Subscribe to your functions
ourBoard.on('ready', readyFunc);
// ourBoard.on('ready', readyFunc);
ourBoard.on('sample', sampleFunc);

function exitHandler (options, err) {
Expand Down
Loading

0 comments on commit a2bd45b

Please sign in to comment.