G-code Digital Buttons (#18389)
Co-Authored-By: android444 <24375898+android444@users.noreply.github.com> Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
parent
8c9a59c29e
commit
7ee9aefed7
|
@ -3369,6 +3369,37 @@
|
|||
#define GCODE_MACROS_SLOT_SIZE 50 // Maximum length of a single macro
|
||||
#endif
|
||||
|
||||
/**
|
||||
* User-defined buttons to run custom G-code.
|
||||
* Up to 25 may be defined.
|
||||
*/
|
||||
//#define CUSTOM_USER_BUTTONS
|
||||
#if ENABLED(CUSTOM_USER_BUTTONS)
|
||||
//#define BUTTON1_PIN -1
|
||||
#if PIN_EXISTS(BUTTON1_PIN)
|
||||
#define BUTTON1_HIT_STATE LOW // State of the triggered button. NC=LOW. NO=HIGH.
|
||||
#define BUTTON1_WHEN_PRINTING false // Button allowed to trigger during printing?
|
||||
#define BUTTON1_GCODE "G28"
|
||||
#define BUTTON1_DESC "Homing" // Optional string to set the LCD status
|
||||
#endif
|
||||
|
||||
//#define BUTTON2_PIN -1
|
||||
#if PIN_EXISTS(BUTTON2_PIN)
|
||||
#define BUTTON2_HIT_STATE LOW
|
||||
#define BUTTON2_WHEN_PRINTING false
|
||||
#define BUTTON2_GCODE "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND)
|
||||
#define BUTTON2_DESC "Preheat for " PREHEAT_1_LABEL
|
||||
#endif
|
||||
|
||||
//#define BUTTON3_PIN -1
|
||||
#if PIN_EXISTS(BUTTON3_PIN)
|
||||
#define BUTTON3_HIT_STATE LOW
|
||||
#define BUTTON3_WHEN_PRINTING false
|
||||
#define BUTTON3_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND)
|
||||
#define BUTTON3_DESC "Preheat for " PREHEAT_2_LABEL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* User-defined menu items to run custom G-code.
|
||||
* Up to 25 may be defined, but the actual number is LCD-dependent.
|
||||
|
|
|
@ -406,6 +406,7 @@ void startOrResumeJob() {
|
|||
* - Check if CHDK_PIN needs to go LOW
|
||||
* - Check for KILL button held down
|
||||
* - Check for HOME button held down
|
||||
* - Check for CUSTOM USER button held down
|
||||
* - Check if cooling fan needs to be switched on
|
||||
* - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT)
|
||||
* - Pulse FET_SAFETY_PIN if it exists
|
||||
|
@ -498,6 +499,102 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if ENABLED(CUSTOM_USER_BUTTONS)
|
||||
// Handle a custom user button if defined
|
||||
const bool printer_not_busy = !printingIsActive();
|
||||
#define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(BUTTON##N) && defined(BUTTON##N##_HIT_STATE) && defined(BUTTON##N##_GCODE) && defined(BUTTON##N##_DESC))
|
||||
#define CHECK_CUSTOM_USER_BUTTON(N) do{ \
|
||||
constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 250UL; \
|
||||
static millis_t next_cub_ms_##N; \
|
||||
if (BUTTON##N##_HIT_STATE == READ(BUTTON##N##_PIN) \
|
||||
&& (ENABLED(BUTTON##N##_WHEN_PRINTING) || printer_not_busy)) { \
|
||||
const millis_t ms = millis(); \
|
||||
if (ELAPSED(ms, next_cub_ms_##N)) { \
|
||||
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
|
||||
if (strlen(BUTTON##N##_DESC)) \
|
||||
LCD_MESSAGEPGM_P(PSTR(BUTTON##N##_DESC)); \
|
||||
queue.inject_P(PSTR(BUTTON##N##_GCODE)); \
|
||||
} \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#if HAS_CUSTOM_USER_BUTTON(1)
|
||||
CHECK_CUSTOM_USER_BUTTON(1);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(2)
|
||||
CHECK_CUSTOM_USER_BUTTON(2);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(3)
|
||||
CHECK_CUSTOM_USER_BUTTON(3);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(4)
|
||||
CHECK_CUSTOM_USER_BUTTON(4);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(5)
|
||||
CHECK_CUSTOM_USER_BUTTON(5);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(6)
|
||||
CHECK_CUSTOM_USER_BUTTON(6);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(7)
|
||||
CHECK_CUSTOM_USER_BUTTON(7);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(8)
|
||||
CHECK_CUSTOM_USER_BUTTON(8);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(9)
|
||||
CHECK_CUSTOM_USER_BUTTON(9);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(10)
|
||||
CHECK_CUSTOM_USER_BUTTON(10);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(11)
|
||||
CHECK_CUSTOM_USER_BUTTON(11);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(12)
|
||||
CHECK_CUSTOM_USER_BUTTON(12);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(13)
|
||||
CHECK_CUSTOM_USER_BUTTON(13);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(14)
|
||||
CHECK_CUSTOM_USER_BUTTON(14);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(15)
|
||||
CHECK_CUSTOM_USER_BUTTON(15);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(16)
|
||||
CHECK_CUSTOM_USER_BUTTON(16);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(17)
|
||||
CHECK_CUSTOM_USER_BUTTON(17);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(18)
|
||||
CHECK_CUSTOM_USER_BUTTON(18);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(19)
|
||||
CHECK_CUSTOM_USER_BUTTON(19);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(20)
|
||||
CHECK_CUSTOM_USER_BUTTON(20);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(21)
|
||||
CHECK_CUSTOM_USER_BUTTON(21);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(22)
|
||||
CHECK_CUSTOM_USER_BUTTON(22);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(23)
|
||||
CHECK_CUSTOM_USER_BUTTON(23);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(24)
|
||||
CHECK_CUSTOM_USER_BUTTON(24);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(25)
|
||||
CHECK_CUSTOM_USER_BUTTON(25);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TERN_(USE_CONTROLLER_FAN, controllerFan.update()); // Check if fan should be turned on to cool stepper drivers down
|
||||
|
||||
TERN_(AUTO_POWER_CONTROL, powerManager.check());
|
||||
|
@ -857,7 +954,7 @@ inline void tmc_standby_setup() {
|
|||
|
||||
/**
|
||||
* Marlin entry-point: Set up before the program loop
|
||||
* - Set up the kill pin, filament runout, power hold
|
||||
* - Set up the kill pin, filament runout, power hold, custom user buttons
|
||||
* - Start the serial port
|
||||
* - Print startup messages and diagnostics
|
||||
* - Get EEPROM or default settings
|
||||
|
@ -1131,6 +1228,86 @@ void setup() {
|
|||
SET_INPUT_PULLUP(HOME_PIN);
|
||||
#endif
|
||||
|
||||
#if ENABLED(CUSTOM_USER_BUTTONS)
|
||||
#define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(BUTTON##N##_PIN); WRITE(BUTTON##N##_PIN, !BUTTON##N##_HIT_STATE); }while(0)
|
||||
|
||||
#if HAS_CUSTOM_USER_BUTTON(1)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(1);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(2)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(2);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(3)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(3);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(4)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(4);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(5)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(5);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(6)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(6);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(7)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(7);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(8)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(8);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(9)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(9);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(10)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(10);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(11)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(11);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(12)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(12);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(13)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(13);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(14)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(14);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(15)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(15);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(16)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(16);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(17)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(17);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(18)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(18);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(19)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(19);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(20)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(20);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(21)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(21);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(22)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(22);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(23)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(23);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(24)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(24);
|
||||
#endif
|
||||
#if HAS_CUSTOM_USER_BUTTON(25)
|
||||
INIT_CUSTOM_USER_BUTTON_PIN(25);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PIN_EXISTS(STAT_LED_RED)
|
||||
OUT_WRITE(STAT_LED_RED_PIN, LOW); // OFF
|
||||
#endif
|
||||
|
|
|
@ -183,6 +183,81 @@
|
|||
#if PIN_EXISTS(JOY_EN)
|
||||
REPORT_NAME_DIGITAL(__LINE__, JOY_EN_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON1)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON1_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON2)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON2_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON3)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON3_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON4)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON4_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON5)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON5_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON6)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON6_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON7)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON7_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON8)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON8_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON9)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON9_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON10)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON10_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON11)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON11_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON12)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON12_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON13)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON13_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON14)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON14_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON15)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON15_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON16)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON16_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON17)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON17_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON18)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON18_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON19)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON19_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON20)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON20_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON21)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON21_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON22)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON22_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON23)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON23_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON24)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON24_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(BUTTON25)
|
||||
REPORT_NAME_DIGITAL(__LINE__, BUTTON25_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(CASE_LIGHT)
|
||||
REPORT_NAME_DIGITAL(__LINE__, CASE_LIGHT_PIN)
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue