diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-12-16 11:30:51 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2023-12-26 11:47:21 -0500 |
commit | e67cbbe5c12bae1deb4651e2b3aa12c3c77c3439 (patch) | |
tree | e59bfdac4e65409b1073a91f021a22ff1c8842ea /klippy/extras/angle.py | |
parent | 978c294741bafac136081f40d066ad2884b1ffce (diff) | |
download | kutter-e67cbbe5c12bae1deb4651e2b3aa12c3c77c3439.tar.gz kutter-e67cbbe5c12bae1deb4651e2b3aa12c3c77c3439.tar.xz kutter-e67cbbe5c12bae1deb4651e2b3aa12c3c77c3439.zip |
bulk_sensor: Add new BulkDataQueue class
Move the bulk sample queue collection to a new helper class in
bulk_sensor.py.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/angle.py')
-rw-r--r-- | klippy/extras/angle.py | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/klippy/extras/angle.py b/klippy/extras/angle.py index 30a4447a..26b9c6f0 100644 --- a/klippy/extras/angle.py +++ b/klippy/extras/angle.py @@ -3,8 +3,8 @@ # Copyright (C) 2021,2022 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. -import logging, math, threading -from . import bus, motion_report +import logging, math +from . import bus, motion_report, bulk_sensor MIN_MSG_TIME = 0.100 TCODE_ERROR = 0xff @@ -417,9 +417,6 @@ class Angle: # Measurement conversion self.start_clock = self.time_shift = self.sample_ticks = 0 self.last_sequence = self.last_angle = 0 - # Measurement storage (accessed from background thread) - self.lock = threading.Lock() - self.raw_samples = [] # Sensor type sensors = { "a1333": HelperA1333, "as5047d": HelperAS5047D, "tle5012b": HelperTLE5012B } @@ -439,8 +436,7 @@ class Angle: "query_spi_angle oid=%d clock=0 rest_ticks=0 time_shift=0" % (oid,), on_restart=True) mcu.register_config_callback(self._build_config) - mcu.register_response(self._handle_spi_angle_data, - "spi_angle_data", oid) + self.bulk_queue = bulk_sensor.BulkDataQueue(mcu, "spi_angle_data", oid) # API server endpoints self.api_dump = motion_report.APIDumpHelper( self.printer, self._api_update, self._api_startstop, 0.100) @@ -464,9 +460,6 @@ class Angle: # Measurement collection def is_measuring(self): return self.start_clock != 0 - def _handle_spi_angle_data(self, params): - with self.lock: - self.raw_samples.append(params) def _extract_samples(self, raw_samples): # Load variables to optimize inner loop below sample_ticks = self.sample_ticks @@ -524,9 +517,7 @@ class Angle: def _api_update(self, eventtime): if self.sensor_helper.is_tcode_absolute: self.sensor_helper.update_clock() - with self.lock: - raw_samples = self.raw_samples - self.raw_samples = [] + raw_samples = self.bulk_queue.pull_samples() if not raw_samples: return {} samples, error_count = self._extract_samples(raw_samples) @@ -541,8 +532,7 @@ class Angle: logging.info("Starting angle '%s' measurements", self.name) self.sensor_helper.start() # Start bulk reading - with self.lock: - self.raw_samples = [] + self.bulk_queue.clear_samples() self.last_sequence = 0 systime = self.printer.get_reactor().monotonic() print_time = self.mcu.estimated_print_time(systime) + MIN_MSG_TIME @@ -557,8 +547,7 @@ class Angle: # Halt bulk reading params = self.query_spi_angle_end_cmd.send([self.oid, 0, 0, 0]) self.start_clock = 0 - with self.lock: - self.raw_samples = [] + self.bulk_queue.clear_samples() self.sensor_helper.last_temperature = None logging.info("Stopped angle '%s' measurements", self.name) def _api_startstop(self, is_start): |