Skip to content

Commit f9782f6

Browse files
authored
Update SHT3.js
1 parent 27fee8e commit f9782f6

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

SHT3.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,24 @@ SHT2x.prototype.checkCrc = function(bytes, bytesLen, checksum) {
3434
};
3535

3636
SHT2x.prototype.readTemperature = function() {
37-
print("v2");
37+
print("v4");
3838
print(this.addr);
3939
this.i2c.writeTo(this.addr, [0x2c, 0x06]);
4040
var result = this.i2c.readFrom(this.addr, 3);
41-
var value = (result[0] << 8) | (result[1] & ~0x03);
41+
var t = (result[0] << 8) | (result[1] & ~0x03);
42+
var h = (result[3] << 8) | (result[4] & ~0x03);
4243
print(result);
43-
this.checkCrc(result, 2, result[2]);
44+
//this.checkCrc(result, 2, result[2]);
4445
if (!value) {
4546
return null;
4647
}
47-
return -49 + 315 / 65535.0 * value;
48-
};
49-
50-
SHT2x.prototype.readHumidity = function() {
51-
this.i2c.writeTo(this.addr, [0x2c, 0x06]);
52-
var result = this.i2c.readFrom(this.addr, 6);
53-
var value = (result[3] << 8) | (result[4] & ~0x03);
54-
print(result);
55-
//this.checkCrc(result, 2, result[5]);
56-
if (!value) {
57-
return null;
58-
}
59-
return 100 / 65535.0 * value;
48+
var d = new DataView(this.i2c.readFrom(this.addr,6).buffer);
49+
return {
50+
tH: d.getInt8(0,1),
51+
tL: d.getInt8(1,1),
52+
hH: d.getInt16(3,1),
53+
hL: d.getInt8(4,1),
54+
tfV: -49.0 + 315.0 / 65535.0 * t,
55+
hfV: 100.0 / 65535.0 * h
56+
};
6057
};

0 commit comments

Comments
 (0)