Skip to content

Commit

Permalink
Autogenerated - Upstream 8e41131
Browse files Browse the repository at this point in the history
  • Loading branch information
Klippy-Tools-Bot committed Jul 7, 2024
1 parent f9c93c6 commit 874dbb1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion klippy/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5ffe7af
8e41131
3 changes: 3 additions & 0 deletions klippy/extras/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 22 additions & 13 deletions klippy/extras/sht3x.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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'])
Expand All @@ -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
Expand Down

0 comments on commit 874dbb1

Please sign in to comment.