diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-12-17 16:30:11 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2024-01-07 11:59:55 -0500 |
commit | 1a1568c38b7b4e9bd5358eb0125d54652789d4aa (patch) | |
tree | 040e73f567acb54916a17b2cdfcb7cc4cb928eec /klippy/extras | |
parent | b50d6669a8b491edf07602c0528d26abe8985536 (diff) | |
download | kutter-1a1568c38b7b4e9bd5358eb0125d54652789d4aa.tar.gz kutter-1a1568c38b7b4e9bd5358eb0125d54652789d4aa.tar.xz kutter-1a1568c38b7b4e9bd5358eb0125d54652789d4aa.zip |
mpu9250: Fix incorrect use of time.sleep()
It is not valid to call time.sleep() in the host python code (it could
causes glitches in other processing, and it does not ensure there is a
pause between operations on the mcu).
Use minclock instead of time.sleep() to ensure there is a sufficient
pause during chip startup.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r-- | klippy/extras/mpu9250.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/klippy/extras/mpu9250.py b/klippy/extras/mpu9250.py index c975f989..04a33eb2 100644 --- a/klippy/extras/mpu9250.py +++ b/klippy/extras/mpu9250.py @@ -4,7 +4,7 @@ # Copyright (C) 2020-2021 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. -import logging, time +import logging from . import bus, adxl345, bulk_sensor MPU9250_ADDR = 0x68 @@ -167,8 +167,12 @@ class MPU9250: # Setup chip in requested query rate self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_WAKE) self.set_reg(REG_PWR_MGMT_2, SET_PWR_MGMT_2_ACCEL_ON) - time.sleep(20. / 1000) # wait for accelerometer chip wake up - self.set_reg(REG_SMPLRT_DIV, SAMPLE_RATE_DIVS[self.data_rate]) + # Add 20ms pause for accelerometer chip wake up + self.read_reg(REG_DEVID) # Dummy read to ensure queues flushed + systime = self.printer.get_reactor().monotonic() + next_time = self.mcu.estimated_print_time(systime) + 0.020 + self.set_reg(REG_SMPLRT_DIV, SAMPLE_RATE_DIVS[self.data_rate], + minclock=self.mcu.print_time_to_clock(next_time)) self.set_reg(REG_CONFIG, SET_CONFIG) self.set_reg(REG_ACCEL_CONFIG, SET_ACCEL_CONFIG) self.set_reg(REG_ACCEL_CONFIG2, SET_ACCEL_CONFIG2) |