@@ -118,7 +118,8 @@ def __init__(self, i2c_bus):
118
118
self .low_power = False
119
119
self .sleeping = False
120
120
self .reset ()
121
- if self ._chip_id & 0x083F != _SHTC3_CHIP_ID :
121
+ self ._chip_id = self ._get_chip_id ()
122
+ if self ._chip_id != _SHTC3_CHIP_ID :
122
123
raise RuntimeError ("Failed to find an SHTC3 sensor - check your wiring!" )
123
124
124
125
def _write_command (self , command ):
@@ -129,18 +130,14 @@ def _write_command(self, command):
129
130
with self .i2c_device as i2c :
130
131
i2c .write (self ._buffer , start = 0 , end = 2 )
131
132
132
- @property
133
- def _chip_id (self ): # readCommand(SHTC3_READID, data, 3);
133
+ def _get_chip_id (self ): # readCommand(SHTC3_READID, data, 3);
134
134
"""Determines the chip id of the sensor"""
135
- self ._buffer [0 ] = _SHTC3_READID >> 8
136
- self ._buffer [1 ] = _SHTC3_READID & 0xFF
137
-
135
+ self ._write_command (_SHTC3_READID )
136
+ time .sleep (0.001 )
138
137
with self .i2c_device as i2c :
139
- i2c .write_then_readinto (
140
- self ._buffer , self ._buffer , out_start = 0 , out_end = 2 , in_start = 0 , in_end = 2
141
- )
138
+ i2c .readinto (self ._buffer )
142
139
143
- return unpack_from (">H" , self ._buffer )[0 ]
140
+ return unpack_from (">H" , self ._buffer )[0 ] & 0x083F
144
141
145
142
def reset (self ):
146
143
"""Perform a soft reset of the sensor, resetting all settings to their power-on defaults"""
0 commit comments