Skip to content

Commit

Permalink
toolhead state colors
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Apr 27, 2024
1 parent 9f683ca commit 1ecbd1d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
28 changes: 25 additions & 3 deletions macros/load_filament.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ gcode:

DEBUG_ECHO PREFIX="_DEFAULT_LOAD_FILAMENT" MSG="toolhead={toolhead}"

# config
{% set color_ok = printer["gcode_macro RatOS"].status_color_ok|string %}
{% set color_error = printer["gcode_macro RatOS"].status_color_error|string %}
{% set color_unknown = printer["gcode_macro RatOS"].status_color_unknown|string %}

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_unknown}"'

# visual feedback
_LED_LOADING_FILAMENT TOOLHEAD=0
_LED_LOADING_FILAMENT TOOLHEAD={toolhead}

# save gcode state
SAVE_GCODE_STATE NAME=load_state
Expand All @@ -77,13 +85,16 @@ gcode:
TEMPERATURE_WAIT SENSOR=extruder MINIMUM={temp}

# load filament
_LOAD_FILAMENT TOOLHEAD={toolhead} RMMU="RMMU_T0" FILAMENT={toolhead}
_LOAD_FILAMENT TOOLHEAD={toolhead} FILAMENT={toolhead}

# restore gcode state
RESTORE_GCODE_STATE NAME=load_state

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_ok}"'

# visual feedback
_LED_FILAMENT_LOADED TOOLHEAD=0
_LED_FILAMENT_LOADED TOOLHEAD={toolhead}


[gcode_macro _IDEX_LOAD_FILAMENT]
Expand All @@ -94,11 +105,19 @@ gcode:
{% set toolhead = params.TOOLHEAD|int %}
{% set filament = params.FILAMENT|default(-1)|int %}

# config
{% set color_ok = printer["gcode_macro RatOS"].status_color_ok|string %}
{% set color_error = printer["gcode_macro RatOS"].status_color_error|string %}
{% set color_unknown = printer["gcode_macro RatOS"].status_color_unknown|string %}

# cache current extruder
{% set old_extruder = printer.toolhead.extruder %}

DEBUG_ECHO PREFIX="_IDEX_LOAD_FILAMENT" MSG="temp: {temp}, toolhead: {toolhead}, old_extruder: {old_extruder}, FILAMENT={filament}"

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_unknown}"'

# visual feedback
_LED_LOADING_FILAMENT TOOLHEAD={toolhead}

Expand Down Expand Up @@ -126,6 +145,9 @@ gcode:
ACTIVATE_EXTRUDER EXTRUDER={old_extruder}
{% endif %}

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_ok}"'

# visual feedback
_LED_FILAMENT_LOADED TOOLHEAD={toolhead}

Expand Down
16 changes: 16 additions & 0 deletions macros/unload_filament.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ gcode:
{% endif %}
{% endif %}

# config
{% set color_ok = printer["gcode_macro RatOS"].status_color_ok|string %}
{% set color_error = printer["gcode_macro RatOS"].status_color_error|string %}
{% set color_unknown = printer["gcode_macro RatOS"].status_color_unknown|string %}

DEBUG_ECHO PREFIX="_DEFAULT_UNLOAD_FILAMENT" MSG="temp={temp}"

# visual feedback
Expand All @@ -86,6 +91,9 @@ gcode:
# restore gcode state
RESTORE_GCODE_STATE NAME=unload_state

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_unknown}"'

# visual feedback
_LED_FILAMENT_UNLOADED TOOLHEAD=0

Expand All @@ -98,6 +106,11 @@ gcode:
{% set toolhead = params.TOOLHEAD|int %}
{% set filament = params.FILAMENT|default(-1)|int %}

# config
{% set color_ok = printer["gcode_macro RatOS"].status_color_ok|string %}
{% set color_error = printer["gcode_macro RatOS"].status_color_error|string %}
{% set color_unknown = printer["gcode_macro RatOS"].status_color_unknown|string %}

# cache current extruder
{% set old_extruder = printer.toolhead.extruder %}

Expand Down Expand Up @@ -130,6 +143,9 @@ gcode:
ACTIVATE_EXTRUDER EXTRUDER={old_extruder}
{% endif %}

# update frontend
SET_GCODE_VARIABLE MACRO=T{toolhead} VARIABLE=color VALUE='"{color_unknown}"'

# visual feedback
_LED_FILAMENT_UNLOADED TOOLHEAD={toolhead}

Expand Down
30 changes: 28 additions & 2 deletions macros/util.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ variable_printable_x_max: 0
variable_printable_y_min: 0
variable_printable_y_max: 0
variable_end_print_motors_off: True
variable_status_color_ok: "00FF00"
variable_status_color_error: "FF0000"
variable_status_color_unknown: "FFFF00"
gcode:
ECHO_RATOS_VARS

Expand All @@ -37,8 +40,31 @@ initial_duration: 0.1
gcode:
_LED_STANDBY
CALCULATE_PRINTABLE_AREA
{% if printer["rmmu"] is defined %}
RMMU_RESET
INITIAL_FRONTEND_UPDATE

[gcode_macro INITIAL_FRONTEND_UPDATE]
gcode:
# config
{% set color_ok = printer["gcode_macro RatOS"].status_color_ok|string %}
{% set color_error = printer["gcode_macro RatOS"].status_color_error|string %}
{% set color_unknown = printer["gcode_macro RatOS"].status_color_unknown|string %}

# set default status
SET_GCODE_VARIABLE MACRO=T0 VARIABLE=color VALUE='"{color_unknown}"'
{% if printer["dual_carriage"] is defined %}
SET_GCODE_VARIABLE MACRO=T1 VARIABLE=color VALUE='"{color_unknown}"'
{% endif %}

# filament detection in case user has filament sensors configured
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"].filament_detected|lower == "true" %}
SET_GCODE_VARIABLE MACRO=T0 VARIABLE=color VALUE='"{color_ok}"'
{% endif %}
{% endif %}
{% if printer["dual_carriage"] is defined and printer["filament_switch_sensor toolhead_filament_sensor_t1"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"].filament_detected|lower == "true" %}
SET_GCODE_VARIABLE MACRO=T1 VARIABLE=color VALUE='"{color_ok}"'
{% endif %}
{% endif %}

[gcode_macro CALCULATE_PRINTABLE_AREA]
Expand Down

0 comments on commit 1ecbd1d

Please sign in to comment.