瀏覽代碼

Attempt to address Bernhard's comments

Refactor configuration to try to make items clearer (what defines a
panel vs what is user changeable).
Robert F-C 11 年之前
父節點
當前提交
6beb42cdf6
共有 4 個文件被更改,包括 134 次插入142 次删除
  1. 11
    16
      Marlin/Configuration.h
  2. 7
    14
      Marlin/Marlin.pde
  3. 10
    4
      Marlin/ultralcd.cpp
  4. 106
    108
      Marlin/ultralcd_implementation_hitachi_HD44780.h

+ 11
- 16
Marlin/Configuration.h 查看文件

@@ -336,44 +336,39 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
336 336
  #define NEWPANEL
337 337
 #endif 
338 338
 
339
-// I2C PANELS
339
+//I2C PANELS
340 340
 
341 341
 //#define LCD_I2C_SAINSMART_YWROBOT
342 342
 #ifdef LCD_I2C_SAINSMART_YWROBOT
343 343
   // This uses the LiquidCrystal_I2C library ( https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home )
344 344
   // Make sure it is placed in the Arduino libraries directory.
345 345
   #define LCD_I2C_TYPE_PCF8575
346
-  #define LCD_I2C
347
-  #define ULTIPANEL
348
-  #define NEWPANEL
349 346
   #define LCD_I2C_ADDRESS 0x27   // I2C Address of the port expander
347
+  #define NEWPANEL
348
+  #define ULTIPANEL 
350 349
 #endif
351 350
 
352
-// PANELOLU2 LCD with status LEDs, separate encoder and click inputs
351
+//PANELOLU2 LCD with status LEDs, separate encoder and click inputs
353 352
 //#define LCD_I2C_PANELOLU2
354 353
 #ifdef LCD_I2C_PANELOLU2
355 354
   // This uses the LiquidTWI2 library ( https://github.com/lincomatic/LiquidTWI2 ).
356 355
   // Make sure it is placed in the Arduino libraries directory.
357 356
   #define LCD_I2C_TYPE_MCP23017
358
-  #define LCD_I2C
359
-  #define ULTIPANEL
357
+  #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
358
+  #define LCD_USE_I2C_BUZZER //comment out to disable buzzer on LCD
360 359
   #define NEWPANEL
361
-  #define LCD_I2C_ADDRESS 0x20
362
-  #define LCD_HAS_I2C_BUZZ //comment out to disable buzzer on LCD
363
-  #define LCD_HAS_STATUS_INDICATORS  
360
+  #define ULTIPANEL 
364 361
 #endif
365 362
 
366
-// VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
363
+//VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
367 364
 //#define LCD_I2C_VIKI
368 365
 #ifdef LCD_I2C_VIKI
369 366
   // This uses the LiquidTWI2 library (https://github.com/lincomatic/LiquidTWI2).
370 367
   // Make sure it is placed in the Arduino libraries directory.
371
-  #define LCD_I2C_TYPE_MCP23017
372
-  #define LCD_I2C
373
-  #define ULTIPANEL
368
+  #define LCD_I2C_TYPE_MCP23017 
369
+  #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
374 370
   #define NEWPANEL
375
-  #define LCD_I2C_ADDRESS 0x20
376
-  #define LCD_HAS_STATUS_INDICATORS  
371
+  #define ULTIPANEL 
377 372
 #endif
378 373
 
379 374
 #ifdef ULTIPANEL

+ 7
- 14
Marlin/Marlin.pde 查看文件

@@ -34,21 +34,14 @@
34 34
 #include "pins.h"
35 35
 
36 36
 #ifdef ULTRA_LCD
37
-  #ifdef LCD_I2C
37
+  #if defined(LCD_I2C_TYPE_PCF8575)
38 38
     #include <Wire.h>
39
-    #if defined(LCD_I2C_TYPE_PCF8575)
40
-      #include <LiquidCrystal_I2C.h>
41
-    #elif defined(LCD_I2C_TYPE_MCP23017)
42
-      #ifdef LCD_I2C_PANELOLU2
43
-        #include <LiquidTWI2.h>
44
-        #ifndef PANELOLU2
45
-          #error You must uncomment #define PANELOLU2 in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly
46
-        #endif
47
-      #else
48
-        #include <LiquidTWI2.h>
49
-      #endif
50
-    #else
51
-      #error Unknown I2C LCD type    
39
+    #include <LiquidCrystal_I2C.h>
40
+  #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)
41
+    #include <Wire.h>
42
+    #include <LiquidTWI2.h>
43
+    #if defined(LCD_I2C_PANELOLU2) && !defined(PANELOLU2)
44
+      #error You must uncomment "#define PANELOLU2" in LiquidTWI2.h for LiquidTWI2.cpp to compile correctly
52 45
     #endif
53 46
   #else
54 47
     #include <LiquidCrystal.h>

+ 10
- 4
Marlin/ultralcd.cpp 查看文件

@@ -705,7 +705,9 @@ void lcd_init()
705 705
     lcd_oldcardstatus = IS_SD_INSERTED;
706 706
 #endif//(SDCARDDETECT > -1)
707 707
     lcd_buttons_update();
708
+#ifdef ULTIPANEL    
708 709
     encoderDiff = 0;
710
+#endif    
709 711
 }
710 712
 
711 713
 void lcd_update()
@@ -714,8 +716,8 @@ void lcd_update()
714 716
     
715 717
     lcd_buttons_update();
716 718
     
717
-    #ifdef LCD_HAS_EXTRA_BUTTONS
718
-    buttons |= lcd_read_extra_buttons(); // buttons which take too long to read in interrupt context
719
+    #ifdef LCD_HAS_SLOW_BUTTONS
720
+    buttons |= lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
719 721
     #endif
720 722
     
721 723
     #if (SDCARDDETECT > -1)
@@ -751,8 +753,12 @@ void lcd_update()
751 753
         if (LCD_CLICKED)
752 754
             timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
753 755
 #endif//ULTIPANEL
754
-        
755 756
         (*currentMenu)();
757
+
758
+#ifdef LCD_HAS_STATUS_INDICATORS
759
+        lcd_implementation_update_indicators();
760
+#endif        
761
+        
756 762
 #ifdef ULTIPANEL
757 763
         if(timeoutToStatus < millis() && currentMenu != lcd_status_screen)
758 764
         {
@@ -860,12 +866,12 @@ void lcd_buttons_update()
860 866
     }
861 867
     lastEncoderBits = enc;
862 868
 }
863
-#endif//ULTIPANEL
864 869
 
865 870
 bool lcd_clicked() 
866 871
 { 
867 872
   return LCD_CLICKED;
868 873
 }
874
+#endif//ULTIPANEL
869 875
 
870 876
 /********************************/
871 877
 /** Float conversion utilities **/

+ 106
- 108
Marlin/ultralcd_implementation_hitachi_HD44780.h 查看文件

@@ -6,72 +6,35 @@
6 6
 * When selecting the rusian language, a slightly different LCD implementation is used to handle UTF8 characters.
7 7
 **/
8 8
 
9
-// Declare LCD class to use
10
-#if defined(LCD_I2C_TYPE_PCF8575)
11
-  // note: these are virtual pins on the PCF8575 controller not Arduino pins
12
-  #define LCD_I2C_PIN_BL  3
13
-  #define LCD_I2C_PIN_EN  2
14
-  #define LCD_I2C_PIN_RW  1
15
-  #define LCD_I2C_PIN_RS  0
16
-  #define LCD_I2C_PIN_D4  4
17
-  #define LCD_I2C_PIN_D5  5
18
-  #define LCD_I2C_PIN_D6  6
19
-  #define LCD_I2C_PIN_D7  7
20
-
21
-  #include <Wire.h>
22
-  #include <LCD.h>
23
-  #include <LiquidCrystal_I2C.h>
24
-  #define LCD_CLASS LiquidCrystal_I2C
25
-  LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7);
26
-#elif defined(LCD_I2C_TYPE_MCP23017)
27
-  //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
28
-  #define LED_A 0x04 //100
29
-  #define LED_B 0x02 //010
30
-  #define LED_C 0x01  //001
31
-
32
-  #include <Wire.h>
33
-  #include <LiquidTWI2.h>
34
-  #define LCD_CLASS LiquidTWI2
35
-  LCD_CLASS lcd(LCD_I2C_ADDRESS);  //An alternative I2C master address can be used in place of "0"
36
-#elif defined(LCD_I2C_TYPE_MCP23008)
37
-  #include <Wire.h>
38
-  #include <LiquidTWI2.h>
39
-  #define LCD_CLASS LiquidTWI2
40
-  LCD_CLASS lcd(LCD_I2C_ADDRESS);  //An alternative I2C master address can be used in place of "0"
41
-#else
42
-  #if LANGUAGE_CHOICE == 6
43
-    #include "LiquidCrystalRus.h"
44
-    #define LCD_CLASS LiquidCrystalRus
45
-  #else 
46
-    #include <LiquidCrystal.h>
47
-    #define LCD_CLASS LiquidCrystal
48
-  #endif  
49
-  LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7
50
-#endif
51
-
52 9
 extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
53 10
 
54
-// provide default button bitmask and encoder definitions (note this is not pin or motherboard specific)
55
-#ifdef LCD_I2C_VIKI
56
-  //encoder rotation values
57
-  #define encrot0 0
58
-  #define encrot1 2
59
-  #define encrot2 3
60
-  #define encrot3 1
61
-
62
-  #define BLEN_C 2
63
-  #define BLEN_B 1
64
-  #define BLEN_A 0
65
-
66
-  #define EN_C (1<<BLEN_C) // The stop/pause/resume button comes through BTN_ENC pin (for consistency with NEWPANEL code)
67
-  #define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
68
-  #define EN_A (1<<BLEN_A)
69
-
70
-  #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
11
+////////////////////////////////////
12
+// Setup button and encode mappings for each panel (into 'buttons' variable)
13
+//
14
+// This is just to map common functions (across different panels) onto the same 
15
+// macro name. The mapping is independent of whether the button is directly connected or 
16
+// via a shift/i2c register.
17
+
18
+#ifdef ULTIPANEL
19
+// All Ultipanels might have an encoder - so this is always be mapped onto first two bits
20
+#define BLEN_B 1
21
+#define BLEN_A 0
22
+
23
+#define EN_B (1<<BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
24
+#define EN_A (1<<BLEN_A)
25
+
26
+//
27
+// Setup other button mappings of each panel
28
+//
29
+#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)
71 34
   
72 35
   // button and encoder bit positions within 'buttons'
73
-  #define B_ST (EN_C)                             // The pause/stop/resume button is mapped to EN_C for consistency with NEWPANEL 
74
-  #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET)    // The remaining buttons are I2C read buttons.
36
+  #define B_ST (EN_C)                             // Map the pause/stop/resume button into its normalized functional name 
37
+  #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET)    // The remaining normalized buttons are all read via I2C
75 38
   #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
76 39
   #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
77 40
   #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
@@ -79,41 +42,16 @@ extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
79 42
 
80 43
   #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
81 44
 
82
-  // I2C buttons are likely to take too long to read inside interrupt context and so we read them during lcd_update
83
-  #define LCD_HAS_EXTRA_BUTTONS
84
-  
85
-#elif defined(NEWPANEL)
86
-  //from the same bit in the RAMPS Newpanel define
87
-  //encoder rotation values
88
-  #define encrot0 0
89
-  #define encrot1 2
90
-  #define encrot2 3
91
-  #define encrot3 1
92
- 
93
-  #define BLEN_C 2
94
-  #define BLEN_B 1
95
-  #define BLEN_A 0
45
+  // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
46
+  #define LCD_HAS_SLOW_BUTTONS
96 47
 
48
+#elif defined(NEWPANEL)
49
+  // Standard Newpanel has just a single button (all direclty connected)
50
+  #define BLEN_C 2 // == select button
97 51
   #define EN_C (1<<BLEN_C)
98
-  #define EN_B (1<<BLEN_B)
99
-  #define EN_A (1<<BLEN_A)
100
-
101 52
   #define LCD_CLICKED (buttons&EN_C)
102 53
   
103 54
 #else // old style ULTIPANEL
104
-  //encoder rotation values
105
-  #ifndef ULTIMAKERCONTROLLER
106
-    #define encrot0 0
107
-    #define encrot1 2
108
-    #define encrot2 3
109
-    #define encrot3 1
110
-  #else
111
-    #define encrot0 0
112
-    #define encrot1 1
113
-    #define encrot2 3
114
-    #define encrot3 2
115
-  #endif
116
-
117 55
   //bits in the shift register that carry the buttons for:
118 56
   // left up center down right red(stop)
119 57
   #define BL_LE 7
@@ -123,9 +61,6 @@ extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
123 61
   #define BL_RI 3
124 62
   #define BL_ST 2
125 63
 
126
-  #define BLEN_B 1
127
-  #define BLEN_A 0
128
-
129 64
   //automatic, do not change
130 65
   #define B_LE (1<<BL_LE)
131 66
   #define B_UP (1<<BL_UP)
@@ -133,15 +68,78 @@ extern volatile uint8_t buttons;  //the last checked buttons in a bit array.
133 68
   #define B_DW (1<<BL_DW)
134 69
   #define B_RI (1<<BL_RI)
135 70
   #define B_ST (1<<BL_ST)
136
-  #define EN_B (1<<BLEN_B)
137
-  #define EN_A (1<<BLEN_A)
138 71
   
139 72
   #define LCD_CLICKED (buttons&(B_MI|B_ST))
140 73
 #endif//else NEWPANEL
141 74
 
142
-#ifdef LCD_HAS_STATUS_INDICATORS  
143
-//forward declaration
144
-static void lcd_implementation_update_indicators();
75
+////////////////////////
76
+// Setup Rotary Encoder Bit Values (for two pin encoders to indicate movement)
77
+// These values are independent of which pins are used for EN_A and EN_B indications
78
+// The rotary encoder part is also independent to the chipset used for the LCD
79
+#if defined(EN_A) && defined(EN_B)
80
+  #ifndef ULTIMAKERCONTROLLER
81
+    #define encrot0 0
82
+    #define encrot1 2
83
+    #define encrot2 3
84
+    #define encrot3 1
85
+  #else
86
+    #define encrot0 0
87
+    #define encrot1 1
88
+    #define encrot2 3
89
+    #define encrot3 2
90
+  #endif
91
+#endif
92
+
93
+#endif //ULTIPANEL
94
+
95
+////////////////////////////////////
96
+// Create LCD class instance and chipset-specific information
97
+#if defined(LCD_I2C_TYPE_PCF8575)
98
+  // note: these are register mapped pins on the PCF8575 controller not Arduino pins
99
+  #define LCD_I2C_PIN_BL  3
100
+  #define LCD_I2C_PIN_EN  2
101
+  #define LCD_I2C_PIN_RW  1
102
+  #define LCD_I2C_PIN_RS  0
103
+  #define LCD_I2C_PIN_D4  4
104
+  #define LCD_I2C_PIN_D5  5
105
+  #define LCD_I2C_PIN_D6  6
106
+  #define LCD_I2C_PIN_D7  7
107
+
108
+  #include <Wire.h>
109
+  #include <LCD.h>
110
+  #include <LiquidCrystal_I2C.h>
111
+  #define LCD_CLASS LiquidCrystal_I2C
112
+  LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7);
113
+  
114
+#elif defined(LCD_I2C_TYPE_MCP23017)
115
+  //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
116
+  #define LED_A 0x04 //100
117
+  #define LED_B 0x02 //010
118
+  #define LED_C 0x01 //001
119
+
120
+  #define LCD_HAS_STATUS_INDICATORS
121
+
122
+  #include <Wire.h>
123
+  #include <LiquidTWI2.h>
124
+  #define LCD_CLASS LiquidTWI2
125
+  LCD_CLASS lcd(LCD_I2C_ADDRESS);
126
+  
127
+#elif defined(LCD_I2C_TYPE_MCP23008)
128
+  #include <Wire.h>
129
+  #include <LiquidTWI2.h>
130
+  #define LCD_CLASS LiquidTWI2
131
+  LCD_CLASS lcd(LCD_I2C_ADDRESS);  
132
+  
133
+#else
134
+  // Standard directly connected LCD implementations
135
+  #if LANGUAGE_CHOICE == 6
136
+    #include "LiquidCrystalRus.h"
137
+    #define LCD_CLASS LiquidCrystalRus
138
+  #else 
139
+    #include <LiquidCrystal.h>
140
+    #define LCD_CLASS LiquidCrystal
141
+  #endif  
142
+  LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7
145 143
 #endif
146 144
 
147 145
 /* Custom characters defined in the first 8 characters of the LCD */
@@ -247,13 +245,16 @@ static void lcd_implementation_init()
247 245
     lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE);
248 246
     lcd.setBacklight(HIGH);
249 247
   #endif
248
+  
250 249
 #elif defined(LCD_I2C_TYPE_MCP23017)
251 250
   	lcd.setMCPType(LTI_TYPE_MCP23017);
252 251
     lcd.begin(LCD_WIDTH, LCD_HEIGHT);
253 252
     lcd.setBacklight(0); //set all the LEDs off to begin with
253
+    
254 254
 #elif defined(LCD_I2C_TYPE_MCP23008)
255 255
   	lcd.setMCPType(LTI_TYPE_MCP23008);
256 256
     lcd.begin(LCD_WIDTH, LCD_HEIGHT);
257
+    
257 258
 #else
258 259
     lcd.begin(LCD_WIDTH, LCD_HEIGHT);
259 260
 #endif
@@ -439,9 +440,6 @@ static void lcd_implementation_status_screen()
439 440
     //Status message line on the last line
440 441
     lcd.setCursor(0, LCD_HEIGHT - 1);
441 442
     lcd.print(lcd_status_message);
442
-#ifdef LCD_HAS_STATUS_INDICATORS
443
-    lcd_implementation_update_indicators();
444
-#endif    
445 443
 }
446 444
 static void lcd_implementation_drawmenu_generic(uint8_t row, const char* pstr, char pre_char, char post_char)
447 445
 {
@@ -630,7 +628,7 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* pst
630 628
 
631 629
 static void lcd_implementation_quick_feedback()
632 630
 {
633
-#ifdef LCD_HAS_I2C_BUZZ
631
+#ifdef LCD_USE_I2C_BUZZER
634 632
     lcd.buzz(300,4000);
635 633
 #elif defined(BEEPER) && BEEPER > -1
636 634
     SET_OUTPUT(BEEPER);
@@ -665,12 +663,12 @@ static void lcd_implementation_update_indicators()
665 663
 }
666 664
 #endif
667 665
 
668
-#ifdef LCD_HAS_EXTRA_BUTTONS
669
-static uint8_t lcd_read_extra_buttons()
666
+#ifdef LCD_HAS_SLOW_BUTTONS
667
+static uint8_t lcd_implementation_read_slow_buttons()
670 668
 {
671 669
   #ifdef LCD_I2C_TYPE_MCP23017
672
-    // the I2C button bit positions are shifted by three bits from the native LiquidTWI2 position
673
-    // this is potentially too slow to call inside interrupt context
670
+    // Reading these buttons this is likely to be too slow to call inside interrupt context
671
+    // so they are called during normal lcd_update
674 672
     return lcd.readButtons() << B_I2C_BTN_OFFSET; 
675 673
   #endif
676 674
 }

Loading…
取消
儲存