Skip to content

Commit

Permalink
Merge pull request #894 from gnarf/aref
Browse files Browse the repository at this point in the history
Complete test conversion for analog controllers and aref
  • Loading branch information
rwaldron committed Aug 26, 2015
2 parents f41da24 + a19f7b8 commit 45ff573
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 75 deletions.
7 changes: 2 additions & 5 deletions lib/temperature.js
Expand Up @@ -301,8 +301,6 @@ var Controllers = {
var adcres = 1023;
// Beta parameter
var beta = 3975;
// 0°C = CELSIUS_TO_KELVIN K
var kelvin = CELSIUS_TO_KELVIN;
// 10 kOhm (sensor resistance)
var rb = 10000;
// Ginf = 1/Rinf
Expand All @@ -311,7 +309,7 @@ var Controllers = {
var tempr = 298.15;

var rthermistor = (adcres - raw) * rb / raw;
var tempc = 1 / (Math.log(rthermistor / rb) / beta + 1 / tempr) - kelvin;
var tempc = 1 / (Math.log(rthermistor / rb) / beta + 1 / tempr) - CELSIUS_TO_KELVIN;

return tempc;
}
Expand All @@ -325,14 +323,13 @@ var Controllers = {
value: function(raw) {
var adcres = 1023;
var beta = 3950;
var kelvin = CELSIUS_TO_KELVIN;
var rb = 10000; // 10 kOhm
var ginf = 120.6685; // Ginf = 1/Rinf

var rthermistor = rb * (adcres / raw - 1);
var tempc = beta / (Math.log(rthermistor * ginf));

return tempc - kelvin;
return tempc - CELSIUS_TO_KELVIN;
}
}
},
Expand Down
126 changes: 56 additions & 70 deletions test/temperature.js
Expand Up @@ -311,6 +311,62 @@ exports["Temperature -- ANALOG"] = {
K: 296
}),
},

GROVE: {
setUp: function(done) {
this.temperature = new Temperature({
controller: "GROVE",
pin: "A0",
freq: 100,
board: this.board
});

done();
},
shape: testShape,
aref: makeTestAnalogConversion({
aref: 3.3,
raw: 659,
C: 39,
F: 102,
K: 312,
}),

data: makeTestAnalogConversion({
raw: 659,
C: 39,
F: 102,
K: 312,
}),
},

TINKERKIT: {
setUp: function(done) {
this.temperature = new Temperature({
controller: "TINKERKIT",
pin: "A0",
freq: 100,
board: this.board
});

done();
},

aref: makeTestAnalogConversion({
aref: 3.3,
raw: 810,
C: 39,
F: 102,
K: 312,
}),

data: makeTestAnalogConversion({
raw: 810,
C: 39,
F: 102,
K: 312,
}),
},
};

function createDS18B20(pin, address) {
Expand Down Expand Up @@ -547,76 +603,6 @@ exports["Temperature -- MPU6050"] = {
}
};


exports["Temperature -- GROVE"] = {

setUp: function(done) {
this.analogRead = this.sandbox.spy(MockFirmata.prototype, "analogRead");
this.temperature = new Temperature({
controller: "GROVE",
pin: "A0",
freq: 100,
board: this.board
});

done();
},

data: function(test) {
var raw = this.analogRead.args[0][1],
spy = this.sandbox.spy();

test.expect(4);
this.temperature.on("data", spy);

raw(659);

this.clock.tick(100);

test.ok(spy.calledOnce);
test.equals(Math.round(spy.args[0][1].celsius), 39);
test.equals(Math.round(spy.args[0][1].fahrenheit), 102);
test.equals(Math.round(spy.args[0][1].kelvin), 312);

test.done();
}
};

exports["Temperature -- TINKERKIT"] = {

setUp: function(done) {
this.analogRead = this.sandbox.spy(MockFirmata.prototype, "analogRead");
this.temperature = new Temperature({
controller: "TINKERKIT",
pin: "A0",
freq: 100,
board: this.board
});

done();
},

data: function(test) {

var raw = this.analogRead.args[0][1],
spy = this.sandbox.spy();

test.expect(4);
this.temperature.on("data", spy);

raw(810);

this.clock.tick(100);

test.ok(spy.calledOnce);
test.equals(Math.round(spy.args[0][1].celsius), 39);
test.equals(Math.round(spy.args[0][1].fahrenheit), 102);
test.equals(Math.round(spy.args[0][1].kelvin), 312);

test.done();
}
};

exports["Temperature -- MPL115A2"] = {

setUp: function(done) {
Expand Down

0 comments on commit 45ff573

Please sign in to comment.