aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/mpu9250.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-04-13 21:02:04 -0400
committerKevin O'Connor <kevin@koconnor.net>2024-04-20 12:52:47 -0400
commit9ceaae3847b4bb87f0e894d6133995f7a07b21bf (patch)
tree3e24461ea90fb3495ac719328efe81a16c3290e7 /klippy/extras/mpu9250.py
parent56829b07d2428abf199bac55cec499286eab5c6e (diff)
downloadkutter-9ceaae3847b4bb87f0e894d6133995f7a07b21bf.tar.gz
kutter-9ceaae3847b4bb87f0e894d6133995f7a07b21bf.tar.xz
kutter-9ceaae3847b4bb87f0e894d6133995f7a07b21bf.zip
bulk_sensor: Refactor ChipClockUpdater constructor
Build the clock_sync and struct.Struct() in the ChipClockUpdater constructor. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/mpu9250.py')
-rw-r--r--klippy/extras/mpu9250.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/klippy/extras/mpu9250.py b/klippy/extras/mpu9250.py
index 492131ae..abc7911a 100644
--- a/klippy/extras/mpu9250.py
+++ b/klippy/extras/mpu9250.py
@@ -52,9 +52,6 @@ SCALE = 0.000244140625 * FREEFALL_ACCEL
FIFO_SIZE = 512
-BYTES_PER_SAMPLE = 6
-SAMPLES_PER_BLOCK = bulk_sensor.MAX_BULK_MSG_SIZE // BYTES_PER_SAMPLE
-
BATCH_UPDATES = 0.100
# Printer class that controls MPU9250 chip
@@ -77,9 +74,8 @@ class MPU9250:
self.bulk_queue = bulk_sensor.BulkDataQueue(mcu, oid=oid)
# Clock tracking
chip_smooth = self.data_rate * BATCH_UPDATES * 2
- self.clock_sync = bulk_sensor.ClockSyncRegression(mcu, chip_smooth)
- self.clock_updater = bulk_sensor.ChipClockUpdater(self.clock_sync,
- BYTES_PER_SAMPLE)
+ self.clock_updater = bulk_sensor.ChipClockUpdater(mcu, chip_smooth,
+ ">hhh")
self.last_error_count = 0
# Process messages in batches
self.batch_bulk = bulk_sensor.BatchBulkHelper(
@@ -97,8 +93,8 @@ class MPU9250:
% (self.oid,), on_restart=True)
self.query_mpu9250_cmd = self.mcu.lookup_command(
"query_mpu9250 oid=%c rest_ticks=%u", cq=cmdqueue)
- self.clock_updater.setup_query_command(
- self.mcu, "query_mpu9250_status oid=%c", oid=self.oid, cq=cmdqueue)
+ self.clock_updater.setup_query_command("query_mpu9250_status oid=%c",
+ oid=self.oid, cq=cmdqueue)
def read_reg(self, reg):
params = self.i2c.i2c_read([reg], 1)
return bytearray(params['response'])[0]
@@ -111,7 +107,7 @@ class MPU9250:
# Measurement decoding
def _extract_samples(self, raw_samples):
# Convert messages to samples
- samples = self.clock_updater.extract_samples(">hhh", raw_samples)
+ samples = self.clock_updater.extract_samples(raw_samples)
# Convert samples
(x_pos, x_scale), (y_pos, y_scale), (z_pos, z_scale) = self.axes_map
count = 0