|
1 #ifndef ULTRALCD_H |
|
2 #define ULTRALCD_H |
|
3 #include "Marlin.h" |
|
4 #ifdef ULTRA_LCD |
|
5 #include <LiquidCrystal.h> |
|
6 void lcd_status(); |
|
7 void lcd_init(); |
|
8 void lcd_status(const char* message); |
|
9 void beep(); |
|
10 void buttons_init(); |
|
11 void buttons_check(); |
|
12 |
|
13 #define LCD_UPDATE_INTERVAL 100 |
|
14 #define STATUSTIMEOUT 15000 |
|
15 extern LiquidCrystal lcd; |
|
16 extern volatile char buttons; //the last checked buttons in a bit array. |
|
17 |
|
18 #ifdef NEWPANEL |
|
19 #define EN_C (1<<BLEN_C) |
|
20 #define EN_B (1<<BLEN_B) |
|
21 #define EN_A (1<<BLEN_A) |
|
22 |
|
23 #define CLICKED (buttons&EN_C) |
|
24 #define BLOCK {blocking=millis()+blocktime;} |
|
25 #if (SDCARDDETECT > -1) |
|
26 #ifdef SDCARDDETECTINVERTED |
|
27 #define CARDINSERTED (READ(SDCARDDETECT)!=0) |
|
28 #else |
|
29 #define CARDINSERTED (READ(SDCARDDETECT)==0) |
|
30 #endif |
|
31 #endif //SDCARDTETECTINVERTED |
|
32 |
|
33 #else |
|
34 |
|
35 //atomatic, do not change |
|
36 #define B_LE (1<<BL_LE) |
|
37 #define B_UP (1<<BL_UP) |
|
38 #define B_MI (1<<BL_MI) |
|
39 #define B_DW (1<<BL_DW) |
|
40 #define B_RI (1<<BL_RI) |
|
41 #define B_ST (1<<BL_ST) |
|
42 #define EN_B (1<<BLEN_B) |
|
43 #define EN_A (1<<BLEN_A) |
|
44 |
|
45 #define CLICKED ((buttons&B_MI)||(buttons&B_ST)) |
|
46 #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;} |
|
47 |
|
48 #endif |
|
49 |
|
50 // blocking time for recognizing a new keypress of one key, ms |
|
51 #define blocktime 500 |
|
52 #define lcdslow 5 |
|
53 |
|
54 enum MainStatus{Main_Status, Main_Menu, Main_Prepare,Sub_PrepareMove, Main_Control, Main_SD,Sub_TempControl,Sub_MotionControl,Sub_RetractControl}; |
|
55 |
|
56 class MainMenu{ |
|
57 public: |
|
58 MainMenu(); |
|
59 void update(); |
|
60 int8_t activeline; |
|
61 MainStatus status; |
|
62 uint8_t displayStartingRow; |
|
63 |
|
64 void showStatus(); |
|
65 void showMainMenu(); |
|
66 void showPrepare(); |
|
67 void showTune(); |
|
68 void showControl(); |
|
69 void showControlMotion(); |
|
70 void showControlTemp(); |
|
71 void showControlRetract(); |
|
72 void showAxisMove(); |
|
73 void showSD(); |
|
74 bool force_lcd_update; |
|
75 long lastencoderpos; |
|
76 int8_t lineoffset; |
|
77 int8_t lastlineoffset; |
|
78 |
|
79 bool linechanging; |
|
80 |
|
81 bool tune; |
|
82 |
|
83 private: |
|
84 FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile long &encoderpos) |
|
85 { |
|
86 if(linechanging) return; // an item is changint its value, do not switch lines hence |
|
87 lastlineoffset=lineoffset; |
|
88 long curencoderpos=encoderpos; |
|
89 force_lcd_update=false; |
|
90 if( (abs(curencoderpos-lastencoderpos)<lcdslow) ) |
|
91 { |
|
92 lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' '); |
|
93 if(curencoderpos<0) |
|
94 { |
|
95 lineoffset--; |
|
96 if(lineoffset<0) lineoffset=0; |
|
97 curencoderpos=lcdslow-1; |
|
98 } |
|
99 if(curencoderpos>(LCD_HEIGHT-1+1)*lcdslow) |
|
100 { |
|
101 lineoffset++; |
|
102 curencoderpos=(LCD_HEIGHT-1)*lcdslow; |
|
103 if(lineoffset>(maxlines+1-LCD_HEIGHT)) |
|
104 lineoffset=maxlines+1-LCD_HEIGHT; |
|
105 if(curencoderpos>maxlines*lcdslow) |
|
106 curencoderpos=maxlines*lcdslow; |
|
107 } |
|
108 lastencoderpos=encoderpos=curencoderpos; |
|
109 activeline=curencoderpos/lcdslow; |
|
110 if(activeline<0) activeline=0; |
|
111 if(activeline>LCD_HEIGHT-1) activeline=LCD_HEIGHT-1; |
|
112 if(activeline>maxlines) |
|
113 { |
|
114 activeline=maxlines; |
|
115 curencoderpos=maxlines*lcdslow; |
|
116 } |
|
117 if(lastlineoffset!=lineoffset) |
|
118 force_lcd_update=true; |
|
119 lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003'); |
|
120 } |
|
121 } |
|
122 |
|
123 FORCE_INLINE void clearIfNecessary() |
|
124 { |
|
125 if(lastlineoffset!=lineoffset ||force_lcd_update) |
|
126 { |
|
127 force_lcd_update=true; |
|
128 lcd.clear(); |
|
129 } |
|
130 } |
|
131 }; |
|
132 |
|
133 //conversion routines, could need some overworking |
|
134 char *ftostr51(const float &x); |
|
135 char *ftostr52(const float &x); |
|
136 char *ftostr31(const float &x); |
|
137 char *ftostr3(const float &x); |
|
138 |
|
139 |
|
140 #define LCD_INIT lcd_init(); |
|
141 #define LCD_MESSAGE(x) lcd_status(x); |
|
142 #define LCD_MESSAGEPGM(x) lcd_statuspgm(MYPGM(x)); |
|
143 #define LCD_STATUS lcd_status() |
|
144 #else //no lcd |
|
145 #define LCD_INIT |
|
146 #define LCD_STATUS |
|
147 #define LCD_MESSAGE(x) |
|
148 #define LCD_MESSAGEPGM(x) |
|
149 FORCE_INLINE void lcd_status() {}; |
|
150 |
|
151 #define CLICKED false |
|
152 #define BLOCK ; |
|
153 #endif |
|
154 |
|
155 void lcd_statuspgm(const char* message); |
|
156 |
|
157 char *ftostr3(const float &x); |
|
158 char *itostr2(const uint8_t &x); |
|
159 char *ftostr31(const float &x); |
|
160 char *ftostr32(const float &x); |
|
161 char *itostr31(const int &xx); |
|
162 char *itostr3(const int &xx); |
|
163 char *itostr4(const int &xx); |
|
164 char *ftostr51(const float &x); |
|
165 #endif //ULTRALCD |