From f4c128ecaa8f0355f6ecd359f06dbc2cfeed344b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 14 Nov 2018 06:00:21 -0600 Subject: [PATCH] Move RRW keypad code to a common method (#12429) --- Marlin/src/lcd/ultralcd.cpp | 161 +++++++++++---------- Marlin/src/lcd/ultralcd.h | 9 +- Marlin/src/pins/pins_TEENSY35_36.h | 9 ++ buildroot/share/tests/megaatmega2560_tests | 5 +- 4 files changed, 101 insertions(+), 83 deletions(-) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 945fa427d..9ee19730c 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -235,38 +235,10 @@ bool MarlinUI::get_blink() { //////////////////////////////////////////// #if ENABLED(REPRAPWORLD_KEYPAD) - volatile uint8_t buttons_reprapworld_keypad; -#endif -#if ENABLED(ADC_KEYPAD) + volatile uint8_t MarlinUI::buttons_reprapworld_keypad; - inline bool handle_adc_keypad() { - #define ADC_MIN_KEY_DELAY 100 - if (buttons_reprapworld_keypad) { - #if HAS_ENCODER_ACTION - ui.refresh(LCDVIEW_REDRAW_NOW); - if (encoderDirection == -1) { // side effect which signals we are inside a menu - #if HAS_LCD_MENU - if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM; - else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; - else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { menu_item_back::action(); ui.quick_feedback(); } - else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { ui.return_to_status(); ui.quick_feedback(); } - #endif - } - else if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_PULSES_PER_STEP; - else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_PULSES_PER_STEP; - else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) encoderPosition = 0; - #endif - next_button_update_ms = millis() + ADC_MIN_KEY_DELAY; - return true; - } - - return false; - } - -#elif ENABLED(REPRAPWORLD_KEYPAD) - - #if HAS_LCD_MENU + #if DISABLED(ADC_KEYPAD) && HAS_LCD_MENU void lcd_move_x(); void lcd_move_y(); @@ -285,45 +257,74 @@ bool MarlinUI::get_blink() { #endif - inline void handle_reprapworld_keypad() { + bool MarlinUI::handle_keypad() { - static uint8_t keypad_debounce = 0; + #if ENABLED(ADC_KEYPAD) - if (!RRK( EN_REPRAPWORLD_KEYPAD_F1 | EN_REPRAPWORLD_KEYPAD_F2 - | EN_REPRAPWORLD_KEYPAD_F3 | EN_REPRAPWORLD_KEYPAD_DOWN - | EN_REPRAPWORLD_KEYPAD_RIGHT | EN_REPRAPWORLD_KEYPAD_MIDDLE - | EN_REPRAPWORLD_KEYPAD_UP | EN_REPRAPWORLD_KEYPAD_LEFT ) - ) { - if (keypad_debounce > 0) keypad_debounce--; - } - else if (!keypad_debounce) { - keypad_debounce = 2; - - const bool homed = all_axes_homed(); - - #if HAS_LCD_MENU - - if (RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)) ui.goto_screen(menu_move); - - #if DISABLED(DELTA) && Z_HOME_DIR == -1 - if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1); + #define ADC_MIN_KEY_DELAY 100 + if (buttons_reprapworld_keypad) { + #if HAS_ENCODER_ACTION + refresh(LCDVIEW_REDRAW_NOW); + if (encoderDirection == -1) { // side effect which signals we are inside a menu + #if HAS_LCD_MENU + if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition -= ENCODER_STEPS_PER_MENU_ITEM; + else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; + else if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) { menu_item_back::action(); quick_feedback(); } + else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) { return_to_status(); quick_feedback(); } + #endif + } + else if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) encoderPosition += ENCODER_PULSES_PER_STEP; + else if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) encoderPosition -= ENCODER_PULSES_PER_STEP; + else if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) encoderPosition = 0; #endif + next_button_update_ms = millis() + ADC_MIN_KEY_DELAY; + return true; + } - if (homed) { - #if ENABLED(DELTA) || Z_HOME_DIR != -1 - if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1); + #else // !ADC_KEYPAD + + static uint8_t keypad_debounce = 0; + + if (!RRK( EN_REPRAPWORLD_KEYPAD_F1 | EN_REPRAPWORLD_KEYPAD_F2 + | EN_REPRAPWORLD_KEYPAD_F3 | EN_REPRAPWORLD_KEYPAD_DOWN + | EN_REPRAPWORLD_KEYPAD_RIGHT | EN_REPRAPWORLD_KEYPAD_MIDDLE + | EN_REPRAPWORLD_KEYPAD_UP | EN_REPRAPWORLD_KEYPAD_LEFT ) + ) { + if (keypad_debounce > 0) keypad_debounce--; + } + else if (!keypad_debounce) { + keypad_debounce = 2; + + const bool homed = all_axes_homed(); + + #if HAS_LCD_MENU + + if (RRK(EN_REPRAPWORLD_KEYPAD_MIDDLE)) goto_screen(menu_move); + + #if DISABLED(DELTA) && Z_HOME_DIR == -1 + if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1); #endif - if (RRK(EN_REPRAPWORLD_KEYPAD_F3)) _reprapworld_keypad_move(Z_AXIS, -1); - if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) _reprapworld_keypad_move(X_AXIS, -1); - if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) _reprapworld_keypad_move(X_AXIS, 1); - if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) _reprapworld_keypad_move(Y_AXIS, 1); - if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) _reprapworld_keypad_move(Y_AXIS, -1); - } - #endif // HAS_LCD_MENU + if (homed) { + #if ENABLED(DELTA) || Z_HOME_DIR != -1 + if (RRK(EN_REPRAPWORLD_KEYPAD_F2)) _reprapworld_keypad_move(Z_AXIS, 1); + #endif + if (RRK(EN_REPRAPWORLD_KEYPAD_F3)) _reprapworld_keypad_move(Z_AXIS, -1); + if (RRK(EN_REPRAPWORLD_KEYPAD_LEFT)) _reprapworld_keypad_move(X_AXIS, -1); + if (RRK(EN_REPRAPWORLD_KEYPAD_RIGHT)) _reprapworld_keypad_move(X_AXIS, 1); + if (RRK(EN_REPRAPWORLD_KEYPAD_DOWN)) _reprapworld_keypad_move(Y_AXIS, 1); + if (RRK(EN_REPRAPWORLD_KEYPAD_UP)) _reprapworld_keypad_move(Y_AXIS, -1); + } - if (!homed && RRK(EN_REPRAPWORLD_KEYPAD_F1)) enqueue_and_echo_commands_P(PSTR("G28")); - } + #endif // HAS_LCD_MENU + + if (!homed && RRK(EN_REPRAPWORLD_KEYPAD_F1)) enqueue_and_echo_commands_P(PSTR("G28")); + return true; + } + + #endif // !ADC_KEYPAD + + return false; } #endif // REPRAPWORLD_KEYPAD @@ -684,18 +685,19 @@ void MarlinUI::update() { slow_buttons = read_slow_buttons(); // Buttons that take too long to read in interrupt context #endif - #if ENABLED(ADC_KEYPAD) + #if ENABLED(REPRAPWORLD_KEYPAD) - if (handle_adc_keypad()) { + if ( + #if ENABLED(ADC_KEYPAD) + handle_keypad() + #else + handle_keypad() + #endif + ) { #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; #endif } - - #elif ENABLED(REPRAPWORLD_KEYPAD) - - handle_reprapworld_keypad(); - #endif const float abs_diff = ABS(encoderDiff); @@ -990,25 +992,26 @@ void MarlinUI::update() { #endif // LCD_HAS_DIRECTIONAL_BUTTONS - buttons = newbutton - #if ENABLED(LCD_HAS_SLOW_BUTTONS) - | slow_buttons - #endif - ; - #if ENABLED(ADC_KEYPAD) - uint8_t newbutton_reprapworld_keypad = 0; buttons = 0; if (buttons_reprapworld_keypad == 0) { - newbutton_reprapworld_keypad = get_ADC_keyValue(); + uint8_t newbutton_reprapworld_keypad = get_ADC_keyValue(); if (WITHIN(newbutton_reprapworld_keypad, 1, 8)) buttons_reprapworld_keypad = _BV(newbutton_reprapworld_keypad - 1); } - #elif ENABLED(REPRAPWORLD_KEYPAD) + #else - GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad); + buttons = newbutton + #if ENABLED(LCD_HAS_SLOW_BUTTONS) + | slow_buttons + #endif + ; + + #if ENABLED(REPRAPWORLD_KEYPAD) + GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad); + #endif #endif diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index b67b6e96a..dcafb30ee 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -63,8 +63,6 @@ #endif #define LCD_UPDATE_INTERVAL 100 - #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0) - #define BUTTON_PRESSED(BN) !READ(BTN_## BN) #if HAS_LCD_MENU @@ -99,6 +97,9 @@ #define EN_A _BV(BLEN_A) #define EN_B _BV(BLEN_B) + #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0) + #define BUTTON_PRESSED(BN) !READ(BTN_## BN) + #if BUTTON_EXISTS(ENC) #define BLEN_C 2 #define EN_C _BV(BLEN_C) @@ -466,6 +467,10 @@ public: #if HAS_ENCODER_ACTION static volatile uint8_t buttons; + #if ENABLED(REPRAPWORLD_KEYPAD) + static volatile uint8_t buttons_reprapworld_keypad; + static bool handle_keypad(); + #endif #if ENABLED(LCD_HAS_SLOW_BUTTONS) static volatile uint8_t slow_buttons; static uint8_t read_slow_buttons(); diff --git a/Marlin/src/pins/pins_TEENSY35_36.h b/Marlin/src/pins/pins_TEENSY35_36.h index ec7eecab2..9d81d3c0b 100644 --- a/Marlin/src/pins/pins_TEENSY35_36.h +++ b/Marlin/src/pins/pins_TEENSY35_36.h @@ -146,7 +146,16 @@ D8 HEATER_BED_PIN CS1 RX4 A12 31 | 46 * * 47 | 34 A15 PWM #define LCD_PINS_D5 43 #define LCD_PINS_D6 44 #define LCD_PINS_D7 45 +#endif + +#if ENABLED(NEWPANEL) #define BTN_EN1 46 #define BTN_EN2 47 #define BTN_ENC 48 #endif + +#if ENABLED(REPRAPWORLD_KEYPAD) + #define SHIFT_OUT 40 + #define SHIFT_CLK 44 + #define SHIFT_LD 42 +#endif diff --git a/buildroot/share/tests/megaatmega2560_tests b/buildroot/share/tests/megaatmega2560_tests index b4a91611c..6b02e5e87 100755 --- a/buildroot/share/tests/megaatmega2560_tests +++ b/buildroot/share/tests/megaatmega2560_tests @@ -74,11 +74,11 @@ exec_test $1 $2 "... Sled Z Probe, Skew, UBL Cartesian moves, Japanese, and Z pr # ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES # restore_configs -opt_enable Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \ +opt_enable ZONESTAR_LCD Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \ AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS EEPROM_CHITCHAT opt_set NUM_SERVOS 1 opt_enable_adv NO_VOLUMETRICS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET -exec_test $1 $2 "RAMPS with Servo Probe, 3-Point ABL, DEBUG_LEVELING_FEATURE, EEPROM, G38, and more" +exec_test $1 $2 "RAMPS with ZONESTAR_LCD, Servo Probe, 3-Point ABL, DEBUG_LEVELING_FEATURE, EEPROM, G38, and more" # # Test MESH_BED_LEVELING feature, with LCD @@ -313,6 +313,7 @@ opt_set Y_DRIVER_TYPE TMC2208 opt_set Z_DRIVER_TYPE TMC2208 opt_set E0_DRIVER_TYPE TMC2208 opt_disable Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN +opt_enable REPRAPWORLD_KEYPAD opt_enable_adv MONITOR_DRIVER_STATUS STEALTHCHOP HYBRID_THRESHOLD TMC_DEBUG exec_test $1 $2 "TMC2208 Config" #