Browse Source

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).
pull/1/head
Robert F-C 12 years ago
parent
commit
7bad72359c
  1. 14
      Marlin/Configuration.h
  2. 6
      Marlin/ultralcd.cpp
  3. 38
      Marlin/ultralcd_implementation_hitachi_HD44780.h

14
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 //PANELOLU2 LCD with status LEDs, separate encoder and click inputs
//#define LCD_I2C_PANELOLU2 //#define LCD_I2C_PANELOLU2
#ifdef LCD_I2C_PANELOLU2 #ifdef LCD_I2C_PANELOLU2
// This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ). // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 )
// Make sure it is placed in the Arduino libraries directory. // 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_TYPE_MCP23017
#define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
#define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD #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 #define ULTIPANEL
#endif #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 //#define LCD_I2C_VIKI
#ifdef LCD_I2C_VIKI #ifdef LCD_I2C_VIKI
// This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2). // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 )
// Make sure it is placed in the Arduino libraries directory. // 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_TYPE_MCP23017
#define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
#define NEWPANEL #define NEWPANEL

6
Marlin/ultralcd.cpp

@ -686,11 +686,13 @@ void lcd_init()
#ifdef NEWPANEL #ifdef NEWPANEL
pinMode(BTN_EN1,INPUT); pinMode(BTN_EN1,INPUT);
pinMode(BTN_EN2,INPUT); pinMode(BTN_EN2,INPUT);
pinMode(BTN_ENC,INPUT);
pinMode(SDCARDDETECT,INPUT); pinMode(SDCARDDETECT,INPUT);
WRITE(BTN_EN1,HIGH); WRITE(BTN_EN1,HIGH);
WRITE(BTN_EN2,HIGH); WRITE(BTN_EN2,HIGH);
#if defined(BTN_ENC) && BTN_ENC > -1
pinMode(BTN_ENC,INPUT);
WRITE(BTN_ENC,HIGH); WRITE(BTN_ENC,HIGH);
#endif
#else #else
pinMode(SHIFT_CLK,OUTPUT); pinMode(SHIFT_CLK,OUTPUT);
pinMode(SHIFT_LD,OUTPUT); pinMode(SHIFT_LD,OUTPUT);
@ -809,8 +811,10 @@ void lcd_buttons_update()
uint8_t newbutton=0; uint8_t newbutton=0;
if(READ(BTN_EN1)==0) newbutton|=EN_A; if(READ(BTN_EN1)==0) newbutton|=EN_A;
if(READ(BTN_EN2)==0) newbutton|=EN_B; if(READ(BTN_EN2)==0) newbutton|=EN_B;
#if defined(BTN_ENC) && BTN_ENC > -1
if((blocking_enc<millis()) && (READ(BTN_ENC)==0)) if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
newbutton |= EN_C; newbutton |= EN_C;
#endif
buttons = newbutton; buttons = newbutton;
#else //read it from the shift register #else //read it from the shift register
uint8_t newbutton=0; uint8_t newbutton=0;

38
Marlin/ultralcd_implementation_hitachi_HD44780.h

@ -23,32 +23,52 @@ extern volatile uint8_t buttons; //the last checked buttons in a bit array.
#define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2 #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
#define EN_A (1<<BLEN_A) #define EN_A (1<<BLEN_A)
#if defined(BTN_ENC) && BTN_ENC > -1
// encoder click is directly connected
#define BLEN_C 2
#define EN_C (1<<BLEN_C)
#endif
// //
// Setup other button mappings of each panel // Setup other button mappings of each panel
// //
#if defined(LCD_I2C_VIKI) #if defined(LCD_I2C_VIKI)
#define BLEN_C 2 // == pause/stop/restart button connected to BTN_ENC pin (named for consistency with NEWPANEL code) #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
#define EN_C (1<<BLEN_C)
#define B_I2C_BTN_OFFSET (BLEN_C+1) // (the first three bit positions reserved for EN_A, EN_B, EN_C)
// button and encoder bit positions within 'buttons' // button and encoder bit positions within 'buttons'
#define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
#define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
#define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET) #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
#define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET) #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
#define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET) #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
#define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET) #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
#if defined(BTN_ENC) && BTN_ENC > -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. #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 // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
#define LCD_HAS_SLOW_BUTTONS #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<<B_I2C_BTN_OFFSET)
#define LCD_CLICKED (buttons&B_MI)
// I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
#define LCD_HAS_SLOW_BUTTONS
#else
#define LCD_CLICKED (buttons&EN_C)
#endif
#elif defined(NEWPANEL) #elif defined(NEWPANEL)
// Standard Newpanel has just a single button (all direclty connected)
#define BLEN_C 2 // == select button
#define EN_C (1<<BLEN_C)
#define LCD_CLICKED (buttons&EN_C) #define LCD_CLICKED (buttons&EN_C)
#else // old style ULTIPANEL #else // old style ULTIPANEL
@ -629,7 +649,7 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pst
static void lcd_implementation_quick_feedback() static void lcd_implementation_quick_feedback()
{ {
#ifdef LCD_USE_I2C_BUZZER #ifdef LCD_USE_I2C_BUZZER
lcd.buzz(300,4000); lcd.buzz(60,1000/6);
#elif defined(BEEPER) && BEEPER > -1 #elif defined(BEEPER) && BEEPER > -1
SET_OUTPUT(BEEPER); SET_OUTPUT(BEEPER);
for(int8_t i=0;i<10;i++) for(int8_t i=0;i<10;i++)

Loading…
Cancel
Save