Skip to content

Commit bd630c8

Browse files
committed
Multi/Barometer/Thermometer: MPL115A2 requires conversion start command for all reads
Signed-off-by: Rick Waldron <[email protected]>
1 parent 0bf862c commit bd630c8

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

lib/imu.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,22 @@ var Drivers = {
624624

625625
io.i2cConfig(opts);
626626

627+
var readCycle = function() {
628+
io.i2cWrite(address, [this.REGISTER.STARTCONVERSION, 0x00]);
629+
630+
io.i2cReadOnce(address, this.REGISTER.READ, READLENGTH, function(data) {
631+
var padc = uint16(data[0], data[1]) >> 6;
632+
var tadc = uint16(data[2], data[3]) >> 6;
633+
634+
computed.pressure = cof.a0 + (cof.b1 + cof.c12 * tadc) * padc + cof.b2 * tadc;
635+
computed.temperature = tadc;
636+
637+
this.emit("data", computed);
638+
639+
readCycle();
640+
}.bind(this));
641+
}.bind(this);
642+
627643
var pCoefficients = new Promise(function(resolve) {
628644
io.i2cReadOnce(address, this.REGISTER.COEFFICIENTS, 8, function(data) {
629645
var A0 = int16(data[0], data[1]);
@@ -646,19 +662,7 @@ var Drivers = {
646662
}.bind(this));
647663
}.bind(this));
648664

649-
pCoefficients.then(function() {
650-
io.i2cWrite(address, [this.REGISTER.STARTCONVERSION, 0x00]);
651-
652-
io.i2cRead(address, this.REGISTER.READ, READLENGTH, function(data) {
653-
var padc = uint16(data[0], data[1]) >> 6;
654-
var tadc = uint16(data[2], data[3]) >> 6;
655-
656-
computed.pressure = cof.a0 + (cof.b1 + cof.c12 * tadc) * padc + cof.b2 * tadc;
657-
computed.temperature = tadc;
658-
659-
this.emit("data", computed);
660-
}.bind(this));
661-
}.bind(this));
665+
pCoefficients.then(readCycle);
662666
}
663667
},
664668
identifier: {

test/barometer.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ exports["Barometer -- MPL115A2"] = {
55
this.board = newBoard();
66
this.i2cConfig = this.sandbox.spy(MockFirmata.prototype, "i2cConfig");
77
this.i2cWrite = this.sandbox.spy(MockFirmata.prototype, "i2cWrite");
8-
this.i2cRead = this.sandbox.spy(MockFirmata.prototype, "i2cRead");
98
this.i2cReadOnce = this.sandbox.spy(MockFirmata.prototype, "i2cReadOnce");
109

1110
this.barometer = new Barometer({
@@ -69,10 +68,10 @@ exports["Barometer -- MPL115A2"] = {
6968
test.equals(this.i2cWrite.args[0][0], 0x60);
7069
test.deepEqual(this.i2cWrite.args[0][1], [0x12, 0x00]);
7170

72-
test.ok(this.i2cRead.calledOnce);
73-
test.equals(this.i2cRead.args[0][0], 0x60);
74-
test.deepEqual(this.i2cRead.args[0][1], 0x00);
75-
test.equals(this.i2cRead.args[0][2], 4);
71+
test.ok(this.i2cReadOnce.calledTwice);
72+
test.equals(this.i2cReadOnce.lastCall.args[0], 0x60);
73+
test.deepEqual(this.i2cReadOnce.lastCall.args[1], 0x00);
74+
test.equals(this.i2cReadOnce.lastCall.args[2], 4);
7675

7776
// In order to handle the Promise used for initialization,
7877
// there can be no fake timers in this test, which means we

test/thermometer.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,6 @@ exports["Thermometer -- MPL115A2"] = {
839839
setUp: function(done) {
840840
this.i2cConfig = this.sandbox.spy(MockFirmata.prototype, "i2cConfig");
841841
this.i2cWrite = this.sandbox.spy(MockFirmata.prototype, "i2cWrite");
842-
this.i2cRead = this.sandbox.spy(MockFirmata.prototype, "i2cRead");
843842
this.i2cReadOnce = this.sandbox.spy(MockFirmata.prototype, "i2cReadOnce");
844843

845844
this.temperature = new Thermometer({
@@ -899,10 +898,10 @@ exports["Thermometer -- MPL115A2"] = {
899898
test.equals(this.i2cWrite.firstCall.args[0], 0x60);
900899
test.deepEqual(this.i2cWrite.firstCall.args[1], [0x12, 0x00]);
901900

902-
test.ok(this.i2cRead.calledOnce);
903-
test.equals(this.i2cRead.firstCall.args[0], 0x60);
904-
test.deepEqual(this.i2cRead.firstCall.args[1], 0x00);
905-
test.equals(this.i2cRead.firstCall.args[2], 4);
901+
test.ok(this.i2cReadOnce.calledTwice);
902+
test.equals(this.i2cReadOnce.lastCall.args[0], 0x60);
903+
test.deepEqual(this.i2cReadOnce.lastCall.args[1], 0x00);
904+
test.equals(this.i2cReadOnce.lastCall.args[2], 4);
906905

907906
// read = this.i2cRead.args[0][3];
908907

0 commit comments

Comments
 (0)