Skip to content

Commit

Permalink
working quaternion streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhortz committed Jan 14, 2017
1 parent ba80490 commit c56d0ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 5 additions & 3 deletions examples/sensorFusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
23 changes: 22 additions & 1 deletion src/registers/sensorFusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c56d0ae

Please sign in to comment.