From 6999ff6256514474d2a309c76cef18e26acf2969 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 11 Aug 2021 23:29:37 -0400 Subject: [PATCH] motion_report: Add helper tool for internal subscribers of data Add support for internal clients to "subscribe" to data like external clients. Signed-off-by: Kevin O'Connor --- klippy/extras/motion_report.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/klippy/extras/motion_report.py b/klippy/extras/motion_report.py index 439c30c6..575ff588 100644 --- a/klippy/extras/motion_report.py +++ b/klippy/extras/motion_report.py @@ -50,6 +50,11 @@ class APIDumpHelper: template = web_request.get_dict('response_template', {}) self.clients[cconn] = template self._start() + def add_internal_client(self): + cconn = InternalDumpClient() + self.clients[cconn] = {} + self._start() + return cconn def _update(self, eventtime): try: msg = self.data_cb(eventtime) @@ -69,6 +74,23 @@ class APIDumpHelper: cconn.send(tmp) return eventtime + self.update_interval +# An "internal webhooks" wrapper for using APIDumpHelper internally +class InternalDumpClient: + def __init__(self): + self.msgs = [] + self.is_done = False + def get_messages(self): + return self.msgs + def finalize(self): + self.is_done = True + def is_closed(self): + return self.is_done + def send(self, msg): + self.msgs.append(msg) + if len(self.msgs) >= 10000: + # Avoid filling up memory with too many samples + self.finalize() + # Extract stepper queue_step messages class DumpStepper: def __init__(self, printer, mcu_stepper):