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