aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/extras/mpu9250.py10
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)