-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchMenu.cpp
2123 lines (1844 loc) · 77.6 KB
/
TouchMenu.cpp
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "TouchMenu.h"
#include "UTFT.h"
#include <SPI.h>
#include "Arduino.h"
#include "EEprom.h"
#include <TimeLib.h>
// ***********************************************
// Variables
// ***********************************************
uint8_t TotalButtons;
uint16_t Touchx;
uint16_t Touchy;
uint16_t ButtonPressed;
uint8_t SubMenuLoopFlag;
uint8_t MenuLoopFlag;
void(*function)(void); // stores the function name to be called from the arrays
uint8_t setweekday;
uint8_t setday;
uint8_t setmonth;
uint16_t setyear;
uint8_t sethour;
uint8_t setminute;
uint8_t setsecond;
// ***********************************************
// Defines
// ***********************************************
#define MAX_MENU_NAME_LENGTH 13
#define MAIN_MENU_SIZE 7
#define USER_SETUP_SIZE 5
#define TIMER_SETUP_SIZE 9
#define SENSOR_SETUP_SIZE 5
#define SENSOR_CALIB_SIZE 5
#define SETUP_FLOW_SIZE 4
#define SYSTEM_SETUP_SIZE 4
#define TFT_B_LIGHT_PIN 9
#define DS1307RTC 0x68 // Set the address of the DS1307 RTC
// ***********************************************
// Function prototypes
// ***********************************************
void MainMenu();
void UserSetup();
void Brightness();
void TimeFormat();
void SecondsDisplay();
void SetDateTime();
void TimerSetup();
void SetTimer();
void SensorSetup();
void TempUnit();
void TempPrecision();
void TempReadDelay();
void SensorNames();
void SensorCalib();
void SensorAddrConfig();
void SetupFlowSensor();
void FlowOnOff();
void CalibrateFlowSensor();
void SetMinFlow();
void SystemSetup();
void SerialDebugging();
void EraseEEPROM();
void RestoreDefaults();
uint8_t AdjustTime();
uint8_t AdjustDate();
uint8_t AdjustTimer(uint8_t id, uint8_t state);
void AlarmON();
void AlarmOFF();
void ExitMenu();
void BackMenu();
void DrawMenuButtonArray(uint8_t buttons, struct MENU_ITEM *currentmenu);
void MenuLoop(uint8_t menuSize, uint16_t delayms);
void ReadTouchData();
void AnalyzeMenuTouchData(int menuSize);
void ClearScreenHeader();
uint8_t DecToBcd(uint8_t val);
uint8_t BcdToDec(uint8_t val);
void Dummy();
void REPLACEME();
// ***********************************************
// Menu Array Definitions
// ***********************************************
typedef struct MENU_ITEM {
char Menu_Name[20];
byte Menu_Size;
void(*function)(void);
};
// ***********************************************
// Button Location Array Definitions
// ***********************************************
struct TOUCH_LOC {
int Button_Number;
int X_Start;
int Y_Start;
int X_End;
int Y_End;
};
// ***********************************************
// Menu Arrays
// ***********************************************
// Main Menu Array
MENU_ITEM Main_Menu[] = {
{ "User Setup", 7, UserSetup },
{ "Timers Setup", 8, TimerSetup },
{ "Sensor Setup", 5, SensorSetup },
{ "Sensor Calib", 8, SensorCalib },
{ "Setup Flow", 4, SetupFlowSensor },
{ "System Setup", 3, SystemSetup },
{ "Exit", 0, BackMenu }
};
// User Setup Arrays
MENU_ITEM User_Setup[] = {
{ "Brightness", 4, Brightness },
{ "Time Format", 3, TimeFormat },
{ "Display Sec", 3, SecondsDisplay },
{ "Set Date/Time", 13, SetDateTime },
{ "Back", 0, BackMenu }
};
MENU_ITEM Backlight_Brightness[] = {
{ "High", 0, REPLACEME },
{ "Medium", 0, REPLACEME },
{ "Low", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
MENU_ITEM Time_Format[] = {
{ "24 Hour", 0, REPLACEME },
{ "12 Hour", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
// Timer Setup Arrays
MENU_ITEM Timer_Setup[] = {
{ "Set Timer 1", 2, SetTimer },
{ "Set Timer 2", 2, SetTimer },
{ "Set Timer 3", 2, SetTimer },
{ "Set Timer 4", 2, SetTimer },
{ "Set Timer 5", 2, SetTimer },
{ "Set Timer 6", 2, SetTimer },
{ "Set Timer 7", 2, SetTimer },
{ "Set Timer 8", 2, SetTimer },
{ "Back", 0, BackMenu }
};
// Sensor Setup Arrays
MENU_ITEM Sensor_Setup[] = {
{ "Temp Unit", 3, TempUnit },
{ "Precision", 3, TempPrecision },
{ "Read Delay", 4, TempReadDelay },
{ "Sensor Names", 5, REPLACEME },
{ "Back", 0, BackMenu }
};
MENU_ITEM Temp_Unit[] = {
{ "Celcius", 0, REPLACEME },
{ "Fahrenheit", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
MENU_ITEM Temp_Precision[] = {
{ "No Decimal", 0, REPLACEME },
{ "1 Decimal", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
MENU_ITEM Read_Delay[] = {
{ "10 Seconds", 0, REPLACEME },
{ "20 Seconds", 0, REPLACEME },
{ "30 Seconds", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
MENU_ITEM Sensor_Names[] = {
{ "!Implemented", 0, REPLACEME },
{ "!Implemented", 0, REPLACEME },
{ "!Implemented", 0, REPLACEME },
{ "!Implemented", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
// Sensor Calibration Arrays
MENU_ITEM Sensor_Calib[] = {
{ "Calib Temp 1", 2, REPLACEME },
{ "Calib Temp 2", 2, REPLACEME },
{ "Calib Temp 3", 2, REPLACEME },
{ "Calib Temp 4", 2, REPLACEME },
{ "Back", 2, BackMenu }
};
// Setup Flow Sensor Arrays
MENU_ITEM Setup_Flow[] = {
{ "On/Off", 3, FlowOnOff},
{ "Calib Flow", 2, CalibrateFlowSensor},
{ "Set Min Flow", 4, SetMinFlow},
{ "Back", 2, BackMenu }
};
MENU_ITEM Min_Flow[] = {
{ "85%", 0, REPLACEME },
{ "75%", 0, REPLACEME },
{ "65%", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
// System Setup
MENU_ITEM System_Setup[] = {
{ "Debugging", 10, SerialDebugging },
{ "Erase EEPROM", 2, EraseEEPROM },
{ "Fact Defaults", 2, RestoreDefaults },
{ "Back", 2, BackMenu }
};
MENU_ITEM Serial_Debugging[] = {
{ "All On", 0, REPLACEME },
{ "All Off", 0, REPLACEME },
{ "Temp Sensors", 0, REPLACEME },
{ "Menu", 0, REPLACEME },
{ "Alarms", 0, REPLACEME },
{ "EEPROM", 0, REPLACEME },
{ "Relays", 0, REPLACEME },
{ "System", 0, REPLACEME },
{ "Flow Sensor", 0, REPLACEME },
{ "Back", 0, REPLACEME }
};
MENU_ITEM Yes_No[] = {
{ "Yes", 0, REPLACEME },
{ "No", 0, REPLACEME }
};
MENU_ITEM On_Off[] = {
{ "On", 0, REPLACEME },
{ "Off", 0, REPLACEME },
{ "Back", 0, REPLACEME}
};
MENU_ITEM Back_Next[] = {
{ "Back", 0, REPLACEME },
{ "Next", 0, REPLACEME }
};
MENU_ITEM CHANGE_ME[] = {
{ "DUMMY", 0, REPLACEME },
{ "DUMMY", 0, REPLACEME }
};
char* WEEKDAY[] = { "INV", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
// ***********************************************
// TouchArea Arrays
// ***********************************************
// 4 Button Main Menu Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 1-5
TOUCH_LOC Buttons_4[] = {
{1, 135, 68, 345, 108},
{2, 135, 116, 345, 156},
{3, 135, 164, 345, 204},
{4, 135, 212, 345, 252},
{5, 420, 212, 460, 252} // Back button if necessary
};
// 8 Button Main Menu Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 5-8
TOUCH_LOC Buttons_8[] = {
{1, 20, 68, 230, 108},
{2, 250, 68, 460, 108},
{3, 20, 116, 230, 156},
{4, 250, 116, 460, 156},
{5, 20, 164, 230, 204},
{6, 250, 164, 460, 204},
{7, 20, 212, 230, 252},
{8, 250, 212, 460, 252}
};
// 10 Button Main Menu Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 10
TOUCH_LOC Buttons_10[] = {
{1, 20, 68, 230, 101},
{2, 250, 68, 460, 101},
{3, 20, 108, 230, 141},
{4, 250, 108, 460, 141},
{5, 20, 148, 230, 181},
{6, 250, 148, 460, 181},
{7, 20, 188, 230, 221},
{8, 250, 188, 460, 221},
{9, 20, 228, 230, 261},
{10, 250, 228, 460, 261}
};
// 1 Button Bottom Located Main Menu Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 11
TOUCH_LOC Buttons_1[] = {
{1, 250, 218, 460, 258}
};
// 2 Buttons Bottom Located Main Menu Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 12
TOUCH_LOC Buttons_12[] = {
{1, 20, 218, 230, 258},
{2, 250, 218, 460, 258}
};
// 8 Button, 3 Up Arrows, 3 Down Arrows, and 2 Bottom Back and OK buttons Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 13
TOUCH_LOC Buttons_13[] = {
{1, 20, 218, 230, 258}, // Back
{2, 250, 218, 460, 258}, // OK
{3, 144, 70, 192, 104}, // 1st Up Arrow
{4, 216, 70, 264, 104}, // 2nd Up Arrow
{5, 288, 70, 336, 104}, // 3rd Up Arrow
{6, 144, 172, 192, 206}, // 1st Down Arrow
{7, 216, 172, 264, 206}, // 2nd Down Arrow
{8, 288, 172, 336, 206} // 3rd Down Arrow
};
// 10 Button, 4 Up Arrows, 4 Down Arrows, and 2 Bottom Back and OK buttons Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 14
TOUCH_LOC Buttons_14[] = {
{1, 20, 218, 230, 258}, // Back
{2, 250, 218, 460, 258}, // OK
{3, 108, 70, 156, 104}, // 1st Up Arrow
{4, 192, 70, 240, 104}, // 2nd Up Arrow
{5, 264, 70, 312, 104}, // 3rd Up Arrow
{6, 336, 70, 384, 104}, // 4th Up Arrow
{7, 108, 172, 156, 206}, // 1st Down Arrow
{8, 192, 172, 240, 206}, // 2nd Down Arrow
{9, 264, 172, 312, 206}, // 3rd Down Arrow
{10, 336, 172, 384, 206} // 4th Down Arrow
};
// 6 Button, 2 Up Arrows, 2 Down Arrows, and 2 Bottom Back and OK buttons Touch Areas
// button number, xstart, ystart, xend, yend
// menusize = 15
TOUCH_LOC Buttons_15[] = {
{1, 20, 218, 230, 258}, // Back
{2, 250, 218, 460, 258}, // OK
{3, 144, 70, 192, 104}, // 1st Up Arrow
{4, 216, 70, 264, 104}, // 2nd Up Arrow
{6, 144, 172, 192, 206}, // 1st Down Arrow
{7, 216, 172, 264, 206} // 2nd Down Arrow
};
TouchMenu::TouchMenu(){
// only here to initialize the class
}
void TouchMenu::EnterMenu()
// Entry point to the menu system and keep looping till the menu times out or is exited.
{
SubMenuLoopFlag = 1;
MainMenu(); // call the main menu function
today = 0; // set today to 0 so that the date function gets called
}
void MenuLoop(uint8_t menusize, uint16_t delayms) {
delay(delayms);
while (MenuLoopFlag == 1) // scans for a button press to do the appropriate action
{
menuTimeout++;
/* if (menuTimeout == 10000) { menuMode = 0; } */ // this will exit the menu system after approx 20 seconds after a button has not been pushed
if (Touch.dataAvailable()) {
ReadTouchData(); // read the data from the touchscreen
AnalyzeMenuTouchData(menusize); // analyzes the touch screen data to determine what was pushed
//Serial.printf("menuTimeout = %d\n\n", menuTimeout);
delay(delayms/2); // small debounce delay for a touch
// evaluate the button pressed for a valid area.
if (ButtonPressed == 255) { MenuLoopFlag = 1; } // invalid button, reloop
else { MenuLoopFlag = 0; } // valid button, exit loop
}
}
}
void DrawMenuButtonArray(uint8_t maxbuttons, struct MENU_ITEM *currentmenu) {
// This function will draw a button array depending on the number of buttons
// maxbuttons is the total number of buttons needed
// determine the number of buttons depending on the size of maxbuttons
if (maxbuttons <= 4) {
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing the button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_4[i].X_Start, Buttons_4[i].Y_Start, Buttons_4[i].X_End, Buttons_4[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_4[i].X_Start, Buttons_4[i].Y_Start, Buttons_4[i].X_End, Buttons_4[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings
TFT.print(menustring, Buttons_4[i].X_Start + 1 + 0, Buttons_4[i].Y_Start + 5);
}
}
else if ((maxbuttons > 4) && (maxbuttons <= 8)) {
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing then button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_8[i].X_Start, Buttons_8[i].Y_Start, Buttons_8[i].X_End, Buttons_8[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_8[i].X_Start, Buttons_8[i].Y_Start, Buttons_8[i].X_End, Buttons_8[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings
TFT.print(menustring, Buttons_8[i].X_Start + 1, Buttons_8[i].Y_Start + 5);
}
}
else if ((maxbuttons > 8) && (maxbuttons <= 10)) {
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing then button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_10[i].X_Start, Buttons_10[i].Y_Start, Buttons_10[i].X_End, Buttons_10[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_10[i].X_Start, Buttons_10[i].Y_Start, Buttons_10[i].X_End, Buttons_10[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
//TFT.setFont(Retro8x16);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings
TFT.print(menustring, Buttons_10[i].X_Start + 3, Buttons_10[i].Y_Start + 1);
}
}
else if (maxbuttons == 12) {
maxbuttons = 2; // the actual maxbuttons for this loop
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing the button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_12[i].X_Start, Buttons_12[i].Y_Start, Buttons_12[i].X_End, Buttons_12[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_12[i].X_Start, Buttons_12[i].Y_Start, Buttons_12[i].X_End, Buttons_12[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings
TFT.print(menustring, Buttons_12[i].X_Start + 1 + 0, Buttons_12[i].Y_Start + 5);
}
}
else if (maxbuttons == 13) {
maxbuttons = 8; // the actual maxbuttons for this loop
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing the button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_13[i].X_Start, Buttons_13[i].Y_Start, Buttons_13[i].X_End, Buttons_13[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_13[i].X_Start, Buttons_13[i].Y_Start, Buttons_13[i].X_End, Buttons_13[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings only if it is the last 2 buttons for the back and ok buttons
if ((i == 0) || (i == 1)) { TFT.print(menustring, Buttons_13[i].X_Start + 1 + 0, Buttons_13[i].Y_Start + 5); }
// draw the icons for the arrows
else if ((i >= 2) && (i <= 4)) { TFT.drawBitmap(Buttons_13[i].X_Start + 8, Buttons_13[i].Y_Start + 1, 32, 32, arrow_up); }
else if (i >= 5) { TFT.drawBitmap(Buttons_13[i].X_Start + 8, Buttons_13[i].Y_Start + 1, 32, 32, arrow_down); }
}
}
else if (maxbuttons == 14) {
maxbuttons = 10; // the actual maxbuttons for this loop
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing the button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_14[i].X_Start, Buttons_14[i].Y_Start, Buttons_14[i].X_End, Buttons_14[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_14[i].X_Start, Buttons_14[i].Y_Start, Buttons_14[i].X_End, Buttons_14[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings only if it is the last 2 buttons for the back and ok buttons
if ((i == 0) || (i == 1)) { TFT.print(menustring, Buttons_14[i].X_Start + 1 + 0, Buttons_14[i].Y_Start + 5); }
// draw the icons for the arrows
else if ((i >= 2) && (i <= 5)) { TFT.drawBitmap(Buttons_14[i].X_Start + 8, Buttons_14[i].Y_Start + 1, 32, 32, arrow_up); }
else if (i >= 6) { TFT.drawBitmap(Buttons_14[i].X_Start + 8, Buttons_14[i].Y_Start + 1, 32, 32, arrow_down); }
}
}
else if (maxbuttons == 15) {
maxbuttons = 6; // the actual maxbuttons for this loop
// loop through and start printing the buttons up to maxbuttons
for (byte i = 0; i < maxbuttons; i++) {
// variable for storing the button name
char* menustring = currentmenu[i].Menu_Name;
// draw the buttons
TFT.setColor(VGA_BLUE);
TFT.fillRoundRect(Buttons_15[i].X_Start, Buttons_15[i].Y_Start, Buttons_15[i].X_End, Buttons_15[i].Y_End);
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_15[i].X_Start, Buttons_15[i].Y_Start, Buttons_15[i].X_End, Buttons_15[i].Y_End);
// set up the font and colors for the strings
TFT.setFont(GroteskBold16x32);
TFT.setBackColor(VGA_BLUE);
TFT.setColor(VGA_WHITE);
// print the menu strings only if it is the first 2 buttons for the back and ok buttons
if ((i == 0) || (i == 1)) { TFT.print(menustring, Buttons_15[i].X_Start + 1 + 0, Buttons_15[i].Y_Start + 5); }
// draw the icons for the arrows
else if ((i >= 2) && (i <= 3)) { TFT.drawBitmap(Buttons_15[i].X_Start + 8, Buttons_15[i].Y_Start + 1, 32, 32, arrow_up); }
else if (i >= 4) { TFT.drawBitmap(Buttons_15[i].X_Start + 8, Buttons_15[i].Y_Start + 1, 32, 32, arrow_down); }
}
}
}
void ReadTouchData()
// Read the coordinates where the screen was touched
{
Touch.read(); // request the coordinates from the touch screen
Touchx = Touch.getX(); // get the x coordinate from the touch screen
Touchy = Touch.getY(); // get the y coordinate from the touch screen
//Serial.printf("Read Touch Data x=%d, y=%d\n", Touchx, Touchy);
//menuTimeout = 0;
}
void AnalyzeMenuTouchData(int menuSize)
// Analyze the touch screen data and determine which button to use
{
if (menuSize <= 4) {
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_4[i].X_Start) && (Touchx <= Buttons_4[i].X_End) && (Touchy >= Buttons_4[i].Y_Start) && (Touchy <= Buttons_4[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_4[i].X_Start, Buttons_4[i].Y_Start, Buttons_4[i].X_End, Buttons_4[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_4[i].X_Start, Buttons_4[i].Y_Start, Buttons_4[i].X_End, Buttons_4[i].Y_End);
// draw a white outline around the box that was pressed
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if ((menuSize > 4) && (menuSize <= 8)) {
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_8[i].X_Start) && (Touchx <= Buttons_8[i].X_End) && (Touchy >= Buttons_8[i].Y_Start) && (Touchy <= Buttons_8[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_8[i].X_Start, Buttons_8[i].Y_Start, Buttons_8[i].X_End, Buttons_8[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_8[i].X_Start, Buttons_8[i].Y_Start, Buttons_8[i].X_End, Buttons_8[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if ((menuSize > 8) && (menuSize <= 10)) {
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_10[i].X_Start) && (Touchx <= Buttons_10[i].X_End) && (Touchy >= Buttons_10[i].Y_Start) && (Touchy <= Buttons_10[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_10[i].X_Start, Buttons_10[i].Y_Start, Buttons_10[i].X_End, Buttons_10[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_10[i].X_Start, Buttons_10[i].Y_Start, Buttons_10[i].X_End, Buttons_10[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if (menuSize == 12) {
for (int i = 0; i < menuSize; i++) {
menuSize = 2; // the actual maxbuttons for this loop
if ((Touchx >= Buttons_12[i].X_Start) && (Touchx <= Buttons_12[i].X_End) && (Touchy >= Buttons_12[i].Y_Start) && (Touchy <= Buttons_12[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_12[i].X_Start, Buttons_12[i].Y_Start, Buttons_12[i].X_End, Buttons_12[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_12[i].X_Start, Buttons_12[i].Y_Start, Buttons_12[i].X_End, Buttons_12[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if (menuSize == 13) {
menuSize = 8; // the actual maxbuttons for this loop
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_13[i].X_Start) && (Touchx <= Buttons_13[i].X_End) && (Touchy >= Buttons_13[i].Y_Start) && (Touchy <= Buttons_13[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_13[i].X_Start, Buttons_13[i].Y_Start, Buttons_13[i].X_End, Buttons_13[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_13[i].X_Start, Buttons_13[i].Y_Start, Buttons_13[i].X_End, Buttons_13[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if (menuSize == 14) {
menuSize = 10; // the actual maxbuttons for this loop
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_14[i].X_Start) && (Touchx <= Buttons_14[i].X_End) && (Touchy >= Buttons_14[i].Y_Start) && (Touchy <= Buttons_14[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_14[i].X_Start, Buttons_14[i].Y_Start, Buttons_14[i].X_End, Buttons_14[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_14[i].X_Start, Buttons_14[i].Y_Start, Buttons_14[i].X_End, Buttons_14[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
else if (menuSize == 15) {
menuSize = 6; // the actual maxbuttons for this loop
for (int i = 0; i < menuSize; i++) {
if ((Touchx >= Buttons_15[i].X_Start) && (Touchx <= Buttons_15[i].X_End) && (Touchy >= Buttons_15[i].Y_Start) && (Touchy <= Buttons_15[i].Y_End))
{
// draw a red outline around the box that was pressed
TFT.setColor(VGA_RED);
TFT.drawRoundRect(Buttons_15[i].X_Start, Buttons_15[i].Y_Start, Buttons_15[i].X_End, Buttons_15[i].Y_End);
delay(150); // short delay to allow the red box to be noticable
// draw a white outline around the box that was pressed
TFT.setColor(VGA_WHITE);
TFT.drawRoundRect(Buttons_15[i].X_Start, Buttons_15[i].Y_Start, Buttons_15[i].X_End, Buttons_15[i].Y_End);
ButtonPressed = i; // set the button that was pressed
i = menuSize; // once the button has been found, exit the for loop
}
else { ButtonPressed = 255; }
}
}
}
void ClearScreenHeader()
// this function clears the screen and sets the font to be used
{
TFT.fillScr(VGA_NAVY); // fill the screen
TFT.setBackColor(VGA_NAVY); // set the back color
TFT.setFont(GroteskBold24x48); // set the font to be used
}
void REPLACEME(){
}
// MAIN MENU SECTION
// ***********************************************
void MainMenu() {
while (SubMenuLoopFlag == 1)
{
Serial.print("Main Menu Entered\n");
ClearScreenHeader(); // clear the touch screen
TFT.print("MAIN MENU", CENTER, 10, 0); // prints the menu name and centers it
DrawMenuButtonArray(MAIN_MENU_SIZE, Main_Menu); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(MAIN_MENU_SIZE, 300); // call the menu loop with 300ms of delay
// call the function depending on the button pressed
Serial.printf("Main Menu Button %d pressed\n\n", ButtonPressed);
function = Main_Menu[ButtonPressed].function; // set the function to be called when the button is pressed
(function)(); // call the function set
}
SubMenuLoopFlag = 1;
}
// USER SETUP MENU SECTION
// ***********************************************
void UserSetup(){
while (SubMenuLoopFlag == 1)
{
Serial.print("User Setup Entered\n");
ClearScreenHeader(); // clear the touch screen
TFT.print("USER SETUP", CENTER, 10, 0); // prints the menu name and centers it
DrawMenuButtonArray(USER_SETUP_SIZE, User_Setup); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(USER_SETUP_SIZE, 300); // call the menu loop with 300ms of delay
// call the function depending on the button pressed
Serial.printf("User Setup Button %d pressed\n\n", ButtonPressed);
function = User_Setup[ButtonPressed].function; // set the function to be called when the button is pressed
(function)(); // call the function set
Serial.println();
}
SubMenuLoopFlag = 1;
}
void Brightness(){
// Sets the brightness of the lcd screen
uint8_t menusize = User_Setup[ButtonPressed].Menu_Size; // set the menusize
Serial.print("Change Brightness Level Entered\n");
ClearScreenHeader(); // clear the touch screen
TFT.print("BRIGHTNESS", CENTER, 10, 0); // prints the menu name and centers it
DrawMenuButtonArray(menusize, Backlight_Brightness); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(menusize, 300); // call the menu loop with 300ms of delay
if (ButtonPressed == menusize - 1) { return; } // return to the previous menu if the back button was pressed
// evaluate the button pressed
Serial.printf("Brightness Level %d pressed\n", ButtonPressed);
ClearScreenHeader(); // clear the touch screen
TFT.print("Backlight Level Set", CENTER, 70, 0); // print the header
byte brightness; // byte to store the brightness level
switch (ButtonPressed) // switch depending on which button was pressed
{
case 0:
brightness = 255; // set the brightness to max level
TFT.print("to High", CENTER, 130, 0); // print to the display to see what was done
break;
case 1:
brightness = 170; // set the brightness to mid level
TFT.print("to Medium", CENTER, 130, 0); // print to the display to see what was done
break;
case 2:
brightness = 70; // set the brightness to low level
TFT.print("to Low", CENTER, 130, 0); // print to the display to see what was done
break;
default:
break;
}
eeprom.write(25, brightness); // write the data to the eeprom
brightness = eeprom.read(25); // read the data back out
analogWrite(TFT_B_LIGHT_PIN, brightness); // write the brightness to the PWM pin
delay(1000); // Small delay to allow the user to see the change on the screen
}
void TimeFormat()
// Sets the time format to 12h or 24h
{
uint8_t menusize = User_Setup[ButtonPressed].Menu_Size;
Serial.print("Change Time Format Entered\n");
ClearScreenHeader(); // clear the touch screen
TFT.print("TIME FORMAT", CENTER, 10, 0); // prints the menu name and centers it
DrawMenuButtonArray(menusize, Time_Format); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(menusize, 300); // call the menu loop with 300ms of delay
if (ButtonPressed == menusize - 1) { return; } // return to the previous menu if the back button was pressed
// evaluate the button pressed
Serial.printf("Time Format Button %d pressed\n", ButtonPressed);
ClearScreenHeader(); // clear the touch screen
TFT.print("Time Format Set to", CENTER, 70, 0); // print the header
switch (ButtonPressed) // switch depending on which button was pressed
{
case 0:
eeprom.write(23, 0); // write the data to the eeprom for 24 hour
timeFormat = 0;
TFT.print("24 Hour", CENTER, 130, 0); // print to the display to see what was done
break;
case 1:
eeprom.write(23, 1); // write the data to the eeprom for 12 hour
timeFormat = 1;
TFT.print("12 Hour", CENTER, 130, 0); // print to the display to see what was done
break;
default:
break;
}
delay(1000); // Small delay to allow the user to see the change on the screen
}
void SecondsDisplay(){
// Set how many buttons there are
uint8_t menusize = User_Setup[ButtonPressed].Menu_Size; // set the menusize
Serial.print("Change Seconds Display Entered\n");
ClearScreenHeader(); // clear the touch screen
TFT.print("SECONDS DISPLAY", CENTER, 10, 0); // prints the menu name and centers it
DrawMenuButtonArray(menusize, On_Off); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(menusize, 300); // call the menu loop with 300ms of delay
if (ButtonPressed == menusize - 1) { return; } // return to the previous menu if the back button was pressed
// evaluate the button pressed
Serial.printf("Seconds Display Button %d pressed\n", ButtonPressed);
ClearScreenHeader(); // clear the touch screen
TFT.print("Seconds Display set", CENTER, 70, 0); // print the header
switch (ButtonPressed)
{
case 0:
eeprom.write(24, 0); // write the data to the eeprom
TFT.print("to Off", CENTER, 130, 0); // print to the display to see what was done
break;
case 1:
eeprom.write(24, 1); // write the data to the eeprom
TFT.print("to On", CENTER, 130, 0); // print to the display to see what was done
break;
default:
break;
}
delay(1000); // Small delay to allow the user to see the change on the screen
}
void SetDateTime(){
uint8_t menusize; // set the menusize
uint8_t writetime = 0; // when set to 1 will enable the time save to the rtc
uint8_t writedate = 0; // when set to 1 will wnable the date save to the rtc
uint8_t twelvehour; // temp variable to store the 12 hour hour to display
char buffer[12]; // buffer to hold the assembled strings
Serial.print("Set Date/Time Entered\n");
// Set the date strings to be written later
ClearScreenHeader(); // clear the touch screen
TFT.print("SET DATE", CENTER, 10, 0); // prints the menu name and centers it
Serial.print("Setting Date\n");
menusize = 14; // set the menusize to call the date change display
DrawMenuButtonArray(menusize, Back_Next); // draws the menu buttons for the specified menu size and array
TFT.setBackColor(VGA_NAVY); // set the back color
TFT.setFont(GroteskBold24x48); // set the font to be used
writedate = AdjustDate(); // call the adjust date function
if (writedate == 0) { return; } // exits the funciton if the back button was pressed
// Set the time strings to be written later
ClearScreenHeader(); // clear the touch screen
TFT.print("SET TIME", CENTER, 10, 0); // prints the menu name and centers it
Serial.print("Setting Time\n");
menusize = 13; // set the menusize to call the time change display
DrawMenuButtonArray(menusize, Back_Next); // draws the menu buttons for the specified menu size and array
TFT.setBackColor(VGA_NAVY); // set the back color
TFT.setFont(GroteskBold24x48); // set the font to be used
writetime = AdjustTime(); // call the adjust time function
if (writetime == 0) { return; } // exits the funciton if the back button was pressed
// assemble the strings and print the date and time to be confirmed
ClearScreenHeader(); // clear the touch screen
TFT.print("SET DATE/TIME TO", CENTER, 10, 0); // prints the menu name and centers it
Serial.print("Saving Date/Time\n");
sprintf(buffer, "%s %2d/%02d/%02d", WEEKDAY[setweekday], setmonth, setday, setyear); // assemble the string to print the date display
TFT.print(buffer, CENTER, 85); // print the date to the screen
Serial.printf("Date: %s\n", buffer);
switch (timeFormat) {
case 0: // 24 hour display print
sprintf(buffer, "%02d:%02d:%02d", sethour, setminute, setsecond); // assemble the time string to print 24 hour display
break;
case 1: // 12 hour display print
// prep the hour to be displayed correctly for 12 hour
if (sethour == 0) { twelvehour = 12; }
else if (sethour < 12) { twelvehour = sethour; }
else if (sethour == 12) { twelvehour = 12; }
else if (sethour > 12) { twelvehour = sethour - 12; }
// print the hour depending on am or pm
if (sethour >= 12) { sprintf(buffer, "%2d:%02d:%02d PM", twelvehour, setminute, setsecond); } // print the PM display
else { sprintf(buffer, "%2d:%02d:%02d AM", twelvehour, setminute, setsecond); } // print the AM display
break;
default:
break;
}
Serial.printf("Time: %s\n", buffer);
TFT.print(buffer, CENTER, 139); // print the time string to the screen
// confirm the date and time to be set using the yes/no buttons
// draw the menu buttons
menusize = 12; // set the menusize to call the 2 button display
DrawMenuButtonArray(menusize, Yes_No); // draws the menu buttons for the specified menu size and array
// loop while we wait for touch screen data
MenuLoopFlag = 1; // enables the menu to loop
MenuLoop(menusize, 300); // call the menu loop
Serial.printf("Confirm date/time set button %d pressed\n\n", ButtonPressed);
switch (ButtonPressed) {
case 0: // yes button pressed, save the date and time
ClearScreenHeader();
TFT.print("Saving Date/Time", CENTER, 112);
setTime(sethour, setminute, setsecond, setday, setmonth, setyear);
RTC.set(now());
delay(1000);
// GET THE TIME FROM THE RTC
setSyncProvider(RTC.get); // this function get the time from the RTC
if (timeStatus() != timeSet) { // checks to see if it can read the RTC
RTC_Status = 0;
Serial.print("Unable to get the RTC\n\n");
}
else { Serial.print("RTC system time\n"); }
break;
case 1: // no button pressed return to the user setup screen
SubMenuLoopFlag = 0;