Add ability to suppress noble startup errors - #19
Esse commit está contido em:
@@ -1,3 +1,11 @@
|
||||
# 0.4.2
|
||||
|
||||
### New Features
|
||||
* Add callback function to constructor to catch noble errors.
|
||||
|
||||
### Bug Fixes
|
||||
* Fix #19
|
||||
|
||||
# 0.4.1
|
||||
|
||||
### New Features
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
const Ganglion = require('../../index').Ganglion;
|
||||
const k = require('../../openBCIConstants');
|
||||
const verbose = true;
|
||||
var ganglion = new Ganglion({
|
||||
// debug: true,
|
||||
let ganglion = new Ganglion({
|
||||
// debug: true; ,
|
||||
nobleAutoStart: false,
|
||||
sendCounts: true,
|
||||
verbose: verbose
|
||||
}, (error) => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
if (verbose) {
|
||||
console.log('Ganglion initialize completed');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function errorFunc (err) {
|
||||
@@ -101,6 +110,7 @@ function exitHandler (options, err) {
|
||||
ganglion.removeAllListeners('message');
|
||||
ganglion.removeAllListeners('impedance');
|
||||
ganglion.removeAllListeners('close');
|
||||
ganglion.removeAllListeners('error');
|
||||
ganglion.removeAllListeners('ganglionFound');
|
||||
ganglion.removeAllListeners('ready');
|
||||
ganglion.destroyNoble();
|
||||
|
||||
+23
-8
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const _ = require('lodash');
|
||||
const noble = require('noble');
|
||||
let noble;
|
||||
const util = require('util');
|
||||
// Local imports
|
||||
const ganglionSample = require('./openBCIGanglionSample');
|
||||
@@ -26,7 +26,7 @@ const _options = {
|
||||
|
||||
/**
|
||||
* @description The initialization method to call first, before any other method.
|
||||
* @param options (optional) - Board optional configurations.
|
||||
* @param options {object} (optional) - Board optional configurations.
|
||||
* - `debug` {Boolean} - Print out a raw dump of bytes sent and received. (Default `false`)
|
||||
*
|
||||
* - `nobleAutoStart` {Boolean} - Automatically initialize `noble`. Subscribes to blue tooth state changes and such.
|
||||
@@ -59,13 +59,19 @@ const _options = {
|
||||
* setting and this sample rate will be used. (Default is `250`)
|
||||
*
|
||||
* - `verbose` {Boolean} - Print out useful debugging events. (Default `false`)
|
||||
*
|
||||
* @param callback {function} (optional) - A callback function used to determine if the noble module was able to be started.
|
||||
* This can be very useful on Windows when there is no compatible BLE device found.
|
||||
* @constructor
|
||||
* @author AJ Keller (@pushtheworldllc)
|
||||
*/
|
||||
function Ganglion (options) {
|
||||
function Ganglion (options, callback) {
|
||||
if (!(this instanceof Ganglion)) {
|
||||
return new Ganglion(options);
|
||||
return new Ganglion(options, callback);
|
||||
}
|
||||
|
||||
if (options instanceof Function) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options = (typeof options !== 'function') && options || {};
|
||||
@@ -128,10 +134,17 @@ function Ganglion (options) {
|
||||
this.manualDisconnect = false;
|
||||
|
||||
/** Initializations */
|
||||
if (this.options.nobleAutoStart) this._nobleInit(); // It get's the noble going
|
||||
for (var i = 0; i < 3; i++) {
|
||||
this._decompressedSamples[i] = [0, 0, 0, 0];
|
||||
}
|
||||
|
||||
try {
|
||||
noble = require('noble');
|
||||
if (this.options.nobleAutoStart) this._nobleInit(); // It get's the noble going
|
||||
if (callback) callback();
|
||||
} catch (e) {
|
||||
if (callback) callback(e);
|
||||
}
|
||||
}
|
||||
|
||||
// This allows us to use the emitter class freely outside of the module
|
||||
@@ -594,8 +607,10 @@ Ganglion.prototype._disconnected = function () {
|
||||
* @private
|
||||
*/
|
||||
Ganglion.prototype._nobleDestroy = function () {
|
||||
noble.removeAllListeners(k.OBCINobleEmitterStateChange);
|
||||
noble.removeAllListeners(k.OBCINobleEmitterDiscover);
|
||||
if (noble) {
|
||||
noble.removeAllListeners(k.OBCINobleEmitterStateChange);
|
||||
noble.removeAllListeners(k.OBCINobleEmitterDiscover);
|
||||
}
|
||||
};
|
||||
|
||||
Ganglion.prototype._nobleConnect = function (peripheral) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openbci-ganglion",
|
||||
"version": "0.4.1",
|
||||
"version": "0.4.2",
|
||||
"description": "The official Node.js SDK for the OpenBCI Ganglion Biosensor Board.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -15,6 +15,21 @@ const clone = require('clone');
|
||||
chai.use(chaiAsPromised);
|
||||
chai.use(sinonChai);
|
||||
|
||||
describe('#ganglion-constructor', function () {
|
||||
it('should callback if only callback used', function (done) {
|
||||
const cb = (err) => {
|
||||
done(err);
|
||||
};
|
||||
const ganglion_cb = new Ganglion(cb);
|
||||
});
|
||||
it('should callback if options and callback', function (done) {
|
||||
const cb = (err) => {
|
||||
done(err);
|
||||
};
|
||||
const ganglion_cb = new Ganglion({}, cb);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ganglion', function () {
|
||||
const mockProperties = {
|
||||
nobleAutoStart: false,
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário