From 874dbb1ab2a88c3b122c897a0607835ab3dbfef3 Mon Sep 17 00:00:00 2001 From: Klippy-Tools-Bot Date: Sun, 7 Jul 2024 00:25:46 +0000 Subject: [PATCH] Autogenerated - Upstream 8e41131 --- klippy/.version | 2 +- klippy/extras/bus.py | 3 +++ klippy/extras/sht3x.py | 35 ++++++++++++++++++++++------------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/klippy/.version b/klippy/.version index d469999..9bc414b 100644 --- a/klippy/.version +++ b/klippy/.version @@ -1 +1 @@ -5ffe7af +8e41131 diff --git a/klippy/extras/bus.py b/klippy/extras/bus.py index 5f3add4..2f4e4ab 100644 --- a/klippy/extras/bus.py +++ b/klippy/extras/bus.py @@ -192,6 +192,9 @@ def i2c_write(self, data, minclock=0, reqclock=0): return self.i2c_write_cmd.send([self.oid, data], minclock=minclock, reqclock=reqclock) + def i2c_write_wait_ack(self, data, minclock=0, reqclock=0): + self.i2c_write_cmd.send_wait_ack([self.oid, data], + minclock=minclock, reqclock=reqclock) def i2c_read(self, write, read_len): return self.i2c_read_cmd.send([self.oid, write, read_len]) def i2c_modify_bits(self, reg, clear_bits, set_bits, diff --git a/klippy/extras/sht3x.py b/klippy/extras/sht3x.py index 699d3f2..5a8785e 100644 --- a/klippy/extras/sht3x.py +++ b/klippy/extras/sht3x.py @@ -27,6 +27,13 @@ 'LOW_REP': [0x24, 0x16], }, }, + 'PERIODIC': { + '2HZ': { + 'HIGH_REP': [0x22, 0x36], + 'MED_REP': [0x22, 0x20], + 'LOW_REP': [0x22, 0x2B], + }, + }, 'OTHER': { 'STATUS': { 'READ': [0xF3, 0x2D], @@ -72,10 +79,12 @@ def get_report_time_delta(self): def _init_sht3x(self): # Device Soft Reset - self.i2c.i2c_write(SHT3X_CMD['OTHER']['SOFTRESET']) - - # Wait 2ms after reset - self.reactor.pause(self.reactor.monotonic() + .02) + self.i2c.i2c_write_wait_ack(SHT3X_CMD['OTHER']['BREAK']) + # Break takes ~ 1ms + self.reactor.pause(self.reactor.monotonic() + .0015) + self.i2c.i2c_write_wait_ack(SHT3X_CMD['OTHER']['SOFTRESET']) + # Wait <=1.5ms after reset + self.reactor.pause(self.reactor.monotonic() + .0015) status = self.i2c.i2c_read(SHT3X_CMD['OTHER']['STATUS']['READ'], 3) response = bytearray(status['response']) @@ -86,17 +95,17 @@ def _init_sht3x(self): if self._crc8(status) != checksum: logging.warning("sht3x: Reading status - checksum error!") + # Enable periodic mode + self.i2c.i2c_write_wait_ack( + SHT3X_CMD['PERIODIC']['2HZ']['HIGH_REP'] + ) + # Wait <=15.5ms for first measurment + self.reactor.pause(self.reactor.monotonic() + .0155) + def _sample_sht3x(self, eventtime): try: - # Read Temeprature - params = self.i2c.i2c_write( - SHT3X_CMD['MEASURE']['STRETCH_ENABLED']['HIGH_REP'] - ) - # Wait - self.reactor.pause(self.reactor.monotonic() - + .20) - - params = self.i2c.i2c_read([], 6) + # Read measurment + params = self.i2c.i2c_read(SHT3X_CMD['OTHER']['FETCH'], 6) response = bytearray(params['response']) rtemp = response[0] << 8