Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STEAPP-454: added status about trigered filament sensor. #125

Merged
merged 4 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions klippy/extras/print_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

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.reset()
self.gcode = self.printer.lookup_object('gcode')
# 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)
Expand Down Expand Up @@ -64,31 +64,25 @@ def _note_finish(self, state, error_message = ""):
self.init_duration = self.total_duration - \
self.prev_pause_duration
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"
self.prev_pause_duration = self.last_epos = 0.
self.filament_used = self.total_duration = 0.
self.print_start_time = self.last_pause_time = None
self.init_duration = 0.
self.count_trigered_sensor = 0
self.info_total_layer = None
self.info_current_layer = None
def get_status(self, eventtime):
Expand All @@ -112,6 +106,7 @@ def get_status(self, eventtime):
'filament_used': self.filament_used,
'state': self.state,
'message': self.error_message,
'count_trigered_sensor': self.count_trigered_sensor,
'info': {'total_layer': self.info_total_layer,
'current_layer': self.info_current_layer}
}
Expand Down
4 changes: 4 additions & 0 deletions stereotech_config/filament_control_2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ gcode:
variable_enable_offset: 1
variable_enable_prime: 1
variable_enable_second_extruder: 0
variable_count_trigered_sensor: 0
gcode:
{% set sensor = params.SENSOR %}
{% if params.RESET %}
Expand All @@ -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
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=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 %}
Expand Down