diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2023-12-17 00:15:55 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2023-12-26 11:47:21 -0500 |
commit | c716edafe291a3d32700becfb67cb1504cd6902b (patch) | |
tree | 35a3fe64f505406e4ab11b672a5724a0bcc1a16f /klippy/extras/angle.py | |
parent | 337013459303a220e1c3552583676c35b4800dd0 (diff) | |
download | kutter-c716edafe291a3d32700becfb67cb1504cd6902b.tar.gz kutter-c716edafe291a3d32700becfb67cb1504cd6902b.tar.xz kutter-c716edafe291a3d32700becfb67cb1504cd6902b.zip |
bulk_sensor: Simplify the registration of internal clients in BatchBulkHelper
Previously, the BatchBulkHelper class was designed primarily to
register webhook clients, and internal clients used a wrapper class
that emulated a webhooks client.
Change BatchBulkHelper to support regular internal callbacks, and
introduce a new BatchWebhooksClient class that can translate these
internal callback to webhooks client messages.
This makes it easier to register internal clients that can process the
bulk messages every batch interval.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/angle.py')
-rw-r--r-- | klippy/extras/angle.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/klippy/extras/angle.py b/klippy/extras/angle.py index 0fe053df..b1aa0d96 100644 --- a/klippy/extras/angle.py +++ b/klippy/extras/angle.py @@ -157,8 +157,14 @@ class AngleCalibration: def do_calibration_moves(self): move = self.printer.lookup_object('force_move').manual_move # Start data collection - angle_sensor = self.printer.lookup_object(self.name) - cconn = angle_sensor.start_internal_client() + msgs = [] + is_finished = False + def handle_batch(msg): + if is_finished: + return False + msgs.append(msg) + return True + self.printer.lookup_object(self.name).add_client(handle_batch) # Move stepper several turns (to allow internal sensor calibration) microsteps, full_steps = self.get_microsteps() mcu_stepper = self.mcu_stepper @@ -190,13 +196,12 @@ class AngleCalibration: move(mcu_stepper, .5*rotation_dist + align_dist, move_speed) toolhead.wait_moves() # Finish data collection - cconn.finalize() - msgs = cconn.get_messages() + is_finished = True # Correlate query responses cal = {} step = 0 for msg in msgs: - for query_time, pos in msg['params']['data']: + for query_time, pos in msg['data']: # Add to step tracking while step < len(times) and query_time > times[step][1]: step += 1 @@ -462,8 +467,8 @@ class Angle: "spi_angle_end oid=%c sequence=%hu", oid=self.oid, cq=cmdqueue) def get_status(self, eventtime=None): return {'temperature': self.sensor_helper.last_temperature} - def start_internal_client(self): - return self.batch_bulk.add_internal_client() + def add_client(self, client_cb): + self.batch_bulk.add_client(client_cb) # Measurement decoding def _extract_samples(self, raw_samples): # Load variables to optimize inner loop below |