Is it possible to use a Virtual button instead of a Pin in Gcode macros?

So what I was wondering, was if I could use “Virtual Button” or “Virtual Pin” in-place of a physical pin in macros.

eg This section of a macro relies on a real button on my OS2 Filament sensor. Say I wanted to re-use this macro on a printer filament sensor that doesn’t have a physical button to press, how would one do this using a Macro button in the Mainsail UI?

[gcode_button sensor_fs]
#pin: PC7  # !!!!!!!!!!!!!!!!!!!!!change with the pin name to which the sensor is connected!!!!!!!!!!!!!!!!!!!!!
pin: EBBCan: PB3 # remove the negation "!" for sensor v1 - use just PA9 as example
press_gcode: # sensor released
  {% if (printer.print_stats.state == "printing") %}  
    #PAUSE # call printer pause macto
    filament_change_state1   
  #{% else %}  
   # SET_GCODE_VARIABLE MACRO=filament_load VARIABLE=loadbusy VALUE=0
  {% endif %} 
  UPDATE_DELAYED_GCODE ID=clear_loadbusy DURATION=2
  UPDATE_DELAYED_GCODE ID=clear_unloadbusy DURATION=2    
  SET_GCODE_VARIABLE MACRO=filament_unload VARIABLE=filamentpresent VALUE=0

release_gcode: #gcode macro for filament load, sensor pressed
  {% if (printer.print_stats.state != "printing") %}
    filament_load
  {% else %}
    M117 Printing! Can't load filament right now!
    M118 Printing! Can't load filament right now! 
    UPDATE_DELAYED_GCODE ID=clear_display DURATION=10
  {% endif %} 
  SET_GCODE_VARIABLE MACRO=filament_unload VARIABLE=filamentpresent VALUE=1
  UPDATE_DELAYED_GCODE ID=clear_changebusy DURATION=2

You may have a look on this:

#general-discussion New "virtual pins" module for testing purposes

1 Like

Cheers, that seems to be what I was thinking of.

1 Like

Maybe my understanding is wrong:

  • A “virtual pin” is just a dummy that does practically nothing (except changing its state)
  • A general [gcode_macro xxx] is displayed as a button in the UI

IMO there is no need to modify Klipper to achieve this

It’s definitely useful, I’m using it to simulate a physical unload button for a Filament sensor macro that I like and won’t work without.