Skip to content

Commit

Permalink
Multi: HTU21D convert raw bytes to uint16 (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
fivdi authored and rwaldron committed Mar 20, 2017
1 parent 933043b commit e93e8e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/imu.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ var Drivers = {

io.i2cReadOnce(address, register, 2, function(data) {
if (isTemperatureCycle) {
computed.temperature = int16(data[0], data[1]);
computed.temperature = uint16(data[0], data[1]);
} else {
computed.humidity = int16(data[0], data[1]);
computed.humidity = uint16(data[0], data[1]);
}

if (++cycle === 2) {
Expand Down
33 changes: 32 additions & 1 deletion test/hygrometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,39 @@ exports["Hygrometer -- HTU21D"] = {
test.equal(Math.round(this.hygrometer.relativeHumidity), 40);

test.done();
}
},

oneHundredPercentHumidity: function(test) {
test.expect(8);
var readOnce;
var spy = this.sandbox.spy();

this.hygrometer.on("data", spy);

test.equal(this.i2cReadOnce.callCount, 1);
test.equal(this.i2cReadOnce.lastCall.args[0], 0x40);
test.equal(this.i2cReadOnce.lastCall.args[1], 0xE3);

readOnce = this.i2cReadOnce.lastCall.args[3];
readOnce([ 100, 76 ]);
this.clock.tick(10);

test.equal(this.i2cReadOnce.callCount, 2);
test.equal(this.i2cReadOnce.lastCall.args[0], 0x40);
test.equal(this.i2cReadOnce.lastCall.args[1], 0xE5);

// The two numbers in the array passed to readOnce represent the two bytes
// of unsigned 16 bit integer which should convert to approximately 100%
// relative humidity.
// See https://github.com/rwaldron/johnny-five/issues/1278
readOnce = this.i2cReadOnce.lastCall.args[3];
readOnce([ 0xd9, 0 ]);
this.clock.tick(10);

test.equal(spy.callCount, 1);
test.equal(Math.round(this.hygrometer.relativeHumidity), 100);
test.done();
}
};


Expand Down
32 changes: 32 additions & 0 deletions test/thermometer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,38 @@ exports["Thermometer -- HTU21D"] = {
test.equal(spy.callCount, 2);
test.equal(Math.round(this.thermometer.C), 22);

test.done();
},

oneHundredDegreesCelsius: function(test) {
test.expect(8);
var readOnce;
var spy = this.sandbox.spy();

this.thermometer.on("data", spy);

test.equal(this.i2cReadOnce.callCount, 1);
test.equal(this.i2cReadOnce.lastCall.args[0], 0x40);
test.equal(this.i2cReadOnce.lastCall.args[1], 0xE3);

// The two numbers in the array passed to readOnce represent the two bytes
// of unsigned 16 bit integer which should convert to approximately 100
// degrees celsius.
// See https://github.com/rwaldron/johnny-five/issues/1278
readOnce = this.i2cReadOnce.lastCall.args[3];
readOnce([ 0xd5, 0xf0 ]);
this.clock.tick(10);

test.equal(this.i2cReadOnce.callCount, 2);
test.equal(this.i2cReadOnce.lastCall.args[0], 0x40);
test.equal(this.i2cReadOnce.lastCall.args[1], 0xE5);

readOnce = this.i2cReadOnce.lastCall.args[3];
readOnce([ 100, 76 ]);
this.clock.tick(10);

test.equal(spy.callCount, 1);
test.equal(Math.round(this.thermometer.C), 100);
test.done();
}
};
Expand Down

0 comments on commit e93e8e0

Please sign in to comment.