Skip to content

Commit

Permalink
qmp6988: Fix crash when soft-reset is performed
Browse files Browse the repository at this point in the history
See the inline comment for details.

Signed-off-by: Sebastian Wicki <gandro@gmx.net>
  • Loading branch information
gandro committed Jan 15, 2023
1 parent 937f54b commit fe3ddc3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/qmp6988.py
Expand Up @@ -160,9 +160,20 @@ def __init__(self, i2c, addr=I2C_DEFAULT_ADDR, *,
self.i2c.writeto_mem(self.addr, _QMP6988_IIR, filter)

def reset(self):
self.i2c.writeto_mem(self.addr, _QMP6988_RESET,
try:
self.i2c.writeto_mem(self.addr, _QMP6988_RESET,
bytes([_QMP6988_RESET_VALUE]))
except OSError:
# It seems that that the device immediately resets upon soft-reset
# without finishing the I2C transaction, causing an ETIMEDOUT here.
# Thus, we silently ignore those errors and instead read back the
# the expected value after reset (ensuring that the device is online
# again)
pass
sleep_ms(10)
reset = self.i2c.readfrom_mem(self.addr, _QMP6988_RESET, 1)
if reset != b"\0":
raise RuntimeError("device not ready")

def _measure_prepare(self):
"""
Expand Down

0 comments on commit fe3ddc3

Please sign in to comment.