From 6716007420f80afb32cd9dbe95a7f7d161d67de4 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 17 Feb 2020 16:51:00 -0500 Subject: [PATCH] filament_switch_sensor: Minor optimization to note_filament_present() Avoid calling into the OS to obtain the system time if the filament state hasn't changed. Signed-off-by: Kevin O'Connor --- klippy/extras/filament_switch_sensor.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/klippy/extras/filament_switch_sensor.py b/klippy/extras/filament_switch_sensor.py index e1411bd4..4dd4fb8e 100644 --- a/klippy/extras/filament_switch_sensor.py +++ b/klippy/extras/filament_switch_sensor.py @@ -83,18 +83,19 @@ class RunoutHelper: insert = False self.runout_enabled = runout self.insert_enabled = insert - def note_filament_present(self, state): + def note_filament_present(self, is_filament_present): + if is_filament_present == self.filament_present: + return + self.filament_present = is_filament_present eventtime = self.reactor.monotonic() - if (eventtime < self.start_time or state == self.filament_present + if (eventtime < self.start_time or (eventtime - self.last_event_time) < self.event_delay or not self.sensor_enabled or self.event_running): # do not process during the initialization time, duplicates, # during the event delay time, while an event is running, or # when the sensor is disabled - self.filament_present = state return - self.filament_present = state - if state: + if is_filament_present: if self.insert_enabled: # insert detected self.event_running = True