@@ -34,27 +34,24 @@ SHT2x.prototype.checkCrc = function(bytes, bytesLen, checksum) {
34
34
} ;
35
35
36
36
SHT2x . prototype . readTemperature = function ( ) {
37
- print ( "v2 " ) ;
37
+ print ( "v4 " ) ;
38
38
print ( this . addr ) ;
39
39
this . i2c . writeTo ( this . addr , [ 0x2c , 0x06 ] ) ;
40
40
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 ) ;
42
43
print ( result ) ;
43
- this . checkCrc ( result , 2 , result [ 2 ] ) ;
44
+ // this.checkCrc(result, 2, result[2]);
44
45
if ( ! value ) {
45
46
return null ;
46
47
}
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
+ } ;
60
57
} ;
0 commit comments