Kaynağa Gözat

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).
Robert F-C 11 yıl önce
ebeveyn
işleme
7bad72359c

+ 9
- 5
Marlin/Configuration.h Dosyayı Görüntüle

@@ -351,8 +351,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
351 351
 //PANELOLU2 LCD with status LEDs, separate encoder and click inputs
352 352
 //#define LCD_I2C_PANELOLU2
353 353
 #ifdef LCD_I2C_PANELOLU2
354
-  // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ).
355
-  // Make sure it is placed in the Arduino libraries directory.
354
+  // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 )
355
+  // Make sure it is placed in the Arduino or Sketchbook libraries directory.
356
+  // Note: The PANELOLU2 encoder click input can either be directly connected to a pin 
357
+  //       (if BTN_ENC defined to != -1) or read through I2C (when BTN_ENC == -1). 
356 358
   #define LCD_I2C_TYPE_MCP23017
357 359
   #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
358 360
   #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
360 362
   #define ULTIPANEL 
361 363
 #endif
362 364
 
363
-//VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
365
+//Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
364 366
 //#define LCD_I2C_VIKI
365 367
 #ifdef LCD_I2C_VIKI
366
-  // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2).
367
-  // Make sure it is placed in the Arduino libraries directory.
368
+  // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 )
369
+  // Make sure it is placed in the Arduino or Sketchbook libraries directory.
370
+  // Note: The pause/stop/resume LCD button pin should be connected to the Arduino
371
+  //       BTN_ENC pin (or set BTN_ENC to -1 if not used)
368 372
   #define LCD_I2C_TYPE_MCP23017 
369 373
   #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
370 374
   #define NEWPANEL

+ 5
- 1
Marlin/ultralcd.cpp Dosyayı Görüntüle

@@ -686,11 +686,13 @@ void lcd_init()
686 686
 #ifdef NEWPANEL
687 687
     pinMode(BTN_EN1,INPUT);
688 688
     pinMode(BTN_EN2,INPUT); 
689
-    pinMode(BTN_ENC,INPUT); 
690 689
     pinMode(SDCARDDETECT,INPUT);
691 690
     WRITE(BTN_EN1,HIGH);
692 691
     WRITE(BTN_EN2,HIGH);
692
+  #if defined(BTN_ENC) && BTN_ENC > -1
693
+    pinMode(BTN_ENC,INPUT); 
693 694
     WRITE(BTN_ENC,HIGH);
695
+  #endif    
694 696
 #else
695 697
     pinMode(SHIFT_CLK,OUTPUT);
696 698
     pinMode(SHIFT_LD,OUTPUT);
@@ -809,8 +811,10 @@ void lcd_buttons_update()
809 811
     uint8_t newbutton=0;
810 812
     if(READ(BTN_EN1)==0)  newbutton|=EN_A;
811 813
     if(READ(BTN_EN2)==0)  newbutton|=EN_B;
814
+  #if defined(BTN_ENC) && BTN_ENC > -1
812 815
     if((blocking_enc<millis()) && (READ(BTN_ENC)==0))
813 816
         newbutton |= EN_C;
817
+  #endif      
814 818
     buttons = newbutton;
815 819
 #else   //read it from the shift register
816 820
     uint8_t newbutton=0;

+ 31
- 11
Marlin/ultralcd_implementation_hitachi_HD44780.h Dosyayı Görüntüle

@@ -23,32 +23,52 @@ extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
23 23
 #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
24 24
 #define EN_A (1<<BLEN_A)
25 25
 
26
+#if defined(BTN_ENC) && BTN_ENC > -1
27
+  // encoder click is directly connected
28
+  #define BLEN_C 2 
29
+  #define EN_C (1<<BLEN_C) 
30
+#endif 
31
+  
26 32
 //
27 33
 // Setup other button mappings of each panel
28 34
 //
29 35
 #if defined(LCD_I2C_VIKI)
30
-  #define BLEN_C 2 // == pause/stop/restart button connected to BTN_ENC pin (named for consistency with NEWPANEL code)
31
-  #define EN_C (1<<BLEN_C) 
32
-
33
-  #define B_I2C_BTN_OFFSET (BLEN_C+1) // (the first three bit positions reserved for EN_A, EN_B, EN_C)
36
+  #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
34 37
   
35 38
   // button and encoder bit positions within 'buttons'
36
-  #define B_ST (EN_C)                             // Map the pause/stop/resume button into its normalized functional name 
37 39
   #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET)    // The remaining normalized buttons are all read via I2C
38 40
   #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
39 41
   #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
40 42
   #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
41 43
   #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
42 44
 
43
-  #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
45
+  #if defined(BTN_ENC) && BTN_ENC > -1 
46
+    // the pause/stop/restart button is connected to BTN_ENC when used
47
+    #define B_ST (EN_C)                            // Map the pause/stop/resume button into its normalized functional name 
48
+    #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
49
+  #else
50
+    #define LCD_CLICKED (buttons&(B_MI|B_RI))
51
+  #endif  
44 52
 
45 53
   // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
46 54
   #define LCD_HAS_SLOW_BUTTONS
47 55
 
56
+#elif defined(LCD_I2C_PANELOLU2)
57
+  #if !defined(BTN_ENC) || BTN_ENC == -1 
58
+    // encoder click is connected through I2C (rather than directly connected)
59
+    #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
60
+  
61
+    #define B_MI (ENCODER_C<<B_I2C_BTN_OFFSET)
62
+
63
+    #define LCD_CLICKED (buttons&B_MI)
64
+
65
+    // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
66
+    #define LCD_HAS_SLOW_BUTTONS
67
+  #else
68
+    #define LCD_CLICKED (buttons&EN_C)  
69
+  #endif
70
+
48 71
 #elif defined(NEWPANEL)
49
-  // Standard Newpanel has just a single button (all direclty connected)
50
-  #define BLEN_C 2 // == select button
51
-  #define EN_C (1<<BLEN_C)
52 72
   #define LCD_CLICKED (buttons&EN_C)
53 73
   
54 74
 #else // old style ULTIPANEL
@@ -88,7 +108,7 @@ extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
88 108
     #define encrot2 3
89 109
     #define encrot3 2
90 110
   #endif
91
-#endif
111
+#endif 
92 112
 
93 113
 #endif //ULTIPANEL
94 114
 
@@ -629,7 +649,7 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pst
629 649
 static void lcd_implementation_quick_feedback()
630 650
 {
631 651
 #ifdef LCD_USE_I2C_BUZZER
632
-    lcd.buzz(300,4000);
652
+    lcd.buzz(60,1000/6);
633 653
 #elif defined(BEEPER) && BEEPER > -1
634 654
     SET_OUTPUT(BEEPER);
635 655
     for(int8_t i=0;i<10;i++)

Loading…
İptal
Kaydet