Skip to content

Commit

Permalink
use full-resolution sensitivity for every range
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Bythell committed Feb 1, 2018
1 parent d3d0607 commit 0a157fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
28 changes: 3 additions & 25 deletions lib/accelerometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ var Controllers = {
initialize: {
value: function(opts, dataHandler) {
var READLENGTH = 6;
var address = opts.address || this.ADDRESSES[0];
var state = priv.get(this);
var address = opts.address || this.ADDRESSES[0];

opts.address = address;

Expand Down Expand Up @@ -224,23 +223,6 @@ var Controllers = {
16: 3
})[opts.range || 2];

/*
Page 4
Sensitivity at Min Typ Max
±2 g, 10-bit resolution 230 256 282
±4 g, 10-bit resolution 115 128 141
±8 g, 10-bit resolution 57 64 71
±16 g, 10-bit resolution 29 32 35
*/
state.sensitivity = [
256,
128,
64,
32,
][range];

state.fdigits = 8 - range;

// Merge the format and range bits to set the DATA_FORMAT
this.io.i2cWrite(address, this.REGISTER.DATA_FORMAT, format | range);

Expand All @@ -258,12 +240,8 @@ var Controllers = {
// From Table 1, page 4
//
// Sensitivity
// ±2 g, 10-bit resolution, 256LSB/g, 0.00390625g/LSB
// ±4 g, 10-bit resolution, 128LSB/g, 0.0078125g/LSB
// ±8 g, 10-bit resolution, 256LSB/g, 0.015625g/LSB
// ±16 g, 10-bit resolution, 256LSB/g, 0.03125g/LSB
var state = priv.get(this);
return toFixed(raw / state.sensitivity, state.fdigits);
// All g-ranges, full resolution, 256LSB/g, 0.00390625g/LSB
return toFixed(raw * 0.00390625, 8);
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions test/accelerometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,11 @@ exports["Accelerometer -- ADXL345"] = {

test.ok(changeSpy.calledOnce);
test.deepEqual(changeSpy.args[0], [{
x: 0.09375,
y: 0.15625,
x: 0.01171875,
y: 0.01953125,
// When this is converted back into a number,
// the trailing 0 is discarded.
z: 7.9375
z: 0.9921875
}]);

test.done();
Expand Down Expand Up @@ -707,11 +707,11 @@ exports["Accelerometer -- ADXL345"] = {

test.ok(changeSpy.calledOnce);
test.deepEqual(changeSpy.args[0], [{
x: 0.046875,
y: 0.078125,
x: 0.01171875,
y: 0.01953125,
// When this is converted back into a number,
// the trailing 0 is discarded.
z: 3.96875
z: 0.9921875
}]);

test.done();
Expand Down

0 comments on commit 0a157fe

Please sign in to comment.