@@ -107,7 +107,7 @@ def __init__(self, i2c_bus, address=0x5A):
107
107
buf = bytearray (1 )
108
108
buf [0 ] = 0xF4
109
109
with self .i2c_device as i2c :
110
- i2c .write (buf , end = 1 , stop = True )
110
+ i2c .write (buf , end = 1 )
111
111
time .sleep (.1 )
112
112
113
113
#make sure there are no errors and we have entered application mode
@@ -132,17 +132,15 @@ def error_code(self):
132
132
buf = bytearray (2 )
133
133
buf [0 ] = 0xE0
134
134
with self .i2c_device as i2c :
135
- i2c .write (buf , end = 1 , stop = False )
136
- i2c .readinto (buf , start = 1 )
135
+ i2c .write_then_readinto (buf , buf , out_end = 1 , in_start = 1 )
137
136
return buf [1 ]
138
137
139
138
def _update_data (self ):
140
139
if self .data_ready :
141
140
buf = bytearray (9 )
142
141
buf [0 ] = _ALG_RESULT_DATA
143
142
with self .i2c_device as i2c :
144
- i2c .write (buf , end = 1 , stop = False )
145
- i2c .readinto (buf , start = 1 )
143
+ i2c .write_then_readinto (buf , buf , out_end = 1 , in_start = 1 )
146
144
147
145
self ._eco2 = (buf [1 ] << 8 ) | (buf [2 ])
148
146
self ._tvoc = (buf [3 ] << 8 ) | (buf [4 ])
@@ -168,8 +166,7 @@ def temperature(self):
168
166
buf = bytearray (5 )
169
167
buf [0 ] = _NTC
170
168
with self .i2c_device as i2c :
171
- i2c .write (buf , end = 1 , stop = False )
172
- i2c .readinto (buf , start = 1 )
169
+ i2c .write_then_readinto (buf , buf , out_end = 1 , in_start = 1 )
173
170
174
171
vref = (buf [1 ] << 8 ) | buf [2 ]
175
172
vntc = (buf [3 ] << 8 ) | buf [4 ]
0 commit comments