diff --git a/examples/sensorFusion.js b/examples/sensorFusion.js index 63854be..0f314dc 100644 --- a/examples/sensorFusion.js +++ b/examples/sensorFusion.js @@ -12,12 +12,14 @@ devices.discover(function(device) { device.connectAndSetup(function(error) { console.log('were connected!'); - const DATA_QUATERION = 3; - const NDOF = 1; + const QUATERION = 0x7; + const DATA_QUATERION = 0x3; + const MODE_NDOF = 0x1; var sensorFusion = new device.SensorFusion(device); - sensorFusion.config.setMode(NDOF); + sensorFusion.config.setMode(MODE_NDOF); + sensorFusion.subscribe(QUATERION); sensorFusion.enableData(DATA_QUATERION); sensorFusion.start(); diff --git a/src/registers/sensorFusion.js b/src/registers/sensorFusion.js index f9ec216..b7dad5f 100644 --- a/src/registers/sensorFusion.js +++ b/src/registers/sensorFusion.js @@ -37,7 +37,7 @@ const DATA_CORRECTED_ACC = 0, var SensorFusion = function(device) { this.device = device; this.config = new Config(); - this.dataSourceMask = undefined; + this.dataSourceMask = 0x0; this.accelerometer = new Accelerometer(device); this.gyro = new Gyro(device); this.magnetometer = new Magnetometer(device); @@ -48,6 +48,18 @@ SensorFusion.prototype.enableData = function(data_source) { this.dataSourceMask |= (0x1 << data_source); }; +SensorFusion.prototype.clearEnabledMask = function() { + this.dataSourceMask = 0x0; +}; + +SensorFusion.prototype.subscribe = function(output_type) { + var buffer = new Buffer(3); + buffer[0] = MODULE_OPCODE; + buffer[1] = output_type; + buffer[2] = 0x1; + this.device.send(buffer); +}; + SensorFusion.prototype.start = function() { switch(this.config.mode) { @@ -101,6 +113,15 @@ SensorFusion.prototype.stop = function() { }; +SensorFusion.prototype.unsubscribe = function(output_type) { + var buffer = new Buffer(3); + buffer[0] = MODULE_OPCODE; + buffer[1] = output_type; + buffer[2] = 0x0; + this.device.send(buffer); +}; + + SensorFusion.prototype.onChange = function(callback) { this.device.emitter.on([MODULE_OPCODE, QUATERNION], function(buffer) { var quaternion = new Core.Quaternion(