From db3def25e96d40e5a56c81a78f27e1e4ac9a2e23 Mon Sep 17 00:00:00 2001 From: sokolovjek Date: Thu, 18 May 2023 15:17:45 +0100 Subject: [PATCH 1/4] STEAPP-454: added status abaut trigered filament sensor. --- klippy/extras/print_stats.py | 15 +++++++++++---- stereotech_config/filament_control_2.cfg | 8 ++++++++ stereotech_config/print_macros.cfg | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/klippy/extras/print_stats.py b/klippy/extras/print_stats.py index 668cd7d0c860..ffd1bb4696cd 100644 --- a/klippy/extras/print_stats.py +++ b/klippy/extras/print_stats.py @@ -6,15 +6,19 @@ class PrintStats: def __init__(self, config): - printer = config.get_printer() - self.gcode_move = printer.load_object(config, 'gcode_move') - self.reactor = printer.get_reactor() + self.printer = config.get_printer() + self.gcode_move = self.printer.load_object(config, 'gcode_move') + self.reactor = self.printer.get_reactor() + self.save_variables = None self.reset() + self.gcode = self.printer.lookup_object('gcode') + self.printer.register_event_handler("klippy:ready", self._handle_ready) # Register commands - self.gcode = printer.lookup_object('gcode') self.gcode.register_command( "SET_PRINT_STATS_INFO", self.cmd_SET_PRINT_STATS_INFO, desc=self.cmd_SET_PRINT_STATS_INFO_help) + def _handle_ready(self): + self.save_variables = self.printer.lookup_object('save_variables') def _update_filament_usage(self, eventtime): gc_status = self.gcode_move.get_status(eventtime) cur_epos = gc_status['position'].e @@ -63,6 +67,7 @@ def _note_finish(self, state, error_message = ""): # No positive extusion detected during print self.init_duration = self.total_duration - \ self.prev_pause_duration + self.trigered_filament_sensor = self.save_variables.allVariables.get('trigered_filament_sensor', 0) self.print_start_time = None cmd_SET_PRINT_STATS_INFO_help = "Pass slicer info like layer act and " \ "total to klipper" @@ -89,6 +94,7 @@ def reset(self): self.filament_used = self.total_duration = 0. self.print_start_time = self.last_pause_time = None self.init_duration = 0. + self.trigered_filament_sensor = 0. self.info_total_layer = None self.info_current_layer = None def get_status(self, eventtime): @@ -112,6 +118,7 @@ def get_status(self, eventtime): 'filament_used': self.filament_used, 'state': self.state, 'message': self.error_message, + 'trigered_filament_sensor': self.trigered_filament_sensor, 'info': {'total_layer': self.info_total_layer, 'current_layer': self.info_current_layer} } diff --git a/stereotech_config/filament_control_2.cfg b/stereotech_config/filament_control_2.cfg index c4c573239422..ce8bef8f906f 100644 --- a/stereotech_config/filament_control_2.cfg +++ b/stereotech_config/filament_control_2.cfg @@ -31,6 +31,7 @@ gcode: variable_enable_offset: 1 variable_enable_prime: 1 variable_enable_second_extruder: 0 +variable_trigered_filament_sensor: 0 gcode: {% set sensor = params.SENSOR %} {% if params.RESET %} @@ -42,7 +43,10 @@ gcode: SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_offset VALUE=1 SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_prime VALUE=1 SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_second_extruder VALUE=0 + SAVE_VARIABLE VARIABLE=trigered_filament_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].trigered_filament_sensor} + SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE=0 {% else %} + SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].trigered_filament_sensor + 1} {% if printer["gcode_macro RECOVER_EXTRUSION"].enable_offset and printer["gcode_macro RECOVER_EXTRUSION_BY_OFFSET"].checks_made < printer["gcode_macro RECOVER_EXTRUSION_BY_OFFSET"].check_count %} RECOVER_EXTRUSION_BY_OFFSET {% else %} @@ -172,3 +176,7 @@ gcode: SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=extruder_temp VALUE=0 RESUME {% endif %} + +[gcode_macro RESET] +variable_enabled: 0 +gcode: diff --git a/stereotech_config/print_macros.cfg b/stereotech_config/print_macros.cfg index bcd6abd7f416..1e2f4ccc7386 100644 --- a/stereotech_config/print_macros.cfg +++ b/stereotech_config/print_macros.cfg @@ -189,6 +189,7 @@ description: Start Gcode gcode: G21 {% if printer["filament_motion_sensor extruder_sensor"] %} + SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE=0 UPDATE_DELAYED_GCODE ID=TURN_OFF_EXTRUDERS_DELAYED DURATION=0 {% endif %} G90 From a97a4d7c6303bd968d2a972ab6e58c202c9f1837 Mon Sep 17 00:00:00 2001 From: sokolovjek Date: Fri, 19 May 2023 10:13:58 +0100 Subject: [PATCH 2/4] STEAPP-454: added status abaut trigered filament sensor. --- stereotech_config/filament_control_2.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stereotech_config/filament_control_2.cfg b/stereotech_config/filament_control_2.cfg index ce8bef8f906f..90145b892518 100644 --- a/stereotech_config/filament_control_2.cfg +++ b/stereotech_config/filament_control_2.cfg @@ -176,7 +176,3 @@ gcode: SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=extruder_temp VALUE=0 RESUME {% endif %} - -[gcode_macro RESET] -variable_enabled: 0 -gcode: From fe784ba3a77930a04049d4f1a7f74a69c5226f38 Mon Sep 17 00:00:00 2001 From: sokolovjek Date: Fri, 19 May 2023 10:23:30 +0100 Subject: [PATCH 3/4] STEAPP-454: added status abaut trigered filament sensor. --- klippy/extras/print_stats.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/klippy/extras/print_stats.py b/klippy/extras/print_stats.py index ffd1bb4696cd..017d22cc3dba 100644 --- a/klippy/extras/print_stats.py +++ b/klippy/extras/print_stats.py @@ -18,7 +18,10 @@ def __init__(self, config): "SET_PRINT_STATS_INFO", self.cmd_SET_PRINT_STATS_INFO, desc=self.cmd_SET_PRINT_STATS_INFO_help) def _handle_ready(self): - self.save_variables = self.printer.lookup_object('save_variables') + try: + self.save_variables = self.printer.lookup_object('save_variables') + except: + pass def _update_filament_usage(self, eventtime): gc_status = self.gcode_move.get_status(eventtime) cur_epos = gc_status['position'].e @@ -67,7 +70,8 @@ def _note_finish(self, state, error_message = ""): # No positive extusion detected during print self.init_duration = self.total_duration - \ self.prev_pause_duration - self.trigered_filament_sensor = self.save_variables.allVariables.get('trigered_filament_sensor', 0) + if self.save_variables: + self.trigered_filament_sensor = self.save_variables.allVariables.get('trigered_filament_sensor', 0) self.print_start_time = None cmd_SET_PRINT_STATS_INFO_help = "Pass slicer info like layer act and " \ "total to klipper" From b28cb8dbff40ce59f3848e26ad62d69f174321f2 Mon Sep 17 00:00:00 2001 From: sokolovjek Date: Tue, 13 Jun 2023 09:11:21 +0100 Subject: [PATCH 4/4] STEAPP-454: deleted the used module save_variable, and rename the variable. --- klippy/extras/print_stats.py | 38 +++++++----------------- stereotech_config/filament_control_2.cfg | 8 ++--- stereotech_config/print_macros.cfg | 1 - 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/klippy/extras/print_stats.py b/klippy/extras/print_stats.py index 017d22cc3dba..90462a9708a5 100644 --- a/klippy/extras/print_stats.py +++ b/klippy/extras/print_stats.py @@ -9,19 +9,12 @@ def __init__(self, config): self.printer = config.get_printer() self.gcode_move = self.printer.load_object(config, 'gcode_move') self.reactor = self.printer.get_reactor() - self.save_variables = None self.reset() self.gcode = self.printer.lookup_object('gcode') - self.printer.register_event_handler("klippy:ready", self._handle_ready) # Register commands self.gcode.register_command( "SET_PRINT_STATS_INFO", self.cmd_SET_PRINT_STATS_INFO, desc=self.cmd_SET_PRINT_STATS_INFO_help) - def _handle_ready(self): - try: - self.save_variables = self.printer.lookup_object('save_variables') - except: - pass def _update_filament_usage(self, eventtime): gc_status = self.gcode_move.get_status(eventtime) cur_epos = gc_status['position'].e @@ -70,27 +63,18 @@ def _note_finish(self, state, error_message = ""): # No positive extusion detected during print self.init_duration = self.total_duration - \ self.prev_pause_duration - if self.save_variables: - self.trigered_filament_sensor = self.save_variables.allVariables.get('trigered_filament_sensor', 0) self.print_start_time = None - cmd_SET_PRINT_STATS_INFO_help = "Pass slicer info like layer act and " \ - "total to klipper" + cmd_SET_PRINT_STATS_INFO_help = "Set info about current file." def cmd_SET_PRINT_STATS_INFO(self, gcmd): - total_layer = gcmd.get_int("TOTAL_LAYER", self.info_total_layer, \ - minval=0) - current_layer = gcmd.get_int("CURRENT_LAYER", self.info_current_layer, \ - minval=0) - if total_layer == 0: - self.info_total_layer = None - self.info_current_layer = None - elif total_layer != self.info_total_layer: + total_layer = gcmd.get_int("TOTAL_LAYER", 0) + current_layer = gcmd.get_int("CURRENT_LAYER", 0) + count_trigered_sensor = gcmd.get_int("COUNT_TRIGERED_SENSOR", 0) + if total_layer: self.info_total_layer = total_layer - self.info_current_layer = 0 - - if self.info_total_layer is not None and \ - current_layer is not None and \ - current_layer != self.info_current_layer: - self.info_current_layer = min(current_layer, self.info_total_layer) + elif current_layer: + self.info_current_layer = current_layer + elif count_trigered_sensor: + self.count_trigered_sensor = count_trigered_sensor def reset(self): self.filename = self.error_message = "" self.state = "standby" @@ -98,7 +82,7 @@ def reset(self): self.filament_used = self.total_duration = 0. self.print_start_time = self.last_pause_time = None self.init_duration = 0. - self.trigered_filament_sensor = 0. + self.count_trigered_sensor = 0 self.info_total_layer = None self.info_current_layer = None def get_status(self, eventtime): @@ -122,7 +106,7 @@ def get_status(self, eventtime): 'filament_used': self.filament_used, 'state': self.state, 'message': self.error_message, - 'trigered_filament_sensor': self.trigered_filament_sensor, + 'count_trigered_sensor': self.count_trigered_sensor, 'info': {'total_layer': self.info_total_layer, 'current_layer': self.info_current_layer} } diff --git a/stereotech_config/filament_control_2.cfg b/stereotech_config/filament_control_2.cfg index 90145b892518..4951f680fe3e 100644 --- a/stereotech_config/filament_control_2.cfg +++ b/stereotech_config/filament_control_2.cfg @@ -31,7 +31,7 @@ gcode: variable_enable_offset: 1 variable_enable_prime: 1 variable_enable_second_extruder: 0 -variable_trigered_filament_sensor: 0 +variable_count_trigered_sensor: 0 gcode: {% set sensor = params.SENSOR %} {% if params.RESET %} @@ -43,10 +43,10 @@ gcode: SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_offset VALUE=1 SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_prime VALUE=1 SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_second_extruder VALUE=0 - SAVE_VARIABLE VARIABLE=trigered_filament_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].trigered_filament_sensor} - SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE=0 + SET_PRINT_STATS_INFO COUNT_TRIGERED_SENSOR={printer["gcode_macro RECOVER_EXTRUSION"].count_trigered_sensor} + SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=count_trigered_sensor VALUE=0 {% else %} - SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].trigered_filament_sensor + 1} + SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=count_trigered_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].count_trigered_sensor + 1} {% if printer["gcode_macro RECOVER_EXTRUSION"].enable_offset and printer["gcode_macro RECOVER_EXTRUSION_BY_OFFSET"].checks_made < printer["gcode_macro RECOVER_EXTRUSION_BY_OFFSET"].check_count %} RECOVER_EXTRUSION_BY_OFFSET {% else %} diff --git a/stereotech_config/print_macros.cfg b/stereotech_config/print_macros.cfg index 1e2f4ccc7386..bcd6abd7f416 100644 --- a/stereotech_config/print_macros.cfg +++ b/stereotech_config/print_macros.cfg @@ -189,7 +189,6 @@ description: Start Gcode gcode: G21 {% if printer["filament_motion_sensor extruder_sensor"] %} - SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=trigered_filament_sensor VALUE=0 UPDATE_DELAYED_GCODE ID=TURN_OFF_EXTRUDERS_DELAYED DURATION=0 {% endif %} G90