From 7bad72359c5f2c78096810fffbf809bb8c30b58b Mon Sep 17 00:00:00 2001 From: Robert F-C Date: Sun, 3 Mar 2013 18:47:50 +1100 Subject: [PATCH] Support encoder click on PANELOLU2 being read through I2C This change also handles the case where the pause/stop/restart button on the VIKI is not used. Make LCD I2C buzz sound the same as the normal buzz (300ms is too long for quick feedback). --- Marlin/Configuration.h | 14 ++++--- Marlin/ultralcd.cpp | 6 ++- .../ultralcd_implementation_hitachi_HD44780.h | 42 ++++++++++++++----- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 492a32361b..ba20c6c04b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -351,8 +351,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th //PANELOLU2 LCD with status LEDs, separate encoder and click inputs //#define LCD_I2C_PANELOLU2 #ifdef LCD_I2C_PANELOLU2 - // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). - // Make sure it is placed in the Arduino libraries directory. + // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // Note: The PANELOLU2 encoder click input can either be directly connected to a pin + // (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). #define LCD_I2C_TYPE_MCP23017 #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD @@ -360,11 +362,13 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #define ULTIPANEL #endif -//VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs +//Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs //#define LCD_I2C_VIKI #ifdef LCD_I2C_VIKI - // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). - // Make sure it is placed in the Arduino libraries directory. + // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ) + // Make sure it is placed in the Arduino or Sketchbook libraries directory. + // Note: The pause/stop/resume LCD button pin should be connected to the Arduino + // BTN_ENC pin (or set BTN_ENC to -1 if not used) #define LCD_I2C_TYPE_MCP23017 #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define NEWPANEL diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index ed259196d7..523fcd4617 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -686,11 +686,13 @@ void lcd_init() #ifdef NEWPANEL pinMode(BTN_EN1,INPUT); pinMode(BTN_EN2,INPUT); - pinMode(BTN_ENC,INPUT); pinMode(SDCARDDETECT,INPUT); WRITE(BTN_EN1,HIGH); WRITE(BTN_EN2,HIGH); + #if defined(BTN_ENC) && BTN_ENC > -1 + pinMode(BTN_ENC,INPUT); WRITE(BTN_ENC,HIGH); + #endif #else pinMode(SHIFT_CLK,OUTPUT); pinMode(SHIFT_LD,OUTPUT); @@ -809,8 +811,10 @@ void lcd_buttons_update() uint8_t newbutton=0; if(READ(BTN_EN1)==0) newbutton|=EN_A; if(READ(BTN_EN2)==0) newbutton|=EN_B; + #if defined(BTN_ENC) && BTN_ENC > -1 if((blocking_enc -1 + // encoder click is directly connected + #define BLEN_C 2 + #define EN_C (1< -1 + // the pause/stop/restart button is connected to BTN_ENC when used + #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name + #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop. + #else + #define LCD_CLICKED (buttons&(B_MI|B_RI)) + #endif // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update #define LCD_HAS_SLOW_BUTTONS +#elif defined(LCD_I2C_PANELOLU2) + #if !defined(BTN_ENC) || BTN_ENC == -1 + // encoder click is connected through I2C (rather than directly connected) + #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C) + + #define B_MI (ENCODER_C< -1 SET_OUTPUT(BEEPER); for(int8_t i=0;i<10;i++)