chiark / gitweb /
Add M401 - Wait for user on LCD button press
[marlin.git] / Marlin / ultralcd.h
1 #ifndef __ULTRALCDH
2 #define __ULTRALCDH
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=0;  //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};
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 showAxisMove();
72     void showSD();
73     bool force_lcd_update;
74     long lastencoderpos;
75     int8_t lineoffset;
76     int8_t lastlineoffset;
77     
78     bool linechanging;
79     
80     bool tune;
81     
82   private:
83     FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile long &encoderpos)
84     {
85       if(linechanging) return; // an item is changint its value, do not switch lines hence
86       lastlineoffset=lineoffset; 
87       long curencoderpos=encoderpos;  
88       force_lcd_update=false;
89       if(  (abs(curencoderpos-lastencoderpos)<lcdslow) ) 
90       { 
91         lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' '); 
92         if(curencoderpos<0)  
93         {  
94           lineoffset--; 
95           if(lineoffset<0) lineoffset=0; 
96           curencoderpos=lcdslow-1;
97         } 
98         if(curencoderpos>(LCD_HEIGHT-1+1)*lcdslow) 
99         { 
100           lineoffset++; 
101           curencoderpos=(LCD_HEIGHT-1)*lcdslow; 
102           if(lineoffset>(maxlines+1-LCD_HEIGHT)) 
103             lineoffset=maxlines+1-LCD_HEIGHT; 
104           if(curencoderpos>maxlines*lcdslow) 
105             curencoderpos=maxlines*lcdslow; 
106         } 
107         lastencoderpos=encoderpos=curencoderpos;
108         activeline=curencoderpos/lcdslow;
109         if(activeline<0) activeline=0;
110         if(activeline>LCD_HEIGHT-1) activeline=LCD_HEIGHT-1;
111         if(activeline>maxlines) 
112         {
113           activeline=maxlines;
114           curencoderpos=maxlines*lcdslow;
115         }
116         if(lastlineoffset!=lineoffset)
117           force_lcd_update=true;
118         lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');    
119       } 
120     }
121     
122     FORCE_INLINE void clearIfNecessary()
123     {
124       if(lastlineoffset!=lineoffset ||force_lcd_update)
125       {
126         force_lcd_update=true;
127          lcd.clear();
128       } 
129     }
130   };
131
132   //conversion routines, could need some overworking
133   char *ftostr51(const float &x);
134   char *ftostr52(const float &x);
135   char *ftostr31(const float &x);
136   char *ftostr3(const float &x);
137
138
139   #define LCD_INIT lcd_init();
140   #define LCD_MESSAGE(x) lcd_status(x);
141   #define LCD_MESSAGEPGM(x) lcd_statuspgm(MYPGM(x));
142   #define LCD_STATUS lcd_status()
143 #else //no lcd
144   #define LCD_INIT
145   #define LCD_STATUS
146   #define LCD_MESSAGE(x)
147   #define LCD_MESSAGEPGM(x)
148   FORCE_INLINE void lcd_status() {};
149
150   #define CLICKED false
151   #define BLOCK ;
152 #endif 
153   
154 void lcd_statuspgm(const char* message);
155   
156 char *ftostr3(const float &x);
157 char *itostr2(const uint8_t &x);
158 char *ftostr31(const float &x);
159 char *ftostr32(const float &x);
160 char *itostr31(const int &xx);
161 char *itostr3(const int &xx);
162 char *itostr4(const int &xx);
163 char *ftostr51(const float &x);
164 #endif //ULTRALCD