@@ -67,12 +67,10 @@ class SHTC3:
67
67
def __init__ (self , i2c_bus , address = _SHTC3_DEFAULT_ADDR ):
68
68
self .i2c_device = i2c_device .I2CDevice (i2c_bus , address )
69
69
70
- self ._buffer = bytearray (2 )
70
+ self ._buffer = bytearray (3 )
71
71
self .reset ()
72
72
self .sleep = False
73
- read_id = self ._chip_id
74
- print ("got chip_id:" , format (read_id , "#010x" ))
75
- if (read_id & 0x083F != _SHTC3_CHIP_ID ):
73
+ if (self ._chip_id & 0x083F != _SHTC3_CHIP_ID ):
76
74
raise RuntimeError ("Failed to find an ICM20X sensor - check your wiring!" )
77
75
78
76
@@ -81,21 +79,17 @@ def _write_command(self, command):
81
79
self ._buffer [1 ] = command & 0xFF
82
80
83
81
with self .i2c_device as i2c :
84
- i2c .write (self ._buffer )
82
+ i2c .write (self ._buffer , start = 0 , end = 0 )
85
83
86
84
@property
87
85
def _chip_id (self ): # readCommand(SHTC3_READID, data, 3);
88
- out_buf = bytearray (3 )
89
-
90
- self ._write_command (_SHTC3_READID )
86
+ self ._buffer [0 ] = _SHTC3_READID >> 8
87
+ self ._buffer [1 ] = _SHTC3_READID & 0xFF
91
88
92
89
with self .i2c_device as i2c :
93
- i2c .readinto (out_buf )
94
- # i2c.write_then_readinto(self._buffer, self._buffer, out_end=1, in_start=1)
95
- print ("buf in:" , out_buf )
96
- print ("vuf a:" , [hex (i ) for i in list (out_buf )])
90
+ i2c .write_then_readinto (self ._buffer , self ._buffer , out_start = 0 , out_end = 2 , in_start = 0 )
97
91
98
- return unpack_from (">H" , out_buf )[0 ]
92
+ return unpack_from (">H" , self . _buffer )[0 ]
99
93
100
94
101
95
def reset (self ):
0 commit comments