Skip to content

Commit

Permalink
Merge pull request #790 from scottgonzalez/accelerometer-esplora
Browse files Browse the repository at this point in the history
Accelerometer: Add support for Esplora
  • Loading branch information
rwaldron committed May 18, 2015
2 parents 084b028 + 2b991dd commit f566d8f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lib/accelerometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ var Controllers = {
sensitivity: 66.5
}
},
initialize: {
initialize: {
value: analogInitialize
},
toGravity: {
value: analogToGravity
toGravity: {
value: analogToGravity
}
},
ADXL345: {
Expand Down Expand Up @@ -180,7 +180,7 @@ var Controllers = {
this.board.pinMode(state.sleepPin, 1);
this.board.digitalWrite(state.sleepPin, 1);
}

analogInitialize.call(this, opts, dataHandler);
}
},
Expand All @@ -196,22 +196,29 @@ var Controllers = {
}
}
}
},
ESPLORA: {
DEFAULTS: {
value: {
zeroV: [320, 330, 310],
sensitivity: 170
}
},
initialize: {
value: function(opts, dataHandler) {
opts.pins = [5, 11, 6];
analogInitialize.call(this, opts, dataHandler);
}
},
toGravity: {
value: analogToGravity
}
}
};

// Otherwise known as...
Controllers["MPU-6050"] = Controllers.MPU6050;
Controllers["TINKERKIT"] = Controllers.ANALOG;
Controllers["ADXL335"] = {
DEFAULTS: {
value: {
zeroV: 330,
sensitivity: 66.5
}
},
initialize: { value: analogInitialize },
toGravity: { value: analogToGravity }
};

function ToPrecision(val, precision) {
return +(val).toPrecision(precision);
Expand Down Expand Up @@ -323,7 +330,7 @@ function Accelerometer(opts) {
if (opts.autoCalibrate && sensor.calibration.length < calibrationSize) {
var axisIndex = axes.indexOf(axis);
sensor.calibration.push(value);

if (!Array.isArray(state.zeroV)) {
state.zeroV = [];
}
Expand Down
44 changes: 44 additions & 0 deletions test/accelerometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,47 @@ exports["Accelerometer -- MMA7361"] = {
test.done();
}
};

exports["Accelerometer -- ESPLORA"] = {
setUp: function(done) {
this.clock = sinon.useFakeTimers();
this.analogRead = sinon.spy(board.io, "analogRead");
this.accel = new Accelerometer({
controller: "ESPLORA",
freq: 100,
board: board
});

done();
},

tearDown: function(done) {
this.analogRead.restore();
this.clock.restore();
done();
},

data: function(test) {
var x = this.analogRead.args[0][1];
var y = this.analogRead.args[1][1];
var z = this.analogRead.args[2][1];
var changeSpy = sinon.spy();

test.expect(2);
this.accel.on("change", changeSpy);

x(320);
y(420);
z(230);

this.clock.tick(100);
test.ok(changeSpy.calledThrice);
test.deepEqual(changeSpy.args[2], [{
x: 0,
y: 0.53,
z: -0.47
}]);

test.done();
}
};

0 comments on commit f566d8f

Please sign in to comment.