Sun, 19 Apr 2020 23:28:26 +0200
Version 0.3.9. Added no-boil handling. Fixed cooling temp during cooling to allow 45 degrees setpoint.
0 | 1 | /** |
2 | * @file tft.h | |
3 | * @brief High level TFT functions | |
4 | * @author LoBo 04/2017 | |
5 | * @see https://github.com/loboris | |
20
3fd5e0fc075f
Version 0.2.6. Removed dead code in the tft component.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
6 | * @author M. Broek - removed unused code for this app. |
0 | 7 | */ |
8 | ||
9 | #ifndef _TFT_H_ | |
10 | #define _TFT_H_ | |
11 | ||
12 | #include <stdlib.h> | |
13 | #include "tftspi.h" | |
14 | ||
29 | 15 | /** |
16 | * @brief Window coordinates | |
17 | */ | |
0 | 18 | typedef struct { |
19 | uint16_t x1; | |
20 | uint16_t y1; | |
21 | uint16_t x2; | |
22 | uint16_t y2; | |
23 | } dispWin_t; | |
24 | ||
29 | 25 | /** |
26 | * @brief Font description. | |
27 | */ | |
0 | 28 | typedef struct { |
29 | uint8_t *font; | |
30 | uint8_t x_size; | |
31 | uint8_t y_size; | |
32 | uint8_t offset; | |
33 | uint16_t numchars; | |
34 | uint16_t size; | |
35 | uint8_t max_x_size; | |
36 | uint8_t bitmap; | |
37 | color_t color; | |
38 | } Font; | |
39 | ||
40 | ||
41 | //========================================================================================== | |
42 | // ==== Global variables =================================================================== | |
43 | //========================================================================================== | |
44 | extern uint8_t orientation; ///< current screen orientation | |
45 | extern uint16_t font_rotate; ///< current font font_rotate angle (0~395) | |
46 | extern uint8_t font_transparent; ///< if not 0 draw fonts transparent | |
47 | extern uint8_t font_forceFixed; ///< if not zero force drawing proportional fonts with fixed width | |
48 | extern uint8_t font_buffered_char; | |
49 | extern uint8_t font_line_space; ///< additional spacing between text lines; added to font height | |
50 | extern uint8_t text_wrap; ///< if not 0 wrap long text to the new line, else clip | |
51 | extern color_t _fg; ///< current foreground color for fonts | |
52 | extern color_t _bg; ///< current background for non transparent fonts | |
53 | extern dispWin_t dispWin; ///< display clip window | |
54 | extern float _angleOffset; ///< angle offset for arc, polygon and line by angle functions | |
55 | extern uint8_t image_debug; ///< print debug messages during image decode if set to 1 | |
56 | ||
57 | extern Font cfont; ///< Current font structure | |
58 | ||
59 | extern int TFT_X; ///< X position of the next character after TFT_print() function | |
60 | extern int TFT_Y; ///< Y position of the next character after TFT_print() function | |
61 | ||
62 | // ========================================================================================= | |
63 | ||
64 | ||
29 | 65 | /** |
66 | * @brief rotational offset in degrees defining position of value 0 (-90 will put it at the top of circle) | |
67 | * this can be changed with setAngleOffset function at runtime | |
68 | */ | |
0 | 69 | #define DEFAULT_ANGLE_OFFSET -90 |
70 | ||
71 | #define PI 3.14159265359 | |
72 | ||
73 | ||
74 | // === Color names constants === | |
75 | extern const color_t TFT_BLACK; | |
76 | extern const color_t TFT_NAVY; | |
77 | extern const color_t TFT_DARKGREEN; | |
78 | extern const color_t TFT_DARKCYAN; | |
79 | extern const color_t TFT_MAROON; | |
80 | extern const color_t TFT_PURPLE; | |
81 | extern const color_t TFT_OLIVE; | |
82 | extern const color_t TFT_LIGHTGREY; | |
83 | extern const color_t TFT_DARKGREY; | |
84 | extern const color_t TFT_BLUE; | |
85 | extern const color_t TFT_GREEN; | |
86 | extern const color_t TFT_CYAN; | |
87 | extern const color_t TFT_RED; | |
88 | extern const color_t TFT_MAGENTA; | |
89 | extern const color_t TFT_YELLOW; | |
90 | extern const color_t TFT_WHITE; | |
91 | extern const color_t TFT_ORANGE; | |
92 | extern const color_t TFT_GREENYELLOW; | |
93 | extern const color_t TFT_PINK; | |
94 | ||
95 | ||
96 | // === Special coordinates constants === | |
29 | 97 | #define CENTER -9003 ///< Center X or Y |
98 | #define RIGHT -9004 ///< Right X | |
99 | #define BOTTOM -9004 ///< Bottom Y | |
0 | 100 | |
29 | 101 | #define LASTX 7000 ///< At last X position |
102 | #define LASTY 8000 ///< At last Y position | |
0 | 103 | |
104 | // === Embedded fonts constants === | |
105 | #define DEFAULT_FONT 0 ///< 12 points 95 characters DejaVu font. | |
106 | #define DEJAVU18_FONT 1 ///< 18 points 95 characters DejaVuSans font. | |
107 | #define DEJAVU24_FONT 2 ///< 24 points 95 characters DejaVu font. | |
108 | #define UBUNTU16_FONT 3 ///< 16 points 95 characters Ubuntu font. | |
109 | #define COMIC24_FONT 4 ///< 24 points 95 characters Comic font. | |
110 | #define MINYA24_FONT 5 ///< 24 points 95 characters Minya font. | |
111 | #define TOONEY32_FONT 6 ///< 32 points 95 characters Tooney font. | |
112 | #define SMALL_FONT 7 ///< 8x12 pixels 95 characters fixed font. | |
113 | #define DEF_SMALL_FONT 8 ///< 9 points 95 characters font. | |
114 | #define FONT_7SEG 9 ///< Variable size 14 characters 7 segment font. | |
115 | #define USER_FONT 10 ///< font will be read from file | |
116 | ||
117 | ||
118 | ||
119 | // ===== PUBLIC FUNCTIONS ========================================================================= | |
120 | ||
121 | ||
122 | /** | |
123 | * @brief Draw pixel at given x,y coordinates | |
124 | * @param x horizontal position | |
125 | * @param y vertical position | |
126 | * @param color pixel color | |
127 | * @param sel if not 0 activate CS before and deactivat after sending pixel data to display | |
128 | * when sending multiple pixels it is faster to activate the CS first, | |
129 | * send all pixels an deactivate CS after all pixela was sent | |
130 | */ | |
131 | void TFT_drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel); | |
132 | ||
133 | /** | |
134 | * @brief Read pixel color value from display GRAM at given x,y coordinates | |
135 | * @param[in] x horizontal position | |
136 | * @param[in] y vertical position | |
137 | */ | |
138 | color_t TFT_readPixel(int16_t x, int16_t y); | |
139 | ||
140 | /** | |
141 | * @brief Draw vertical line at given x,y coordinates | |
142 | * | |
143 | * @param x horizontal start position | |
144 | * @param y vertical start position | |
145 | * @param h line height in pixels | |
146 | * @param color line color | |
147 | */ | |
148 | void TFT_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color); | |
149 | ||
150 | /** | |
151 | * @brief Draw horizontal line at given x,y coordinates | |
152 | * | |
153 | * @param x horizontal start position | |
154 | * @param y vertical start position | |
155 | * @param w line width in pixels | |
156 | * @param color line color | |
157 | */ | |
158 | void TFT_drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color); | |
159 | ||
160 | /** | |
161 | * @brief Draw line on screen | |
162 | * | |
163 | * @param x0 horizontal start position | |
164 | * @param y0 vertical start position | |
165 | * @param x1 horizontal end position | |
166 | * @param y1 vertical end position | |
167 | * @param color line color | |
168 | */ | |
169 | void TFT_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color); | |
170 | ||
171 | /** | |
172 | * @brief Fill given rectangular screen region with color | |
173 | * | |
174 | * @param x horizontal rect start position | |
175 | * @param y vertical rect start position | |
176 | * @param w rectangle width | |
177 | * @param h rectangle height | |
178 | * @param color fill color | |
179 | */ | |
180 | void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color); | |
181 | ||
182 | /** | |
183 | * @brief Draw rectangle on screen | |
184 | * | |
185 | * @param x horizontal rect start position | |
186 | * @param y vertical rect start position | |
187 | * @param w rectangle width | |
188 | * @param h rectangle height | |
189 | * @param color rect line color | |
190 | */ | |
191 | void TFT_drawRect(uint16_t x1,uint16_t y1,uint16_t w,uint16_t h, color_t color); | |
192 | ||
193 | /** | |
194 | * @brief Draw rectangle with rounded corners on screen | |
195 | * | |
196 | * @param x horizontal rect start position | |
197 | * @param y vertical rect start position | |
198 | * @param w rectangle width | |
199 | * @param h rectangle height | |
200 | * @param r corner radius | |
201 | * @param color rectangle color | |
202 | */ | |
203 | void TFT_drawRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color); | |
204 | ||
205 | /** | |
206 | * @brief Fill given rectangular screen region with rounded corners with color | |
207 | * | |
208 | * @param x horizontal rect start position | |
209 | * @param y vertical rect start position | |
210 | * @param w rectangle width | |
211 | * @param h rectangle height | |
212 | * @param r corner radius | |
213 | * @param color fill color | |
214 | */ | |
215 | void TFT_fillRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color); | |
216 | ||
217 | /** | |
218 | * @brief Fill the whole screen with color | |
219 | * | |
220 | * @param color fill color | |
221 | */ | |
222 | void TFT_fillScreen(color_t color); | |
223 | ||
224 | /** | |
225 | * @brief Fill the current clip window with color | |
226 | * | |
227 | * @param color fill color | |
228 | */ | |
229 | void TFT_fillWindow(color_t color); | |
230 | ||
231 | /** | |
232 | * @brief Draw circle on screen | |
233 | * | |
234 | * @param x circle center x position | |
235 | * @param y circle center x position | |
236 | * @param r circle radius | |
237 | * @param color circle color | |
238 | */ | |
239 | void TFT_drawCircle(int16_t x, int16_t y, int radius, color_t color); | |
240 | ||
241 | /** | |
242 | * @brief Fill circle on screen with color | |
243 | * | |
244 | * @param x circle center x position | |
245 | * @param y circle center x position | |
246 | * @param r circle radius | |
247 | * @param color circle fill color | |
248 | */ | |
249 | void TFT_fillCircle(int16_t x, int16_t y, int radius, color_t color); | |
250 | ||
251 | /** | |
252 | * @brief Set the font used for writing the text to display. | |
253 | * | |
254 | * ------------------------------------------------------------------------------------ | |
255 | * For 7 segment font only characters 0,1,2,3,4,5,6,7,8,9, . , - , : , / are available. | |
256 | * Character ‘/‘ draws the degree sign. | |
257 | * ------------------------------------------------------------------------------------ | |
258 | * | |
259 | * @param font font number; use defined font names | |
260 | * @param font_file pointer to font file name; NULL for embeded fonts | |
261 | */ | |
262 | void TFT_setFont(uint8_t font, const char *font_file); | |
263 | ||
264 | /** | |
265 | * @brief Returns current font height & width in pixels. | |
266 | * | |
267 | * @param[in] width pointer to returned font width | |
268 | * @param[in] height pointer to returned font height | |
269 | */ | |
270 | int TFT_getfontsize(int *width, int* height); | |
271 | ||
272 | /** | |
273 | * @brief Returns current font height in pixels. | |
274 | * @return The font height in pixels. | |
275 | */ | |
276 | int TFT_getfontheight(); | |
277 | ||
278 | /** | |
279 | * @brief Write text to display. | |
280 | * | |
281 | * Rotation of the displayed text depends on 'font_rotate' variable (0~360) | |
282 | * if 'font_transparent' variable is set to 1, no background pixels will be printed | |
283 | * | |
284 | * If the text does not fit the screen width it will be clipped (if text_wrap=0), | |
285 | * or continued on next line (if text_wrap=1) | |
286 | * | |
287 | * Two special characters are allowed in strings: | |
288 | * | |
289 | * ‘\r’ CR (0x0D), clears the display to EOL | |
290 | * ‘\n’ LF (ox0A), continues to the new line, x=0 | |
291 | * | |
292 | * @param st pointer to null terminated string to be printed | |
293 | * @param x horizontal position of the upper left point in pixels. Special values can be entered: | |
294 | * | |
295 | * CENTER, centers the text | |
296 | * RIGHT, right justifies the text | |
297 | * LASTX, continues from last X position; offset can be used: LASTX+n | |
298 | * | |
299 | * @param y vertical position of the upper left point in pixels. Special values can be entered: | |
300 | * | |
301 | * CENTER, centers the text | |
302 | * BOTTOM, bottom justifies the text | |
303 | * LASTY, continues from last Y position; offset can be used: LASTY+n | |
304 | * | |
305 | */ | |
306 | void TFT_print(char *st, int x, int y); | |
307 | ||
308 | /** | |
309 | * @brief Set atributes for 7 segment vector font | |
310 | * @note 7 segment font must be the current font to this function to have effect | |
311 | * | |
312 | * @param l 6~40; distance between bars in pixels | |
313 | * @param w 1~12, max l/2; bar width in pixels | |
314 | * @param outline draw font outline if set to 1 | |
315 | * @param color font outline color, only used if outline=1 | |
316 | */ | |
317 | void set_7seg_font_atrib(uint8_t l, uint8_t w, int outline, color_t color); | |
318 | ||
319 | /** | |
320 | * @brief Sets the clipping area coordinates. | |
321 | * All writing to screen is clipped to that area. | |
322 | * Starting x & y in all functions will be adjusted to the clipping area. | |
323 | * | |
324 | * @param x1,y1 upper left point of the clipping area | |
325 | * @param x2,y2 bottom right point of the clipping area | |
326 | */ | |
327 | void TFT_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); | |
328 | ||
329 | /** | |
330 | * @brief Resets the clipping area to full screen (0,0),(_wodth,_height) | |
331 | */ | |
332 | void TFT_resetclipwin(); | |
333 | ||
334 | /** | |
335 | * @brief Save current clipping area to temporary variable | |
336 | */ | |
337 | void TFT_saveClipWin(); | |
338 | ||
339 | /** | |
340 | * @brief Restore current clipping area from temporary variable | |
341 | */ | |
342 | void TFT_restoreClipWin(); | |
343 | ||
344 | /** | |
345 | * @brief Set the screen rotation | |
346 | * Also resets the clip window and clears the screen with current background color | |
347 | * | |
348 | * @param rot 0~3; screen rotation; use defined rotation constants: | |
349 | * PORTRAIT, LANDSCAPE, PORTRAIT_FLIP, LANDSCAPE_FLIP | |
350 | */ | |
351 | void TFT_setRotation(uint8_t rot); | |
352 | ||
353 | /** | |
354 | * @brief Select gamma curve | |
355 | * @param gm gama curve, values 0~3 | |
356 | */ | |
357 | void TFT_setGammaCurve(uint8_t gm); | |
358 | ||
359 | /** | |
360 | * @brief returns the string width in pixels. Useful for positions strings on the screen. | |
361 | * @return The string width. | |
362 | */ | |
363 | int TFT_getStringWidth(char* str); | |
364 | ||
365 | ||
366 | /** | |
367 | * @brief Fills the rectangle occupied by string with current background color | |
368 | * @param x X position | |
369 | * @param Y Y position | |
370 | * @param str The string | |
371 | */ | |
372 | void TFT_clearStringRect(int x, int y, char *str); | |
373 | ||
374 | /** | |
375 | * @brief Get the touch panel coordinates. | |
376 | * The coordinates are adjusted to screen orientation if raw=0 | |
377 | * | |
378 | * @param[in] x pointer to X coordinate | |
379 | * @param[in] y pointer to Y coordinate | |
380 | * @param raw if 0 returns calibrated screen coordinates; if 1 returns raw touch controller coordinates | |
381 | * @return 0 if touch panel is not touched; x=y=0 | |
382 | * 1 if touch panel is touched; x&y are the valid coordinates | |
383 | */ | |
384 | int TFT_read_touch(int *x, int* y, uint8_t raw); | |
385 | ||
386 | #endif |