From 10c8c034bdc529ced1d0b70b5f8a1079cccc5f66 Mon Sep 17 00:00:00 2001 From: 7eggert <7eggert@gmx.de> Date: Tue, 12 Mar 2019 00:10:56 +0100 Subject: [PATCH] Allow both encoder and ADC keypad (#13355) --- Marlin/src/core/macros.h | 3 ++- Marlin/src/inc/Conditionals_LCD.h | 6 ------ Marlin/src/lcd/ultralcd.cpp | 6 +++--- Marlin/src/lcd/ultralcd.h | 12 +++++++++++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index b438db9201..7a1bb45c51 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -194,7 +194,8 @@ #define DECREMENT_(n) DEC_ ##n #define DECREMENT(n) DECREMENT_(n) -#define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0) +#define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0) +#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0) #define MMM_TO_MMS(MM_M) ((MM_M)/60.0f) #define MMS_TO_MMM(MM_S) ((MM_S)*60.0f) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index efc91ea673..1eb610b3d7 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -320,12 +320,6 @@ #define HAS_LCD_MENU (ENABLED(ULTIPANEL) && DISABLED(NO_LCD_MENUS)) #define HAS_ADC_BUTTONS ENABLED(ADC_KEYPAD) -#define HAS_DIGITAL_BUTTONS (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) -#define HAS_SHIFT_ENCODER (!HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL)))) -#define HAS_ENCODER_WHEEL (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) - -// I2C buttons must be read in the main thread -#define HAS_SLOW_BUTTONS (ENABLED(LCD_I2C_VIKI) || ENABLED(LCD_I2C_PANELOLU2)) #if HAS_GRAPHICAL_LCD /** diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index ab973e9e2c..3a2bc3d3c2 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -1073,15 +1073,15 @@ void MarlinUI::update() { | slow_buttons #endif ; - #elif HAS_ADC_BUTTONS - buttons = 0; + #endif + + #if HAS_ADC_BUTTONS if (keypad_buttons == 0) { const uint8_t b = get_ADC_keyValue(); if (WITHIN(b, 1, 8)) keypad_buttons = _BV(b - 1); } - #endif #if HAS_SHIFT_ENCODER diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index b50272ae9e..56d097bb93 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -27,8 +27,19 @@ #include "../libs/buzzer.h" #endif +#define HAS_DIGITAL_BUTTONS (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL) \ + || (BUTTON_EXISTS(EN1) && BUTTON_EXISTS(EN2)) \ + || BUTTON_EXISTS(ENC) || BUTTON_EXISTS(BACK) \ + || BUTTON_EXISTS(UP) || BUTTON_EXISTS(DWN) \ + || BUTTON_EXISTS(LFT) || BUTTON_EXISTS(RT)) + +#define HAS_SHIFT_ENCODER (!HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL)))) +#define HAS_ENCODER_WHEEL ((!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || (BUTTON_EXISTS(EN1) && BUTTON_EXISTS(EN2)) ) #define HAS_ENCODER_ACTION (HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY)) +// I2C buttons must be read in the main thread +#define HAS_SLOW_BUTTONS (ENABLED(LCD_I2C_VIKI) || ENABLED(LCD_I2C_PANELOLU2)) + #if HAS_SPI_LCD #include "../Marlin.h" @@ -133,7 +144,6 @@ #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)