Macro Button Feature - bdring/Grbl_Esp32 GitHub Wiki

Macro Button Feature

Overview

Macro buttons allow you to associate a switch closure with a macro. A basic macro can be simple commands or run a file from an SD card or the ESP32 flash file system. Advanced macros are written into the firmware and can do complex calculations and branch on conditions.

Electrical

Button are connected to GPIO. They can be normally open or normally closed. They are part of control button group and can be inverted with #define INVERT_CONTROL_PIN_MASK Bnnnnnnnn in the config.h file. You can see them in the response to the ? command when they are in the active state.

Machine Definition

Macro buttons are similar to the control switches (reset, hold, etc). You can define up to (4) of them. You add them to your machine definition file like...

#define MACRO_BUTTON_0_PIN GPIO_NUM_13

Settings

Basic macros are implemented using settings. $User/Macro0= assigns a macro to button 0.

  • Single Command: This can be any command or gcode. Example:$User/Macro0=$H
  • Multiple commands: Place and ampersand "&" between commands (limit 250 chars). Example: $User/Macro0=G90&G53G0Z-1&G0X0Y0
  • File from SD Card: Example: Use the $SD/Run command and a filename Example: $User/Macro0=$SD/Run=foo.nc
  • File from ESP32 Flash File System: Use the $LocalFS/Run command and a filename. Example: $User/Macro0=$LocalFS/Run=bar.nc

A file can be gcode, most Grbl_ESP32 commands and settings or a mixture of both.

You must be in the idle state to execute button macros.

Advanced Macros

When a macro button is pushed Grbl_ESP32 calls the user_defined_macro(uint8_t index) function with the button number (0-3) as the parameter. This is a weakly defined function. This means, if you provide your own version, the compiler will use that instead. Put this in a file in the Custom folder. Provide a reference to it in your machine definition file with....

#define CUSTOM_CODE_FILENAME "Custom/my_file.cpp"

Important Note

This feature is initiated by an interrupt on the input pin. The current implementation is not very robust. Be sure to do a lot of testing to be sure your setup is stable. We hope to implement a more robust version soon.