Skip to content

Commit 82e3414

Browse files
committed
cleaned up to use one buffer
1 parent c9f87a6 commit 82e3414

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

adafruit_shtc3.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ class SHTC3:
6767
def __init__(self, i2c_bus, address = _SHTC3_DEFAULT_ADDR):
6868
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
6969

70-
self._buffer = bytearray(2)
70+
self._buffer = bytearray(3)
7171
self.reset()
7272
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):
7674
raise RuntimeError("Failed to find an ICM20X sensor - check your wiring!")
7775

7876

@@ -81,21 +79,17 @@ def _write_command(self, command):
8179
self._buffer[1] = command & 0xFF
8280

8381
with self.i2c_device as i2c:
84-
i2c.write(self._buffer)
82+
i2c.write(self._buffer, start=0, end=0)
8583

8684
@property
8785
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
9188

9289
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)
9791

98-
return unpack_from(">H", out_buf)[0]
92+
return unpack_from(">H", self._buffer)[0]
9993

10094

10195
def reset(self):

0 commit comments

Comments
 (0)