From 941507148256d368ed23375158891a0504646715 Mon Sep 17 00:00:00 2001 From: Arksine Date: Sun, 16 Feb 2020 07:18:56 -0500 Subject: [PATCH] filament_switch_sensor: Execute events using reactor callbacks This removes the possibility of re-entry to callers of note_filament_present(). Signed-off-by: Eric Callahan --- klippy/extras/filament_switch_sensor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/klippy/extras/filament_switch_sensor.py b/klippy/extras/filament_switch_sensor.py index aef1259e..9019b767 100644 --- a/klippy/extras/filament_switch_sensor.py +++ b/klippy/extras/filament_switch_sensor.py @@ -76,6 +76,7 @@ class RunoutHelper: self.gcode.run_script(prefix + template.render() + "\nM400") except Exception: logging.exception("Script running error") + self.event_running = False def set_enable(self, runout, insert): if runout and insert: # both cannot be enabled @@ -93,23 +94,23 @@ class RunoutHelper: self.filament_present = state return self.filament_present = state - self.event_running = True if state: if self.insert_enabled: # insert detected + self.event_running = True self.last_event_time = eventtime logging.info( "Filament Sensor %s: insert event detected, Time %.2f" % (self.name, eventtime)) - self._insert_event_handler(eventtime) + self.reactor.register_callback(self._insert_event_handler) elif self.runout_enabled: # runout detected + self.event_running = True self.last_event_time = eventtime logging.info( "Filament Sensor %s: runout event detected, Time %.2f" % (self.name, eventtime)) - self._runout_event_handler(eventtime) - self.event_running = False + self.reactor.register_callback(self._runout_event_handler) cmd_QUERY_FILAMENT_SENSOR_help = "Query the status of the Filament Sensor" def cmd_QUERY_FILAMENT_SENSOR(self, params): if self.filament_present: