From e67cbbe5c12bae1deb4651e2b3aa12c3c77c3439 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 16 Dec 2023 11:30:51 -0500 Subject: 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 --- klippy/extras/bulk_sensor.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'klippy/extras/bulk_sensor.py') 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 # # 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: -- cgit v1.2.3-70-g09d2