File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -264,18 +264,20 @@ def _write_command(
264
264
data: Optional list of 16-bit values to write
265
265
execution_time: Time to wait after command (seconds)
266
266
"""
267
+
268
+ buffer = struct .pack (">H" , command )
267
269
with self .i2c_device as i2c :
268
270
# Write command (MSB first)
269
- i2c .write (struct .pack (">H" , command ))
270
-
271
- # Write data if provided
272
- if data is not None :
271
+ if data is None :
272
+ i2c .write (buffer )
273
+ else :
273
274
for value in data :
274
275
# Pack 16-bit value
275
276
value_bytes = struct .pack (">H" , value )
276
277
# Calculate and append CRC
277
278
crc = self ._crc8 (value_bytes )
278
- i2c .write (value_bytes + bytes ([crc ]))
279
+ buffer += value_bytes + bytes ([crc ])
280
+ i2c .write (buffer )
279
281
280
282
# Wait for command execution
281
283
time .sleep (execution_time )
You can’t perform that action at this time.
0 commit comments