Skip to content

Commit

Permalink
IMU/Altimeter: Finesse elevations that are below sea level. It's magic.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Oct 16, 2015
1 parent 0f215d0 commit ee2f739
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/imu.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ var Drivers = {
var io = board.io;
var address = opts.address || this.ADDRESSES[0];
var elevation = null;
var offset = 0;
var isPressure = false;

// See http://www.henrylahr.com/?p=99 for implementation approach
Expand All @@ -253,6 +254,11 @@ var Drivers = {
elevation = opts.elevation;
}

if (elevation !== null && elevation <= 0) {
offset = Math.abs(elevation) + 1;
elevation = 1;
}

var waitForReady = function(next) {
io.i2cReadOnce(address, this.REGISTER.STATUS, 1, function(data) {
if (data[0] & this.MASK.STATUS.PRESSURE_DATA_READ) {
Expand Down Expand Up @@ -291,7 +297,7 @@ var Drivers = {
altVal = (m << 8 | c) + fl;
altNow = (altNow * 3 + altVal) / 4;

computed.altitude = altNow;
computed.altitude = altNow - offset;
}

isPressure = !isPressure;
Expand Down

0 comments on commit ee2f739

Please sign in to comment.