Skip to content

Commit

Permalink
STEAPP-453: added WARNING log for macros. (#123)
Browse files Browse the repository at this point in the history
* STEAPP-453-WIP:added new function for logging warning meassage.

* STEAPP-453:added "WARNING" loging.

* STEAPP-453: added WARNING loging for macros.

---------

Co-authored-by: Ilya Gushchin <[email protected]>
  • Loading branch information
SokolovJek and frylock34 authored May 29, 2023
1 parent 91a5b84 commit c687959
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"${workspaceFolder}/HTE530-5-4-22.cfg",
"-v",
"-a",
"/tmp/klipper_uds"
"/tmp/klipper_uds",
// "-l",
// "/tmp/dev_klipper_log.log"
]
}
]
Expand Down
4 changes: 4 additions & 0 deletions klippy/extras/gcode_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def _action_stop_for_power_off(self, msg="action_stop_for_power_off"):
def _action_respond_info(self, msg):
self.printer.lookup_object('gcode').respond_info(msg)
return ""
def _action_respond_warning(self, msg):
self.printer.lookup_object('gcode').respond_warning(msg)
return ""
def _action_raise_error(self, msg):
raise self.printer.command_error(msg)
def _action_call_remote_method(self, method, **kwargs):
Expand All @@ -115,6 +118,7 @@ def create_template_context(self, eventtime=None):
'printer': GetStatusWrapper(self.printer, eventtime),
'action_emergency_stop': self._action_emergency_stop,
'action_respond_info': self._action_respond_info,
'action_respond_warning': self._action_respond_warning,
'action_raise_error': self._action_raise_error,
'action_call_remote_method': self._action_call_remote_method,
'action_stop_for_power_off': self._action_stop_for_power_off
Expand Down
4 changes: 4 additions & 0 deletions klippy/gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def respond_info(self, msg, log=True):
logging.info(msg)
lines = [l.strip() for l in msg.strip().split('\n')]
self.respond_raw("// " + "\n// ".join(lines))
def respond_warning(self, msg):
logging.warning(msg)
lines = msg.strip().split('\n')
self.respond_info("\n".join(lines), log=False)
def _respond_error(self, msg):
logging.warning(msg)
lines = msg.strip().split('\n')
Expand Down
36 changes: 18 additions & 18 deletions stereotech_config/filament_control.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
M117 trigered_filament_sensor0
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder0.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder0.')}
PAUSE TURN_OFF_EXTRUDERS=0 E=0
M400
SET_STATE_TRY_EXTRUDE_FILAMENT SENSOR='extruder_sensor' ENABLE=1
Expand All @@ -31,7 +31,7 @@ gcode:
M400
EXTRUDE_WITH_COOLING_AND_HEATING SENSOR={sensor}
{% else %}
{action_respond_info('Extruder not heat enough!')}
{action_respond_warning('Extruder not heat enough!')}
{% endif %}

[gcode_macro FILAMENT_ERROR]
Expand All @@ -53,12 +53,12 @@ gcode:
{% set sensor = params.SENSOR %}
{% set filament_detected = printer['filament_motion_sensor ' ~ sensor].filament_detected %}
{% if filament_detected %}
{action_respond_info('Extruding attempt completed successfully, resuming printing.')}
{action_respond_warning('Extruding attempt completed successfully, resuming printing.')}
M117 resume_after_trigered_sensor
RESUME
{% else %}
M117 all_attempt_extrude_failed
{action_respond_info('All extruding attempt completed failed.')}
M117 failed_try_do_extrude
{action_respond_warning('All extruding attempt completed failed.')}
{% if sensor == 'extruder_sensor' %}
SET_GCODE_VARIABLE MACRO=CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=triggered_extruder VALUE=0
{% elif sensor == 'extruder1_sensor' %}
Expand All @@ -72,10 +72,10 @@ gcode:
; checking the printer state is pause, maybe user resumed printing
{% if printer.pause_resume.is_paused %}
{% if printer["gcode_macro CONTINUE_PRINT_WITH_EXTRUDER"].enabled|int > 0 %}
{action_respond_info('Function "continue printing with another extruder" is enabled')}
{action_respond_warning('Function "continue printing with another extruder" is enabled')}
CONTINUE_PRINT_WITH_EXTRUDER
{% else %}
{action_respond_info('Function "continue printing with another extruder" is disabled. Turn off all extruder')}
{action_respond_warning('Function "continue printing with another extruder" is disabled. Turn off all extruder')}
TURN_OFF_EXTRUDERS
{% endif %}
{% endif %}
Expand All @@ -88,20 +88,20 @@ gcode:
{% if printer.pause_resume.is_paused and printer["filament_motion_sensor extruder1_sensor"] %}
{% set triggered_extruder = printer["gcode_macro CONTINUE_PRINT_WITH_EXTRUDER"].triggered_extruder|int %}
{% if triggered_extruder == 0 %}
{action_respond_info('Printing continued with extruder 2.')}
{action_reaction_respond_warningspond_info('Printing continued with extruder 2.')}
M117 resume_print_another_extruder
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=current_extruder VALUE=1
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=extruder1_temp VALUE={printer["gcode_macro PAUSE"].extruder_temp}
SET_GCODE_VARIABLE MACRO=PAUSE VARIABLE=extruder_temp VALUE=0
SET_GCODE_VARIABLE MACRO=SET_CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=needed_set VALUE=1
RESUME
{% elif triggered_extruder == 1 %}
{action_respond_info('Continue printing with extruder0 fails because this function is not available.')}
{action_respond_info('Turn off all extruder')}
{action_respond_warning('Continue printing with extruder0 fails because this function is not available.')}
{action_respond_warning('Turn off all extruder')}
TURN_OFF_EXTRUDERS
SET_GCODE_VARIABLE MACRO=CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=triggered_extruder VALUE=-1
{% else %}
{action_respond_info('Turn off all extruder')}
{action_respond_warning('Turn off all extruder')}
TURN_OFF_EXTRUDERS
{% endif %}
{% endif %}
Expand All @@ -110,14 +110,14 @@ gcode:
variable_needed_reset: 0
gcode:
{% if printer["gcode_macro RESET_CONTINUE_PRINT_WITH_EXTRUDER"].needed_reset > 0 %}
{action_respond_info('Reset offset.')}
{action_respond_warning('Reset offset.')}
SET_GCODE_OFFSET X_ADJUST=25.0 MOVE=1
ENABLE_CONSTRAIN ENABLE=0
SET_GCODE_VARIABLE MACRO=SET_CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=needed_set VALUE=1
SET_GCODE_VARIABLE MACRO=RESET_CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=needed_reset VALUE=0
{% endif %}
{% if params.RESET_VARIABLES|default(0) > 0 %}
{action_respond_info('Reset variable.')}
{action_respond_warning('Reset variable.')}
SET_GCODE_VARIABLE MACRO=CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=enabled VALUE=0
SET_GCODE_VARIABLE MACRO=CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=triggered_extruder VALUE=-1
SET_GCODE_VARIABLE MACRO=SET_CONTINUE_PRINT_WITH_EXTRUDER VARIABLE=needed_set VALUE=0
Expand All @@ -128,7 +128,7 @@ gcode:
variable_needed_set: 0
gcode:
{% if printer["gcode_macro SET_CONTINUE_PRINT_WITH_EXTRUDER"].needed_set|int > 0 %}
{action_respond_info('An offset is set to continue printing on another extruder.')}
{action_respond_warning('An offset is set to continue printing on another extruder.')}
SET_GCODE_OFFSET X_ADJUST=-25.0 MOVE=1
;if an offset is added, movement beyond coord_min is possible, you need to enable the coordinate limit for movement in the tolhead module
ENABLE_CONSTRAIN ENABLE=1
Expand All @@ -140,7 +140,7 @@ gcode:
description: Trying to extrude the filament.
gcode:
{% for attempt in range(printer["gcode_macro TRY_DO_EXTRUDE"].retries_count|int) %}
{action_respond_info('Attempt to extrude the filament.')}
{action_respond_warning('Attempt to extrude the filament.')}
G91
G0 E25 F600
G90
Expand All @@ -152,16 +152,16 @@ gcode:
{% set sensor = params.SENSOR %}
{% set filament_detected = printer['filament_motion_sensor ' ~ sensor].filament_detected %}
{% if not filament_detected %}
{action_respond_info('Attempt to extrude the filament is failed.')}
{action_respond_warning('Attempt to extrude the filament is failed.')}
{% if sensor == 'extruder_sensor' %}
{action_respond_info('Cooling and heat extruder0.')}
{action_respond_warning('Cooling and heat extruder0.')}
{% set temp_extruder = printer["gcode_macro PAUSE"].extruder_temp|int %}
M117 cooling_extruder
M109 T0 S50
M117 heat_extruder
M109 T0 S{temp_extruder}
{% elif sensor == 'extruder1_sensor' %}
{action_respond_info('Cooling and heat extruder1.')}
{action_respond_warning('Cooling and heat extruder1.')}
{% set temp_extruder = printer["gcode_macro PAUSE"].extruder1_temp|int %}
M117 cooling_extruder
M109 T1 S50
Expand Down
9 changes: 7 additions & 2 deletions stereotech_config/filament_control_2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
M117 trigered_filament_sensor0
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder0.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder0.')}
RECOVER_EXTRUSION SENSOR='extruder_sensor'
{% else %}
FILAMENT_ERROR EXTRUDER=extruder
Expand Down Expand Up @@ -44,6 +44,7 @@ gcode:
SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_second_extruder VALUE=0
{% else %}
{% 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 %}
{action_respond_warning('Recover extrusion by offset %s' % printer["gcode_macro RECOVER_EXTRUSION_BY_OFFSET"].checks_made)}
RECOVER_EXTRUSION_BY_OFFSET
{% else %}
{% if printer["gcode_macro RECOVER_EXTRUSION"].enable_offset %}
Expand All @@ -64,10 +65,12 @@ gcode:
RECOVER_EXTRUSION_BY_SECOND_EXTRUDER
{% else %}
{% if printer["gcode_macro RECOVER_EXTRUSION"].enable_second_extruder and sensor == 'extruder_sensor' %}
{action_respond_warning('Switch to second extruder and resume printing.')}
RECOVER_EXTRUSION_BY_SECOND_EXTRUDER RESET=1
SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_second_extruder VALUE=0
{% endif %}
#Set timeout and wait for user
{action_respond_warning('All attempt to extrude failed.')}
M117 all_attempt_extrude_failed
UPDATE_DELAYED_GCODE ID=TURN_OFF_EXTRUDERS_DELAYED DURATION=300
SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=enable_offset VALUE=1
Expand Down Expand Up @@ -119,6 +122,7 @@ gcode:
{% if printer["gcode_macro RECOVER_EXTRUSION_BY_PRIME"].use_cooldown and printer["gcode_macro RECOVER_EXTRUSION_BY_PRIME"].checks_made >= printer["gcode_macro RECOVER_EXTRUSION_BY_PRIME"].check_count %}
{% set extruder_temp = printer["gcode_macro PAUSE"].extruder_temp if extruder == 'extruder' else printer["gcode_macro PAUSE"].extruder1_temp %}
M117 cooling_extruder
{action_respond_warning('Recover extrusion after cooling and heating.')}
M106 S255
M109 S50
M107
Expand All @@ -133,6 +137,7 @@ gcode:
SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION_BY_PRIME VARIABLE=use_cooldown VALUE=0
CHECK_FILAMENT_MOTION_SENSOR SENSOR={sensor}
{% else %}
{action_respond_warning('Recover extrusion do extrude attempt %s' % printer["gcode_macro RECOVER_EXTRUSION_BY_PRIME"].checks_made)}
M117 try_do_extrude_{printer["gcode_macro RECOVER_EXTRUSION_BY_PRIME"].checks_made + 1}
M400
G4 P3000
Expand All @@ -150,7 +155,7 @@ gcode:
{% set sensor = params.SENSOR %}
{% set filament_detected = printer['filament_motion_sensor ' ~ sensor].filament_detected %}
{% if filament_detected %}
{action_respond_info('Extruding attempt completed successfully, resuming printing.')}
{action_respond_warning('Extruding attempt completed successfully, resuming printing.')}
M117 resume_after_trigered_sensor
RESUME
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion stereotech_config/filament_control_second.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
M117 trigered_filament_sensor1
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder2.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder2.')}
PAUSE TURN_OFF_EXTRUDERS=0 E=0
M400
SET_STATE_TRY_EXTRUDE_FILAMENT SENSOR='extruder1_sensor' ENABLE=1
Expand Down
2 changes: 1 addition & 1 deletion stereotech_config/filament_control_second_2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
M117 trigered_filament_sensor1
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder2.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder2.')}
RECOVER_EXTRUSION SENSOR='extruder1_sensor'
{% else %}
FILAMENT_ERROR EXTRUDER=extruder1
Expand Down
4 changes: 2 additions & 2 deletions stereotech_config/homing.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ gcode:
CUT_FIBER
G1 E-{e} F1200
{% else %}
{action_respond_info("Extruder not hot enough")}
{action_respond_warning("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G1 Z{z_safe} F3600
G90
G1 X{x} Y{y} F3600
{% else %}
{action_respond_info("Printer not homed")}
{action_respond_warning("Printer not homed")}
{% endif %}
6 changes: 3 additions & 3 deletions stereotech_config/print_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ gcode:
CUT_FIBER
G1 E-{e} F1200
{% else %}
{action_respond_info("Extruder not hot enough")}
{action_respond_warning("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G1 Z{z_safe} F3600
G90
G1 X{x} Y{y} F3600
{% else %}
{action_respond_info("Printer not homed")}
{action_respond_warning("Printer not homed")}
{% endif %}
M106 S0

Expand All @@ -88,7 +88,7 @@ gcode:
G1 E{e} F1800
PRIME_FIBER
{% else %}
{action_respond_info("Extruder not hot enough")}
{action_respond_warning("Extruder not hot enough")}
{% endif %}
G90
SET_IDLE_TIMEOUT TIMEOUT=600
Expand Down
2 changes: 1 addition & 1 deletion stereotech_config/v6/filament_control.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ switch_pin: filament_control_1
pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder 1.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder 1.')}
# PAUSE TURN_OFF_EXTRUDERS=0 E=0
{% else %}
FILAMENT_ERROR EXTRUDER=extruder
Expand Down
2 changes: 1 addition & 1 deletion stereotech_config/v6/filament_control_second.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ switch_pin: filament_control_2
pause_on_runout: False
runout_gcode:
{% if printer.virtual_sdcard.is_active %}
{action_respond_info('The filament has run out or there is a problem with its supply at the Extruder 2.')}
{action_respond_warning('The filament has run out or there is a problem with its supply at the Extruder 2.')}
# PAUSE TURN_OFF_EXTRUDERS=0 E=0
{% else %}
FILAMENT_ERROR EXTRUDER=extruder1
Expand Down

0 comments on commit c687959

Please sign in to comment.