ultralcd.h

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 0
2c8ba1964db7
permissions
-rw-r--r--

proper configuration, homing and planner optimization

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

mercurial