Debounce sketchy - Macro to get ticks?

Hi, I’m having some sketchy debounce on my printer, which is causing my physical skirt buttons to register multiple presses really sporadically.

Is there a way in gcode to solve this properly?
If not, is there a get_ticks() function somewhere? Or a way to detect recent macros that have run, so I can solve it myself?

There is no exported method to set the “debouncing” time. (Internally the “debounce time” is 2ms as set by the QUERY_TIME parameter at the top of klippy/extras/ .)

Macros can access printer.toolhead.estimated_print_time to access an incrementing timer (in seconds).


Thanks for the info… I’ve been fighting this all day. The solution I’ve come up with is pretty horrible, but it does work:

[gcode_macro skirtglobal]
variable_counter: 0
variable_timeout: 0.05
    M115 ; GCODE cannot be empty

[delayed_gcode SKIRT_COUNTER]
initial_duration: 0.05
    SET_GCODE_VARIABLE MACRO=skirtglobal VARIABLE=counter VALUE={printer["gcode_macro skirtglobal"].counter + 0.05}

## Left
[gcode_button BUTTON_GPIO4]
pin: !pi:gpio4
    {% set timer = printer["gcode_macro skirtglobal"].counter|float %}
    {% set timeout = printer["gcode_macro skirtglobal"].timeout|float %}
    {% if timer > timeout %}
        SET_GCODE_VARIABLE MACRO=skirtglobal VARIABLE=counter VALUE={0.0}
        { action_respond_info("GPIO4") } 
    {% endif %}

    SET_GCODE_VARIABLE MACRO=skirtglobal VARIABLE=counter VALUE={0.0}

I’ll have a look at printer.toolhead.estimated_print_time, but if the precision on that is seconds, then I won’t be able to use it.

It’s not ideal to have a constantly running macro firing in the background to count for me. But unless there’s a reasonably high precision timer somewhere - I’m kinda stuck.