diff options
Diffstat (limited to 'klippy/extras/adxl345.py')
-rw-r--r-- | klippy/extras/adxl345.py | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/klippy/extras/adxl345.py b/klippy/extras/adxl345.py index 76fd4ca4..b91224d5 100644 --- a/klippy/extras/adxl345.py +++ b/klippy/extras/adxl345.py @@ -187,7 +187,7 @@ def read_axes_map(config): MIN_MSG_TIME = 0.100 BYTES_PER_SAMPLE = 5 -SAMPLES_PER_BLOCK = 10 +SAMPLES_PER_BLOCK = bulk_sensor.MAX_BULK_MSG_SIZE // BYTES_PER_SAMPLE BATCH_UPDATES = 0.100 @@ -205,13 +205,12 @@ class ADXL345: self.mcu = mcu = self.spi.get_mcu() self.oid = oid = mcu.create_oid() self.query_adxl345_cmd = None - self.query_adxl345_status_cmd = None mcu.add_config_cmd("config_adxl345 oid=%d spi_oid=%d" % (oid, self.spi.get_oid())) mcu.add_config_cmd("query_adxl345 oid=%d clock=0 rest_ticks=0" % (oid,), on_restart=True) mcu.register_config_callback(self._build_config) - self.bulk_queue = bulk_sensor.BulkDataQueue(mcu, "adxl345_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) @@ -230,10 +229,8 @@ class ADXL345: cmdqueue = self.spi.get_command_queue() self.query_adxl345_cmd = self.mcu.lookup_command( "query_adxl345 oid=%c clock=%u rest_ticks=%u", cq=cmdqueue) - self.query_adxl345_status_cmd = self.mcu.lookup_query_command( - "query_adxl345_status oid=%c", - "adxl345_status oid=%c clock=%u query_ticks=%u next_sequence=%hu" - " buffered=%c fifo=%c limit_count=%hu", oid=self.oid, cq=cmdqueue) + self.clock_updater.setup_query_command( + self.mcu, "query_adxl345_status oid=%c", oid=self.oid, cq=cmdqueue) def read_reg(self, reg): params = self.spi.spi_transfer([reg | REG_MOD_READ, 0x00]) response = bytearray(params['response']) @@ -286,17 +283,6 @@ class ADXL345: self.clock_sync.set_last_chip_clock(seq * SAMPLES_PER_BLOCK + i) del samples[count:] return samples - def _update_clock(self, minclock=0): - # Query current state - for retry in range(5): - params = self.query_adxl345_status_cmd.send([self.oid], - minclock=minclock) - fifo = params['fifo'] & 0x7f - if fifo <= 32: - break - else: - raise self.printer.command_error("Unable to query adxl345 fifo") - self.clock_updater.update_clock(params) # Start, stop, and process message batches def _start_measurements(self): # In case of miswiring, testing ADXL345 device ID prevents treating @@ -325,8 +311,6 @@ class ADXL345: logging.info("ADXL345 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 @@ -334,7 +318,7 @@ class ADXL345: self.bulk_queue.clear_samples() logging.info("ADXL345 finished '%s' measurements", self.name) 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 {} @@ -342,7 +326,7 @@ class ADXL345: 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 ADXL345(config) |