forked from KrisKasprzak/ILI9341_t3_controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathILI9341_t3_Controls.h
466 lines (346 loc) · 13 KB
/
ILI9341_t3_Controls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/*
The MIT License (MIT)
library writen by Kris Kasprzak
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
On a personal note, if you develop an application or product using this library
and make millions of dollars, I'm happy for you!
rev date author change
1.0 9/2019 kasprzak initial code
2.0 9/2020 kasprzak added shapes and sizes for handles
*/
#ifndef ILI9341_T3_CONTROLS_H
#define ILI9341_T3_CONTROLS_H
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
#ifdef __cplusplus
#include "Arduino.h"
#endif
#include <ILI9341_t3.h>
#define G_REPAINT 0
#define G_DRAWOVER 1
#define BELOW 0
#define ABOVE 1
#define HANDLE_NONE 0
#define HANDLE_CIRCLE 1
#define HANDLE_SQUARE 2
#define HANDLE_TRIANGLE_1 3
#define HANDLE_TRIANGLE_2 4
#define HANDLE_TRIANGLE_3 5
#define C_BLACK 0x0000
#define C_BLUE 0x001F
#define C_RED 0xF800
#define C_GREEN 0x07E0
#define C_CYAN 0x07FF
#define C_MAGENTA 0xF81F
#define C_YELLOW 0xFFE0
#define C_WHITE 0xFFFF
#define C_LTBLUE 0xB6DF
#define C_LTTEAL 0xBF5F
#define C_LTGREEN 0xBFF7
#define C_LTCYAN 0xC7FF
#define C_LTRED 0xFD34
#define C_LTMAGENTA 0xFD5F
#define C_LTYELLOW 0xFFF8
#define C_LTORANGE 0xFE73
#define C_LTPINK 0xFDDF
#define C_LTPURPLE 0xCCFF
#define C_LTGREY 0xE71C
#define C_TEAL 0x0438
#define C_ORANGE 0xFD20
#define C_PINK 0xF81F
#define C_PURPLE 0x801F
#define C_GREY 0xC618
#define C_DKBLUE 0x000D
#define C_DKTEAL 0x020C
#define C_DKGREEN 0x03E0
#define C_DKCYAN 0x03EF
#define C_DKRED 0x6000
#define C_DKMAGENTA 0x8008
#define C_DKYELLOW 0x8400
#define C_DKORANGE 0x8200
#define C_DKPINK 0x9009
#define C_DKPURPLE 0x4010
#define C_DKGREY 0x4A49
#define C_MDGREY 0x7BCF
class BarChartH {
public:
BarChartH(ILI9341_t3 *disp, float GraphXLoc, float GraphYLoc, float GraphWidth, float GraphHeight, float ScaleLow, float ScaleHigh, float ScaleInc);
void init(const char *Title, uint16_t TextColor, uint16_t BarColor, uint16_t BarBColor, uint16_t BackColor,const ILI9341_t3_font_t &TitleFont , const ILI9341_t3_font_t &ScaleFont );
void setBarColor(uint16_t val = 0xF800);
void plot(float val);
void setScale(float ScaleLow, float ScaleHigh, float ScaleInc);
void showTitle(bool val);
void showScale(bool val);
private:
ILI9341_t3 *d;
ILI9341_t3_font_t tf;
ILI9341_t3_font_t sf;
bool st = true, ss = true;
char ti[20];
char sc[20];
char cc[2] = "D";
char text[30];
float XLow;
float XHigh;
float XInc;
int Dec, tLen, tHi;
float Low;
float High;
float Inc;
float gx;
float gy;
float gw;
float gh;
uint16_t tc;
uint16_t rc;
uint16_t bc;
uint16_t ac;
bool redraw;
float stepval, range, TempY, level, i, data;
float MapFloat(float x, float in_min, float in_max, float out_min, float out_max);
};
class BarChartV {
public:
BarChartV(ILI9341_t3 *disp, float GraphXLoc, float GraphYLoc, float GraphWidth, float GraphHeight, float ScaleLow, float ScaleHigh, float ScaleInc);
void init(const char *Title, uint16_t TextColor, uint16_t BarColor, uint16_t BarBColor, uint16_t BackColor,const ILI9341_t3_font_t &TitleFont , const ILI9341_t3_font_t &ScaleFont );
void setBarColor(uint16_t val = 0xF800);
void plot(float val);
void setScale(float ScaleLow, float ScaleHigh, float ScaleInc);
void showTitle(bool val);
void showScale(bool val);
private:
ILI9341_t3 *d;
ILI9341_t3_font_t tf;
ILI9341_t3_font_t sf;
bool st = true, ss = true;
char ti[20];
char sc[20];
char cc[2] = "D";
char text[30];
float XLow;
float XHigh;
float XInc;
int Dec, tLen, tHi;
float Low;
float High;
float Inc;
float gx;
float gy;
float gw;
float gh;
uint16_t tc;
uint16_t rc;
uint16_t bc;
uint16_t ac;
bool redraw;
float stepval, range, TempY, level, i, data;
float MapFloat(float x, float in_min, float in_max, float out_min, float out_max);
};
class CGraph {
public:
CGraph(ILI9341_t3 *disp, float GraphXLoc, float GraphYLoc, float GraphWidth, float GraphHeight, float XAxisLow, float XAxisHigh, float XAxisInc, float YAxisLow, float YAxisHigh, float YAxisInc);
void init(const char *Title, const char *XAxis, const char *YAxis, uint16_t TextColor, uint16_t GridColor, uint16_t AxisColor, uint16_t BackColor,uint16_t PlotkColor, const ILI9341_t3_font_t &TitleFont , const ILI9341_t3_font_t &AxisFont );
void plot(int ID, float y);
void setX(float x);
int add(const char * DataLabel, uint16_t DataColor );
void setYAxis(float Ylow, float YHigh, float YInc);
void showTitle(bool val);
void showLegend(bool val);
void showXScale(bool val);
void showYScale(bool val);
private:
ILI9341_t3 *d;
ILI9341_t3_font_t tf;
ILI9341_t3_font_t af;
int ID = 0;
float x, y;
float i, j;
bool st, sl, sxs, sys;
float Delta;
int k;
float XLow, XHigh, XInc;
float YLow, YHigh, YInc;
bool RedrawGraph = true;
bool HaveFirstPoint = false;
float XPoint, YPoint, oXPoint, oYPoint[10], TextHeight;
float XDec = 0.0, YDec = 0.0;
char text[30];
byte oOrientation = 0;
float gx, gy, gw, gh;
int StartPointX, StartPointY;
char buf0[20], buf1[20], buf2[20], buf3[20], buf4[20], buf5[20], buf6[20], buf7[20], buf8[20], buf9[20];
char *dl[20] = {buf0, buf1, buf2, buf3, buf4, buf5, buf6, buf6, buf8, buf9};
char t[20];
char xa[20];
char ya[20];
uint16_t tc;
uint16_t dc[10];
uint16_t ac;
uint16_t gc;
uint16_t bc;
uint16_t pc;
void drawGraph();
float MapFloat(float x, float in_min, float in_max, float out_min, float out_max);
};
class Dial {
public:
Dial(ILI9341_t3 *disp, int CenterX, int CenterY, int DialRadius, float LowVal , float HiVal , float ValInc, float SweepAngle);
void init(uint16_t NeedleColor, uint16_t DialColor, uint16_t TextColor, uint16_t TickColor, const char *Title, const ILI9341_t3_font_t &TitleFont , const ILI9341_t3_font_t &DataFont );
void draw(float val);
private:
bool Redraw = true;
ILI9341_t3 *d;
ILI9341_t3_font_t tf;
ILI9341_t3_font_t df;
char t[10];
int cx;
int cy;
int dr;
float lv;
float hv;
float inc;
float sa;
uint16_t nc;
uint16_t dc;
uint16_t tc;
uint16_t ic;
float degtorad;
float offset, stepval, angle, data;
float i;
//variables to track new needle values
float ix;
float iy;
float ox;
float oy;
float tx;
float ty;
float dx;
float dy;
float lx;
float rx;
float ly;
float ry;
int tLen, tHi;
char buf[38];
int dec;
// variables to track previous needle values
float px;
float py;
float pix;
float piy;
float plx;
float ply;
float prx;
float pry;
};
class SliderH {
public:
SliderH(ILI9341_t3 *disp, uint16_t left, uint16_t top, uint16_t wide, uint16_t sliderColor, uint16_t backColor, uint16_t handleColor); // class constructor
void init(float scaleLow, float scaleHi, float scale = 0.0, float snap = 0.0); // initializer
void draw(float val); // method to draw complete slider
float slide(float x, float y); // method to move handle as user drags finger over handle, this method automatically looks for a valid range press
bool changed();
void change();
void setColors(uint16_t sliderColor, uint16_t backColor, uint16_t handleColor); // way to reset colors (useful for drawing enabled or disabled)
void setHandleColor(uint16_t handleColor); // method to just draw the handle (useful for showing handle in green for OK value
void setHandleSize(int val);
void setHandleShape(byte val);
void drawSliderColor(bool val);
private:
ILI9341_t3 *d; // the display object
uint16_t sColor; // the slider color
uint16_t bColor; // the slider background color
uint16_t hColor; // the sliders drag handle
uint16_t l; // the left coordinate of the scale
uint16_t t; // the top coordinate of the scale
uint16_t w; // the width of the scale
float ox; // the old screen x value where user pressed
float sl; // the scale lower value
float sh; // the scale upper value
float pos; // the position on the scale
float sn; // the snap increment
float sc; // the scale increment
float ce; // the tick mark where zero is (for drawing heavy line on +/- scales
float i; // loop counter
int handlesize;
byte handleshape;
bool ch; // flag if control was changed by user
bool colorscale; // flag to draw slider in handle color
float MapFloat(float x, float fromLow, float fromHigh, float toLow, float toHigh); // why Arduino has no mapping for floats is beyond me, here it is...
};
class SliderV {
public:
SliderV(ILI9341_t3 *disp, uint16_t left, uint16_t top, uint16_t high, uint16_t sliderColor, uint16_t backColor, uint16_t handleColor); // class constructor
void init(float scaleLow, float scaleHi, float scale = 0.0, float snap= 0.0); // initializer
void draw(float val); // method to draw complete slider
float slide(uint16_t x, uint16_t y); // method to move handle as user drags finger over handle, this method automatically looks for a valid range press
bool changed();
void change();
void setColors(uint16_t sliderColor, uint16_t backColor, uint16_t handleColor); // way to reset colors (useful for drawing enabled or disabled)
void setHandleColor(uint16_t handleColor); // method to just draw the handle (useful for showing handle in green for OK value
void setHandleSize(int val);
void setHandleShape(byte val);
void drawSliderColor(bool val);
private:
ILI9341_t3 *d; // the display object
uint16_t sColor; // the slider color
uint16_t bColor; // the slider background color
uint16_t hColor; // the sliders drag handle
uint16_t l; // the left coordinate of the scale
uint16_t t; // the top coordinate of the scale
uint16_t w; // the with of the scale
uint16_t h; // the with of the scale
uint16_t oy; // the old screen y value where user pressed
float sl; // the scale lower value
float sh; // the scale upper value
float pos; // the screen coordinate position
float sn; // the snap increment
float sc; // the scale increment
float ce; // the tick mark where zero is (for drawing heavy line on +/- scales
float i; // loop counter
byte tl;
bool ch; // flag if control was changed by user
bool colorscale; // flag to draw slider in handle color
float MapFloat(float x, float fromLow, float fromHigh, float toLow, float toHigh);// why Arduino has no mapping for floats is beyond me, here it is...
int tLen, tHi;
int handlesize;
byte handleshape;
};
class SliderOnOff {
public:
SliderOnOff(ILI9341_t3 *disp, uint16_t left, uint16_t top, uint16_t width, uint16_t height, uint16_t sliderColor, uint16_t backColor, uint16_t OnColor, uint16_t OffColor);// class constructor
void draw(bool val); // method to draw complete slider
bool slide(float x,float y); // method to move handle as user drags finger over handle, this method automatically looks for a valid range press
bool changed(); // method to return if state change, useful for determining if a something should be done but not done unless state change
bool getValue();
private:
ILI9341_t3 *_d; // the display object
uint16_t _sColor; // the slider color
uint16_t _bColor; // the slider background color
uint16_t _onColor; // the sliders on color
uint16_t _offColor; // the sliders on color
uint16_t _l; // the left coordinate of the scale
uint16_t _t; // the top coordinate of the scale
uint16_t _w; // the with of the scale
uint16_t _h; // the with of the scale
bool _pos; // the screen coordinate position
bool _changed; //flag to track if button was just changed
};
#endif