diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-12-17 17:59:25 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2024-01-19 11:55:15 -0500 |
commit | 266e96621c0133e1192bbaec5addb6bcf443a203 (patch) | |
tree | 1f4396874db47db20aa75feb09757204c13b2c98 /klippy/extras/mpu9250.py | |
parent | dc6182f3b339b990c8a68940f02a210e332be269 (diff) | |
download | kutter-266e96621c0133e1192bbaec5addb6bcf443a203.tar.gz kutter-266e96621c0133e1192bbaec5addb6bcf443a203.tar.xz kutter-266e96621c0133e1192bbaec5addb6bcf443a203.zip |
sensor_bulk: New C file with helper code for sending bulk sensor measurements
Refactor the low-level "bulk sensor" management code in the mcu. This
updates the sensor_adxl345.c, sensor_mpu9250.c, sensor_lis2dw.c, and
sensor_angle.c code to use the same "bulk sensor" messages. All of
these sensors will now send "sensor_bulk_data" and
"sensor_bulk_status" messages.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/mpu9250.py')
-rw-r--r-- | klippy/extras/mpu9250.py | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/klippy/extras/mpu9250.py b/klippy/extras/mpu9250.py index 41376dc3..4626e1c0 100644 --- a/klippy/extras/mpu9250.py +++ b/klippy/extras/mpu9250.py @@ -50,7 +50,7 @@ FIFO_SIZE = 512 MIN_MSG_TIME = 0.100 BYTES_PER_SAMPLE = 6 -SAMPLES_PER_BLOCK = 8 +SAMPLES_PER_BLOCK = bulk_sensor.MAX_BULK_MSG_SIZE // BYTES_PER_SAMPLE BATCH_UPDATES = 0.100 @@ -70,9 +70,8 @@ class MPU9250: self.mcu = mcu = self.i2c.get_mcu() self.oid = oid = mcu.create_oid() self.query_mpu9250_cmd = None - self.query_mpu9250_status_cmd = None mcu.register_config_callback(self._build_config) - self.bulk_queue = bulk_sensor.BulkDataQueue(mcu, "mpu9250_data", oid) + 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) @@ -95,10 +94,8 @@ class MPU9250: % (self.oid,), on_restart=True) self.query_mpu9250_cmd = self.mcu.lookup_command( "query_mpu9250 oid=%c clock=%u rest_ticks=%u", cq=cmdqueue) - self.query_mpu9250_status_cmd = self.mcu.lookup_query_command( - "query_mpu9250_status oid=%c", - "mpu9250_status oid=%c clock=%u query_ticks=%u next_sequence=%hu" - " buffered=%c fifo=%u limit_count=%hu", oid=self.oid, cq=cmdqueue) + self.clock_updater.setup_query_command( + self.mcu, "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] @@ -142,11 +139,6 @@ class MPU9250: self.clock_sync.set_last_chip_clock(seq * SAMPLES_PER_BLOCK + i) del samples[count:] return samples - - def _update_clock(self, minclock=0): - params = self.query_mpu9250_status_cmd.send([self.oid], - minclock=minclock) - self.clock_updater.update_clock(params) # Start, stop, and process message batches def _start_measurements(self): # In case of miswiring, testing MPU9250 device ID prevents treating @@ -184,8 +176,6 @@ class MPU9250: logging.info("MPU9250 starting '%s' measurements", self.name) # Initialize clock tracking self.clock_updater.note_start(reqclock) - self._update_clock(minclock=reqclock) - self.clock_updater.clear_duration_filter() self.last_error_count = 0 def _finish_measurements(self): # Halt bulk reading @@ -195,7 +185,7 @@ class MPU9250: self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_SLEEP) self.set_reg(REG_PWR_MGMT_2, SET_PWR_MGMT_2_OFF) def _process_batch(self, eventtime): - self._update_clock() + self.clock_updater.update_clock() raw_samples = self.bulk_queue.pull_samples() if not raw_samples: return {} @@ -203,7 +193,7 @@ class MPU9250: if not samples: return {} return {'data': samples, 'errors': self.last_error_count, - 'overflows': self.clock_updater.get_last_limit_count()} + 'overflows': self.clock_updater.get_last_overflows()} def load_config(config): return MPU9250(config) |