diff --git a/config/filament_sensors.cfg b/config/filament_sensors.cfg index 245fcd9..aeb2afc 100644 --- a/config/filament_sensors.cfg +++ b/config/filament_sensors.cfg @@ -23,6 +23,30 @@ # * 'T' - the integer index of the extruder # * 'LAST_PRESET' - the filament preset that was previously assigned to the extruder, if any +[gcode_macro QUERY_FILAMENT] +description: Prompts the user to select a filament, and sets the value of filament_extruder to that filament +gcode: + {% set response = params.RESPONSE|default(False) %} + {% set name = params.NAME|default(False) %} + {% set return_macro = params.RETURN_MACRO|default(False) %} + + {% if not response %} + RESPOND TYPE=command MSG="action:prompt_begin Select Filament" + {% for filament_name in printer.filaments.presets|map(attribute='name',default='None') %} + RESPOND TYPE=command MSG="action:prompt_button {filament_name}|QUERY_FILAMENT {rawparams} NAME={filament_name} RESPONSE=True|primary" + {% endfor %} + RESPOND TYPE=command MSG="action:prompt_show" + {% else %} + # close the dialog + RESPOND TYPE=command MSG="action:prompt_end" + SET_EXTRUDER_FILAMENT NAME={name} + # if we've specified a return macro, run this next. + {% if return_macro %} + {return_macro} + {% endif %} + {% endif %} + + [gcode_macro UNPRIME_FILAMENT] description: Unprimes the filament, leaving it in a state where it can be unloaded without changing temperatures gcode: @@ -30,26 +54,31 @@ {% set unload = params.UNLOAD|default(False) %} {% if svv.filament_load_state == "primed" %} - SET_FILAMENT_LOAD_STATE STATE="processing" - - # tell the end macro wether to call the unload macro after this - SET_GCODE_VARIABLE MACRO=END_UNPRIME_FILAMENT VARIABLE=unload VALUE={unload} - # If the extruder was cold, keep it cold after finishing. - SET_GCODE_VARIABLE MACRO=END_UNPRIME_FILAMENT VARIABLE=etemp VALUE={printer['extruder'].target} - - # set temperature of extruder - # if in auto mode, set temperature and wait. Otherwise wait for the set temperature if it it's above 25c. - {% if svv.heater_mode == "auto" %} - SET_TEMPERATURE_AND_WAIT HEATER=extruder TARGET={printer['extruder'].filament.extruder} MODE=auto - {% elif printer['extruder'].target > 25 %} - TEMPERATURE_WAIT SENSOR=extruder MINIMUM={printer['extruder'].target|float - 1} MAXIMUM={printer['extruder'].target|float + 2} + # check if there is a valid value for the currently loaded filament. if not, prompt the user for it. + {% if not svv.filament_extruder in printer.filaments.presets|map(attribute='name',default='yeet') %} + # if there isn't a set loaded filament, run QUERY_FILAMENT + {% else %} + QUERY_FILAMENT RETURN_MACRO=LOAD_FILAMENT + SET_FILAMENT_LOAD_STATE STATE="processing" + + # tell the end macro wether to call the unload macro after this + SET_GCODE_VARIABLE MACRO=END_UNPRIME_FILAMENT VARIABLE=unload VALUE={unload} + # If the extruder was cold, keep it cold after finishing. + SET_GCODE_VARIABLE MACRO=END_UNPRIME_FILAMENT VARIABLE=etemp VALUE={printer['extruder'].target} + + # set temperature of extruder + # if in auto mode, set temperature and wait. Otherwise wait for the set temperature if it it's above 25c. + {% if svv.heater_mode == "auto" %} + SET_TEMPERATURE_AND_WAIT HEATER=extruder TARGET={printer['extruder'].filament.extruder} MODE=auto + {% elif printer['extruder'].target > 25 %} + TEMPERATURE_WAIT SENSOR=extruder MINIMUM={printer['extruder'].target|float - 1} MAXIMUM={printer['extruder'].target|float + 2} + {% endif %} + + # run the loop to retract until the switch is no longer pressed + M83 # relative extruder moves + UPDATE_DELAYED_GCODE ID=LOOP_UNPRIME_FILAMENT DURATION=0.15 + # retract filament until the button is no longer pressed {% endif %} - - # run the loop to retract until the switch is no longer pressed - M83 # relative extruder moves - UPDATE_DELAYED_GCODE ID=LOOP_UNPRIME_FILAMENT DURATION=0.15 - # retract filament until the button is no longer pressed - {% else %} {action_respond_info("unable to unprime filament. Current filament state: %s " %(svv.filament_load_state))} {% endif %} @@ -112,36 +141,32 @@ [gcode_macro LOAD_FILAMENT] # loads filament after it has been detected in the entry sensor or manually triggered gcode: + {% set svv = printer.save_variables.variables %} {% set prompt = params.PROMPT|default(False) %}M84 E {% set prime = params.PRIME|default(False) %} - # tell the end macro wether to call the unload macro after this + # tell the end macro wether to call the prime macro after this SET_GCODE_VARIABLE MACRO=END_LOAD_FILAMENT VARIABLE=prime VALUE={prime} - - # prompt user for filament types: - {% if prompt %} - RESPOND TYPE=command MSG="action:prompt_end" - {% endif %} - # check if the given thing matches the other thing - {% if not params.NAME in printer.filaments.presets|map(attribute='name',default='None') %} - # if the thing doesnt match the thing then prompt the user and call the macro again - RESPOND TYPE=command MSG="action:prompt_begin Load Filament" - RESPOND TYPE=command MSG="action:prompt_text Select filament" - {% for filament_name in printer.filaments.presets|map(attribute='name',default='None') %} - RESPOND TYPE=command MSG="action:prompt_button {filament_name}|LOAD_FILAMENT NAME={filament_name} PROMPT=True|primary" - {% endfor %} - RESPOND TYPE=command MSG="action:prompt_show" - {% else %} - # forward the filament name to the next macro - SET_GCODE_VARIABLE MACRO=END_LOAD_FILAMENT VARIABLE=name VALUE="'{params.NAME}'" - # we could set it here, but it avoids weird states if the macro fails for some reason. - - SET_FILAMENT_LOAD_STATE STATE="processing" - M83 # relative extruder moves - # load filament into extruder gear - UPDATE_DELAYED_GCODE ID=LOOP_LOAD_FILAMENT DURATION=0.15 - {% endif %} + {% if not filament_state in ['unloaded'] %} + # check if there is a valid value for the currently loaded filament. if not, prompt the user for it. + {% if not svv.filament_extruder in printer.filaments.presets|map(attribute='name',default='yeet') %} + # if there isn't a set loaded filament, run QUERY_FILAMENT + QUERY_FILAMENT RETURN_MACRO=LOAD_FILAMENT + + {% else %} + # forward the filament name to the next macro + SET_GCODE_VARIABLE MACRO=END_LOAD_FILAMENT VARIABLE=name VALUE="'{params.NAME}'" + # we could set it here, but it avoids weird states if the macro fails for some reason. + + SET_FILAMENT_LOAD_STATE STATE="processing" + M83 # relative extruder moves + # load filament into extruder gear + UPDATE_DELAYED_GCODE ID=LOOP_LOAD_FILAMENT DURATION=0.15 + {% endif %} + {% else %} + {action_respond_info("unable to load filament. Current filament state: %s " %(svv.filament_load_state))} + {% endif %} [delayed_gcode LOOP_LOAD_FILAMENT] gcode: @@ -161,7 +186,6 @@ gcode: M82 # absolute extruder moves # set loaded filament - SET_EXTRUDER_FILAMENT NAME={name} SET_FILAMENT_LOAD_STATE STATE="loaded" {% if prime %} @@ -172,11 +196,31 @@ [gcode_macro PRIME_FILAMENT] gcode: + {% set svv = printer.save_variables.variables %} + + {% if svv.filament_load_state in ['unloaded', 'loaded'] %} + # check if there is a valid value for the currently loaded filament. if not, prompt the user for it. + {% if not svv.filament_extruder in printer.filaments.presets|map(attribute='name',default='yeet') %} + # if there isn't a set loaded filament, run QUERY_FILAMENT + QUERY_FILAMENT RETURN_MACRO=PRIME_FILAMENT + {% elif svv.filament_load_state in ['unloaded'] %} + LOAD_FILAMENT PRIME=True + {% elif svv.filament_load_state in ['loaded'] %} + # perform filament priming.... + {% endif %} + {% else %} + {action_respond_info("unable to prime filament. Current filament state: %s " %(svv.filament_load_state))} + {% endif %} - [gcode_macro PURGE_FILAMENT] gcode: - {% if filament_load_state in ["loaded", "primed"] %} + {% set svv = printer.save_variables.variables %} + + {% if not svv.filament_extruder in printer.filaments.presets|map(attribute='name',default='yeet') %} + # if there isn't a set loaded filament, run QUERY_FILAMENT + QUERY_FILAMENT RETURN_MACRO=PURGE_FILAMENT + + {% elif svv.filament_load_state in ["loaded", "primed"] %} # if the filament is loaded or primed, then continue ##SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_hotend, ## svv.filament_extruder])|map(attribute="extruder",default='None')|max|string)} MODE=auto; set extruder temp diff --git a/config/macros.cfg b/config/macros.cfg index 32f3152..b9e76dd 100644 --- a/config/macros.cfg +++ b/config/macros.cfg @@ -3,7 +3,7 @@ gcode: # grab saved variables {% set svv = printer.save_variables.variables %} - {% set bed_leeway_temp = 10 %} + {% set bed_leeway_temp = 5 %} {% set extruder_leeway_temp = 20 %} {% set hotend_filament = svv.hotend_filament %} @@ -11,7 +11,6 @@ {% if not(svv.heater_mode == "auto" or svv.heater_mode == "manual" or svv.heater_mode == "slicer")%} { action_respond_info("setting heater_mode to AUTO, before: %s" % (svv.heater_mode)) } SAVE_VARIABLE VARIABLE=heater_mode VALUE='"auto"' - {% endif %} # set temp variables - call variables macro @@ -23,7 +22,7 @@ # check the current heater states and re enable heaters if able {% if svv.extruder_state == 'hot' %} - {% if printer.extruder.temperature - extruder_leeway_temp <= svv.extruder_temperature %} + {% if svv.extruder_temperature - extruder_leeway_temp <= printer.extruder.temperature %} { action_respond_info("re-enabling extruder after printer shutoff") } {% else %} { action_respond_info("extruder was enabled before last shutoff. State updated to cold.") } @@ -36,7 +35,7 @@ {action_respond_info(bed_leeway_temp|string)} {action_respond_info(svv.bed_temperature|string)} - {% if printer.heater_bed.temperature - bed_leeway_temp <= svv.bed_temperature %} + {% if svv.bed_temperature - bed_leeway_temp <= printer.heater_bed.temperature %} { action_respond_info("re-enabling bed after printer shutoff") } {% else %} { action_respond_info("bed was enabled before last shutoff. State updated to cold.") } @@ -71,29 +70,22 @@ # loaded {% elif entry_sense and exit_sense and bowden_sense %} {% if svv.filament_load_state != "loaded" %} - { action_respond_info("Current filament state does not match filament state on last boot. Was " ~ (svv.filament_load_state|string) ~ ", currently loaded. Double check filament path.") } + { action_respond_info("Current filament state does not match filament state on last boot. Was " ~ (svv.filament_load_state|string) ~ "") } {% endif %} - # SAVE_VARIABLE VARIABLE=loaded_filament VALUE=none SET_FILAMENT_LOAD_STATE STATE="loaded" SET_FILAMENT_SENSOR SENSOR=bowden_encoder_sensor ENABLE=1 # runout {% elif entry_sense and not(exit_sense) and not(bowden_sense) %} { action_respond_info("Current filament state is runout. Unable to print.") } - SET_FILAMENT_LOAD_STATE STATE="runout" SET_FILAMENT_SENSOR SENSOR=bowden_encoder_sensor ENABLE=0 # near_runout {% elif entry_sense and exit_sense and not(bowden_sense) %} { action_respond_info("Current filament state is runout. Unable to print.") } - SET_FILAMENT_LOAD_STATE STATE="near_runout" SET_FILAMENT_SENSOR SENSOR=bowden_encoder_sensor ENABLE=0 - {% endif %} - # set the currently loaded filament - SET_FILAMENT NAME={loaded_filament['name']} - initial_duration: 2 [gcode_macro TEST] @@ -109,62 +101,68 @@ G28 QUAD_GANTRY_LEVEL BED_MESH_CALIBRATE METHOD=rapid_scan + SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=mesh_bed_temp VALUE={printer['heater_bed'].temperature} G0 X239 Y210 F{700*60} - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"full"' [gcode_macro calibrate] gcode: - {% set calibrate = printer["gcode_macro VARIABLES"].calibrate %} + {% set mesh_temp_leeway = printer["gcode_macro VARIABLES"].mesh_bed_temp_leeway %} + {% set mesh_temp = printer["gcode_macro VARIABLES"].mesh_bed_temp %} + {% set skip_mesh = params.SKIP_MESH|default(False)%} - {% if calibrate == "none" %} + {% if "xyz" not in printer['toolhead'].homed_axes %} G28 - QUAD_GANTRY_LEVEL - BED_MESH_CALIBRATE METHOD=rapid_scan + {% endif %} - {% elif calibrate == "home" %} + {% if not printer['quad_gantry_level'].applied %} QUAD_GANTRY_LEVEL - BED_MESH_CALIBRATE METHOD=rapid_scan + {% endif %} - {% elif calibrate == "QGL" %} + {action_respond_info((not printer['bed_mesh'].profile_name)|string)} + + {% if skip_mesh %} + G0 X239 Y210 F{700*60} + # if a bed mesh has not been performed, or the temperature hasn't changed by more than 15 degrees. + {% elif ((not printer['bed_mesh'].profile_name) or + (printer['heater_bed'].temperature <= mesh_temp - mesh_temp_leeway) or + (printer['heater_bed'].temperature >= mesh_temp + mesh_temp_leeway)) %} + G0 X15 Y22 F{700*60} BED_MESH_CALIBRATE METHOD=rapid_scan + SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=mesh_bed_temp VALUE={printer['heater_bed'].temperature} + + G0 X239 Y210 F{700*60} {% endif %} - G0 X239 Y210 F{700*60} - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"full"' [gcode_macro calibrate_override] gcode: - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"full"' - -[gcode_macro calibrate_query] -gcode: - {% set val = printer["gcode_macro VARIABLES"].calibrate %} - { action_respond_info("a" + val|string) } ####### PRINT START AND STOP ETC [gcode_macro START_PRINT] description: Runs before the start of a print. Checks print readyness, corrects if nessesary, and primes the nozzle. gcode: {% set svv = printer.save_variables.variables %} - # first, check calibration - CALIBRATE - - # enable the encoder filament sensor - SET_FILAMENT_SENSOR SENSOR=bowden_encoder_sensor ENABLE=1 - # check the state of the loaded filament {% if svv.filament_state in ["loaded", "primed"] and svv.filament_runout_state != "runout" %} - # if in auto, only bother to set bed to loaded filament parameters. The others will be set when we purge/prime. + # if in auto, set bed and extruder to loaded filament parameters. {% if svv.heater_mode == "auto" %} - #SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={svv.filaments|selectattr("name", "equalto", svv.filament_extruder)|map(attribute="bed",default='None')|first|string} MODE=auto; set extruder temp + #SET_BED_TO_FILAMENT + #SET_HOTEND_TO_FILAMENT POSITION=both + # if in slicer or manual mode, quickly sanity check the set temperatures: {% else %} {% if printer['extruder'].target != 0 %} {action_raise_error("Extruder temperature is set to at or below zero")} {% endif %} {% endif %} - + + # check calibration + CALIBRATE SKIP_MESH=True + + # enable the encoder filament sensor + SET_FILAMENT_SENSOR SENSOR=bowden_encoder_sensor ENABLE=1 + {% if svv.filament_extruder == svv.filament_hotend %} PRIME_FILAMENT {% else %} @@ -320,11 +318,35 @@ ###### HEATER AUTO HANDLING [gcode_macro SET_HEATERS_TO_FILAMENT_AND_WAIT] +description: gcode: SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "equalto", svv.filament_hotend)|map(attribute="extruder",default='None')|first|string} MODE=auto SET_HEATER_TEMPERATURE_AND_WAIT HEATER=heater_bed TARGET={svv.filaments|selectattr("name", "equalto", svv.filament_hotend)|map(attribute="bed",default='None')|first|string} MODE=auto SET_HEATER_TEMPERATURE_AND_WAIT HEATER=extruder TARGET={svv.filaments|selectattr("name", "equalto", svv.filament_hotend)|map(attribute="extruder",default='None')|first|string} MODE=auto +[gcode_macro SET_HOTEND_TO_FILAMENT] +description: sets the temperature of the hotend to the temperature required by the stored filament +gcode: + {% set position = params.POSITION|default('extruder')|string|lower %} + {% if position == 'extruder' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_extruder])|map(attribute="extruder",default='None')|max|string} MODE=auto + {% elif position == 'hotend' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_hotend])|map(attribute="extruder",default='None')|max|string} MODE=auto + {% elif position == 'both' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_hotend, svv.filament_extruder])|map(attribute="extruder",default='None')|max|string} MODE=auto + {% endif %} + +[gcode_macro SET_BED_TO_FILAMENT] +description: sets the temperature of the bed to the temperature required by the stored filament +gcode: + {% set position = params.POSITION|default('extruder')|string|lower %} + {% if position == 'extruder' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_extruder])|map(attribute="bed",default='None')|max|string} MODE=auto + {% elif position == 'hotend' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_hotend])|map(attribute="bed",default='None')|max|string} MODE=auto + {% elif position == 'both' %} + SET_HEATER_TEMPERATURE HEATER=extruder TARGET={svv.filaments|selectattr("name", "in", [svv.filament_hotend, svv.filament_extruder])|map(attribute="bed",default='None')|max|string} MODE=auto + {% endif %} ## MISC MACROS diff --git a/config/overrides.cfg b/config/overrides.cfg index 7805b2c..c6c85f3 100644 --- a/config/overrides.cfg +++ b/config/overrides.cfg @@ -26,7 +26,6 @@ [gcode_macro G28] rename_existing: G9928 gcode: - {% set calibrate = printer["gcode_macro VARIABLES"].calibrate %} G9928 {rawparams} {% if not rawparams or (rawparams and 'Z' in rawparams) %} @@ -34,40 +33,27 @@ SET_Z_FROM_PROBE {% endif %} - {% if calibrate == "none" %} - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"home"' - {% endif %} - -[gcode_macro QUAD_GANTRY_LEVEL] -rename_existing: QUAD_GANTRY_LEVEL1 -gcode: - {% set calibrate = printer["gcode_macro VARIABLES"].calibrate %} +# [gcode_macro QUAD_GANTRY_LEVEL] +# rename_existing: QUAD_GANTRY_LEVEL1 +# gcode: +# {% if calibrate == "none" %} +# G28 +# {% endif %} - {% if calibrate == "none" %} - G28 - {% endif %} - - QUAD_GANTRY_LEVEL1 {rawparams} +# QUAD_GANTRY_LEVEL1 {rawparams} - {% if calibrate == "home" or calibrate == "none" %} - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"QGL"' - {% endif %} -[gcode_macro BED_MESH_CALIBRATE] -rename_existing: BED_MESH_CALIBRATE1 -gcode: - {% set calibrate = printer["gcode_macro VARIABLES"].calibrate %} +# [gcode_macro BED_MESH_CALIBRATE] +# rename_existing: BED_MESH_CALIBRATE1 +# gcode: +# {% if calibrate == "none" %} +# G28 +# QUAD_GANTRY_LEVEL +# {% elif calibrate == "home" %} +# QUAD_GANTRY_LEVEL +# {% endif %} - {% if calibrate == "none" %} - G28 - QUAD_GANTRY_LEVEL - {% elif calibrate == "home" %} - QUAD_GANTRY_LEVEL - {% endif %} - - BED_MESH_CALIBRATE1 {rawparams} - - SET_GCODE_VARIABLE MACRO=VARIABLES VARIABLE=calibrate VALUE='"full"' +# BED_MESH_CALIBRATE1 {rawparams} # replace pause [gcode_macro M600] diff --git a/config/variable_macros.cfg b/config/variable_macros.cfg index 91b6297..0833572 100644 --- a/config/variable_macros.cfg +++ b/config/variable_macros.cfg @@ -2,7 +2,8 @@ filename: ~/printer_data/config/storage/variables.cfg [gcode_macro VARIABLES] -variable_calibrate: "none" +variable_mesh_bed_temp: 0 # stores the temperature of the bed at the last bed mesh calibrate +variable_mesh_bed_temp_leeway: 15 # +- leeway (K) outside of which another bed mesh will be performed gcode: [gcode_macro SET_FILAMENT_LOAD_STATE]