jschuh / klipper-macros

A collection of useful macros for the Klipper 3D printer firmware
GNU General Public License v3.0
921 stars 167 forks source link

Klipper update breaks beeper #235

Closed HitLuca closed 5 months ago

HitLuca commented 5 months ago

Due to a recent klipper update, it seems that beepers now need to be defined as pwm_cycle_time elements (forum link). While this fixes the issue with beepers not working and just emitting an audible click, the M300 macro doesn't work anymore as it's looking for an output_pin beeper element in the printer config. Updating the macro check to also look for the new element would solve this issue.

Here is my quick fix to the the M300 macro working again

[gcode_macro m300]
description: Emits and audible beep.
  Usage: M300 [P<duration>] [S<frequency>]
gcode:
  {% set settings = printer.configfile.settings %}
  {% if "output_pin beeper" in printer or "pwm_cycle_time beeper" in printer %}
    {% set P = (params.P|default(100)|int, 0)|max %}
    {% set S = (params.S|default(1000)|int, 1)|max %}

    {% if "output_pin beeper" in printer %}
      SET_PIN PIN=beeper VALUE={% if settings["output_pin beeper"].pwm %}{
        settings["output_pin beeper"].scale|default(1.0) * 0.5
      } CYCLE_TIME={ 1.0 / S }{% else %}1{% endif %}
    {% else %}
      SET_PIN PIN=beeper VALUE={settings["pwm_cycle_time beeper"].scale|default(1.0) * 0.5} CYCLE_TIME={ 1.0 / S }
    {% endif %}

    G4 P{P}
    SET_PIN PIN=beeper VALUE=0
  {% else %}
    {action_respond_info(
       "M300 is disabled. To enable create an [output_pin beeper] or [pwm_cycle_time beeper] (new klipper versions) config.")}
  {% endif %}
jschuh commented 5 months ago

Should be fixed in f90a118 on dev.

jschuh commented 5 months ago

Fixed on main.