aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/bulk_sensor.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2023-12-16 11:30:51 -0500
committerKevin O'Connor <kevin@koconnor.net>2023-12-26 11:47:21 -0500
commite67cbbe5c12bae1deb4651e2b3aa12c3c77c3439 (patch)
treee59bfdac4e65409b1073a91f021a22ff1c8842ea /klippy/extras/bulk_sensor.py
parent978c294741bafac136081f40d066ad2884b1ffce (diff)
downloadkutter-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/bulk_sensor.py')
-rw-r--r--klippy/extras/bulk_sensor.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/klippy/extras/bulk_sensor.py b/klippy/extras/bulk_sensor.py
index 3d76eb6f..15749051 100644
--- a/klippy/extras/bulk_sensor.py
+++ b/klippy/extras/bulk_sensor.py
@@ -3,6 +3,26 @@
# Copyright (C) 2020-2023 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
+import threading
+
+# Helper class to store incoming messages in a queue
+class BulkDataQueue:
+ def __init__(self, mcu, msg_name, oid):
+ # Measurement storage (accessed from background thread)
+ self.lock = threading.Lock()
+ self.raw_samples = []
+ # Register callback with mcu
+ mcu.register_response(self._handle_data, msg_name, oid)
+ def _handle_data(self, params):
+ with self.lock:
+ self.raw_samples.append(params)
+ def pull_samples(self):
+ with self.lock:
+ raw_samples = self.raw_samples
+ self.raw_samples = []
+ return raw_samples
+ def clear_samples(self):
+ self.pull_samples()
# Helper class for chip clock synchronization via linear regression
class ClockSyncRegression: