Gcode_button with delay etc

I am about to move from OctoPrint/Klipper to Fluidd(or MainSail, not decided)/Klipper

In my current Octoprint setup I use a plugin called Physical Button, this allows me to map several GPIO to buttons.

Some of my buttons are set to only fire after x seconds of being depressed (Hold Time), only firing if currently printing.

So, for instance I have a macro to turn off / on my TPLink but only if held for 5 seconds. Another is to extrude 25mm (but only if up to temperature). And lastly I have a macro that sends an ssh command.

How to achieve these things moving away from the OctoPrint plugin please?

For reference of the capabilties: Physical Button

Klipper only knows press and release events on gcode_buttons but not a “long press”

Conditions like “only when printing” or delays can be done via macros, e.g. delayed gcode macros.

As @Sineos did say - klipper don’t know “long press” directly, but klipper can be improved to support not only “long press” but also have multiple levels :slight_smile:

here is config for 4 different levels.

[gcode_button my_button_long_press]
pin: !host:gpiochip0/gpio30
press_gcode:
  {% set current_timer = printer.toolhead.estimated_print_time %} 
  SET_GCODE_VARIABLE MACRO=my_button VARIABLE=last_press VALUE={current_timer}
  {action_respond_info("Press time: %.2f "% (current_timer))}

release_gcode:
  {% set duration = printer.toolhead.estimated_print_time - printer["gcode_macro my_button"].last_press|float %}
  {action_respond_info("duration: %.2f "% (duration))}
  {% if duration|float > 10.0 %}
      my_button_level3
  {% elif duration|float > 4.0 %}
      my_button_level2
  {% elif duration|float > 2.0 %}
      my_button
  {% else %}
      {action_respond_info("button didn't meet criteria it was too short press")}
  {% endif %}

[gcode_macro my_button]
variable_last_press: 0.0
gcode:
  {action_respond_info("it was loong press of a button1 level 1")}

[gcode_macro my_button_level2]
gcode:
  {action_respond_info("it was loong press of a button1 level 2")}

[gcode_macro my_button_level3]
gcode:
  {action_respond_info("it was loong press of a button1 level 3")}
3 Likes

Awesome - thank you, will give this a go when my new board arrives :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.