|
@@ -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
|
}
|