Skip to content

Commit

Permalink
status_events: Allow registering multiple statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuh committed Jun 10, 2023
1 parent 1662b82 commit c9d48b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,8 @@ operations you may want to run at a given status in the printing process.
Associates a gcode command with a specific status and sets the parameters for
when and how the status event fires.

* `STATUS` - The status event this command is associated with.
* `STATUS` - A comma seperated list of status events this command is associated
with. Passing the value `all` will associate the gcode with all statuses.
* `COMMAND` - The text of the command.
* `ARGS` *(default: `0`)* - Set to `1` to enable passing the following status
arguments to the macro: `TYPE`, `WHEN`, `LAST_STATUS`, and `NEXT_STATUS`.
Expand Down
29 changes: 18 additions & 11 deletions status_events.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ gcode:
(params.FILTER_LEAVE|default("")|trim|lower).split(',')|
select()|unique|list %}

{% if not STATUS in command_list %}
{% set dummy = command_list.__setitem__(STATUS,[]) %}
{% endif %}
{% set dummy = command_list[STATUS].append({'cmd':COMMAND, 'args':ARGS,
'type':TYPE, 'when':WHEN,
'filt_e':FILTER_ENTER,
'filt_l':FILTER_LEAVE}) %}
{% set STATUSES = STATUS.split(',')|map('trim')|list %}
{% for s in (STATUSES if STATUSES[0] != 'all' else status_list) %}
{% if not s in command_list %}
{% set dummy = command_list.__setitem__(s,[]) %}
{% endif %}
{% set dummy = command_list[s].append({'cmd':COMMAND, 'args':ARGS,
'type':TYPE, 'when':WHEN,
'filt_e':FILTER_ENTER,
'filt_l':FILTER_LEAVE}) %}
{% endfor %}

# Change the current status.
{% elif ACTION == "CHANGE" %}
Expand Down Expand Up @@ -109,7 +112,7 @@ description: Adds a gcode command for a status event.
[FILTER_ENTER=<status list>]
[FILTER_LEAVE=<status list>]
gcode:
{% set STATUS = params.STATUS|trim|lower %}
{% set STATUS = (params.STATUS|lower).split(',')|map('trim')|list %}
{% set TYPE = params.TYPE|default('ENTER')|trim|upper %}
{% set WHEN = params.WHEN|default('PRINTING')|trim|upper %}
{% set FILTER_ENTER =
Expand All @@ -119,9 +122,13 @@ gcode:

# Error checking
{% set status_list = printer["gcode_macro _km_print_status"].status_list %}
{% if STATUS not in status_list %}
{action_raise_error("STATUS parameter '%s' not valid."|format(STATUS))}
{% elif TYPE not in ('ENTER', 'LEAVE', 'BOTH') %}
{% for s in STATUS %}
{% if not (s in status_list or s == 'all' and STATUS|length == 1) %}
{action_raise_error("STATUS parameter '%s' not valid."|format(s))}
{% endif %}
{% endfor %}

{% if TYPE not in ('ENTER', 'LEAVE', 'BOTH') %}
{action_raise_error("TYPE paramater '%s' not valid."|format(TYPE))}
{% elif WHEN not in ('PRINTING', 'IDLE', 'ALWAYS') %}
{action_raise_error("WHEN parameter '%s' not valid."|format(WHEN))}
Expand Down

0 comments on commit c9d48b4

Please sign in to comment.