diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index fdaaf1ceab..20ddfeead5 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -3045,7 +3045,35 @@ // // #define FF_INTERFACEBOARD -// #define MIGHTYBOARD_LCD +// +// MightyBoard LCD/Interface +// + +//#define MIGHTYBOARD_LCD +//#define MIGHTYBOARD_INTERFACE + +// Runtime debug: uncomment to enable lightweight serial runtime traces for UI/button flow +// Enable runtime debug traces for MightyBoard button diagnostics +// Uncomment to see serial output of button state reads and encoder changes +//#define MIGHTYBOARD_RUNTIME_DEBUG + + +// BTN_ENC (central click) pull-up control (independent flag for click button) +// Disable this if the button reads stuck HIGH even when pressed +//#define MIGHTYBOARD_DISABLE_ENC_PULLUP + +// Board-specific option: enable internal INPUT_PULLUP for MightyBoard button pins +// Define `MIGHTYBOARD_BUTTON_PULLUPS` to enable `SET_INPUT_PULLUP(BTN_*)` in Marlin's UI init. +// #ifndef MIGHTYBOARD_BUTTON_PULLUPS +// #define MIGHTYBOARD_BUTTON_PULLUPS +// #endif + +// +// Optional: Button behavior for LEFT/RIGHT +// If enabled, LEFT goes back one menu level, RIGHT returns to status screen +// If disabled (default), LEFT/RIGHT change encoder position (navigate menu items) +// +//#define DIGITAL_BUTTON_L_R_MENU_BACK_STATUS // // TFT GLCD Panel with Marlin UI diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index ee372aca69..d7462aa929 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -70,6 +70,12 @@ MarlinUI ui; bool MarlinUI::wait_for_move; // = false #endif +#if ENABLED(DIGITAL_BUTTON_L_R_MENU_BACK_STATUS) +// Flags set from interrupt context; handled in main loop +volatile bool MarlinUI::request_back = false; +volatile bool MarlinUI::request_return_to_status = false; +#endif + constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; #if HAS_STATUS_MESSAGE @@ -1079,7 +1085,19 @@ void MarlinUI::init() { else wait_for_unclick = false; } - + #if ENABLED(DIGITAL_BUTTON_L_R_MENU_BACK_STATUS) + // Handle requests set from interrupt context (ISR-safe) + if (MarlinUI::request_back) { + MarlinUI::request_back = false; + quick_feedback(); + goto_previous_screen(); + } + if (MarlinUI::request_return_to_status) { + MarlinUI::request_return_to_status = false; + quick_feedback(); + return_to_status(); + } + #endif if (LCD_BACK_CLICKED()) { quick_feedback(); goto_previous_screen(); @@ -1432,27 +1450,30 @@ void MarlinUI::init() { else if (BUTTON_PRESSED(DOWN)) { encoderDiff = pulses * -(ENCODER_STEPS_PER_MENU_ITEM); next_button_update_ms = now + 300; - // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) - // SERIAL_ECHO_MSG("update_buttons(): DOWN -> encoderDiff=", encoderDiff); - // SERIAL_ECHOLN(""); - // #endif - } - else if (BUTTON_PRESSED(LEFT)) { - encoderDiff = -pulses; - next_button_update_ms = now + 300; - // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) - // SERIAL_ECHO_MSG("update_buttons(): LEFT -> encoderDiff=", encoderDiff); - // SERIAL_ECHOLN(""); - // #endif - } - else if (BUTTON_PRESSED(RIGHT)) { - encoderDiff = pulses; - next_button_update_ms = now + 300; - // #if ENABLED(MIGHTYBOARD_RUNTIME_DEBUG) - // SERIAL_ECHO_MSG("update_buttons(): RIGHT -> encoderDiff=", encoderDiff); - // SERIAL_ECHOLN(""); - // #endif } + #if ENABLED(DIGITAL_BUTTON_L_R_MENU_BACK_STATUS) + // Alternative behavior: LEFT/RIGHT for menu navigation (back/home) instead of encoder scrolling + else if (BUTTON_PRESSED(LEFT)) { + // ISR-safe: request action to be handled in main loop + MarlinUI::request_back = true; + next_button_update_ms = now + 300; + } + else if (BUTTON_PRESSED(RIGHT)) { + // ISR-safe: request action to be handled in main loop + MarlinUI::request_return_to_status = true; + next_button_update_ms = now + 300; + } + #else + // Default behavior: LEFT/RIGHT change encoder position for menu item selection + else if (BUTTON_PRESSED(LEFT)) { + encoderDiff = -pulses; + next_button_update_ms = now + 300; + } + else if (BUTTON_PRESSED(RIGHT)) { + encoderDiff = pulses; + next_button_update_ms = now + 300; + } + #endif // DIGITAL_BUTTON_L_R_MENU_BACK_STATUS #endif // UP || DOWN || LEFT || RIGHT diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 85d05887e3..cda27c879b 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -825,6 +825,12 @@ public: static void update_buttons(); + #if ENABLED(DIGITAL_BUTTON_L_R_MENU_BACK_STATUS) + // Requests set from interrupt context and handled in main loop + static volatile bool request_back; + static volatile bool request_return_to_status; + #endif + #if ENABLED(ENCODER_NOISE_FILTER) /** * Some printers may have issues with EMI noise especially using a motherboard with 3.3V logic levels