generated from othneildrew/Best-README-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.c
2416 lines (2039 loc) · 84.2 KB
/
menu.c
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
/*
@file menu.c
@brief Implementation of menu content build upon module tft.h (implemented for XMC4700 and DAVE)
@version 1.0
@date 2020-02-25
@author Rene Santeler @ MCI 2020/21
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <DAVE.h>
#include "globals.h"
#include "tft.h" // includes display EVE Library EVE.h
#include "polyfit/polyfit.h"
#include "record.h"
#include "menu.h"
/////////// Menu function pointers - At the end of the menu control functions (TFT_display_static, TFT_display and TFT_touch inside tft.h) the function referenced to this pointer is executed
// Every new menu needs to be defined in menu.h, declared at the end of this file and registered here in this function pointer array!
// TFT_MENU_SIZE is declared in menu.h and must be changed if menus are added or removed
// TFT_MAIN_MENU_SIZE is declared in menu.h. It states to where the main menus (accessible via swipe an background) are listed. All higher menus are considered submenus (control on how to get there is on menu.c)
void (*TFT_display_cur_Menu__fptr_arr[TFT_MENU_SIZE])(void) = {
&menu_display_0monitor,
&menu_display_1dash,
&menu_display_2setup1,
&menu_display_3setup2,
&menu_display_curveset,
&menu_display_filterset
};
void (*TFT_touch_cur_Menu__fptr_arr[TFT_MENU_SIZE])(uint8_t tag, uint8_t* toggle_lock, uint8_t swipeInProgress, uint8_t *swipeEvokedBy, int32_t *swipeDistance_X, int32_t *swipeDistance_Y) = {
&menu_touch_0monitor,
&menu_touch_1dash,
&menu_touch_2setup1,
&menu_touch_3setup2,
&menu_touch_curveset,
&menu_touch_filterset
};
void (*TFT_display_static_cur_Menu__fptr_arr[TFT_MENU_SIZE])(void) = {
&menu_display_static_0monitor,
&menu_display_static_1dash,
&menu_display_static_2setup1,
&menu_display_static_3setup2,
&menu_display_static_curveset,
&menu_display_static_filterset
};
/////////// Menu definition structs - Define header, share and color of the menu
#define M_0_UPPERBOND 65
menu menu_0monitor = {
.index = 0,
.headerText = "Monitoring",
.upperBond = M_0_UPPERBOND, // deepest coordinate (greatest number) of the header
.headerLayout = {M_0_UPPERBOND, 320, 50, 360}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
#define M_1_UPPERBOND 65 // deepest coordinate (greatest number) of the header
menu menu_1dashboard = {
.index = 1,
.headerText = "Dashboard",
.upperBond = M_1_UPPERBOND, // deepest coordinate (greatest number) of the header
.headerLayout = {M_1_UPPERBOND, 280, 50, 320}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
#define M_SETUP_UPPERBOND 65 // deepest coordinate (greatest number) of the header
menu menu_2setup1 = {
.index = 2,
.headerText = "Setup I",
.upperBond = M_SETUP_UPPERBOND, // deepest coordinate (greatest number) of the header
.headerLayout = {M_SETUP_UPPERBOND, 240, 50, 280}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
#define M_SETUP_UPPERBOND 65 // deepest coordinate (greatest number) of the header
menu menu_3setup2 = {
.index = 3,
.headerText = "Setup II",
.upperBond = M_SETUP_UPPERBOND, // deepest coordinate (greatest number) of the header
.headerLayout = {M_SETUP_UPPERBOND, 240, 50, 280}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
#define M_LINSET_UPPERBOND 40
menu menu_curveset = {
.index = 4,
.headerText = "",
.upperBond = 0, // removed upper bond because header is written every TFT_display() in this submenu (alwayson top -> no overlay possible)
.headerLayout = {0, EVE_HSIZE-65, M_LINSET_UPPERBOND, EVE_HSIZE-50}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
#define M_LINSET_UPPERBOND 40
menu menu_filterset = {
.index = 5,
.headerText = "",
.upperBond = 0, // removed upper bond because header is written every TFT_display() in this submenu (on top -> no overlay possible)
.headerLayout = {0, EVE_HSIZE-65, M_LINSET_UPPERBOND, EVE_HSIZE-50}, //[Y1,X1,Y2,X2]
.bannerColor = MAIN_BANNERCOLOR,
.dividerColor = MAIN_DIVIDERCOLOR,
.headerColor = MAIN_TEXTCOLOR,
};
/////////// Menu definitions array - Groups all menu definitions
menu* menu_objects[TFT_MENU_SIZE] = {&menu_0monitor, &menu_1dashboard, &menu_2setup1, &menu_3setup2, &menu_curveset, &menu_filterset};
/////////// Menu space and distance conventions
#define M_UPPER_PAD 14 // Common padding from upper border (offset in pixels from the upper header or display edge)
#define M_ROW_DIST 40 // Common distance between rows of content
#define M_COL_1 25 // Start of first Column (is also the padding/indent from the left edge)
#define M_COL_2 140 // Suggestion of an absolute second column coordinate to be used when displaying stuff (no need to use this, but easier to structure)
#define M_COL_3 200 // Suggestion ...
#define M_COL_4 400
#define FONT_COMP 3 // In order to get text of different fonts to the same level an adjustment is need
#define G_PADDING 12 // Graph inner padding
#ifndef TEXTBOX_PAD_V // This should be defined in tft.c
#define TEXTBOX_PAD_V 8 // offset of the text from vertical border in pixel
#endif
/////////// Debug
uint16_t display_list_size = 0; // Current size of the display-list from register. Used by the TFT_display() menu specific functions
uint32_t tracker = 0; // Value of tracker register (1.byte=tag, 2.byte=value). Used by the TFT_display() menu specific functions
// Temporary value for deflection
float_buffer_t f_deflection = 0.0;
float_buffer_t r_deflection = 0.0;
int16_t record_time = 0;
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Monitoring Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Input signal type used for measurement and GUI display
uint8_t inputType = 0;
#define BTN_INPUT_TAG 13
control btn_input = {
.x = 180, .y = 17,
.w0 = 70, .h0 = 30,
.mytag = BTN_INPUT_TAG, .font = 27, .options = 0, .state = 0,
.text = "Raw1",
.controlType = Button,
.ignoreScroll = 1
};
#define BTN_GRAPHMODE_TAG 12
control tgl_graphMode = {
.x = 270, .y = 26,
.w0 = 60, .h0 = 27,
.mytag = BTN_GRAPHMODE_TAG, .font = 27, .options = 0, .state = 0,
.text = "Frame",
.controlType = Toggle,
.ignoreScroll = 1
};
label lbl_sensor = {
.x = 360, .y = 25, //10&25 for 2 lines
.font = 26, .options = 0, .text = "Value:",
.ignoreScroll = 1,
.numSrc.srcType = srcTypeNone
};
label lbl_sensor_val = {
.x = 470, .y = 25, //10&25 for 2 lines
.font = 26, .options = EVE_OPT_RIGHTX, .text = "%d",//.text = "%d.%.2d V",
.ignoreScroll = 1,
.numSrc.srcType = srcTypeInt, //srcTypeFloat,
.numSrc.intSrc = (int_buffer_t*)&s1_buf_0raw, //(float_buffer_t*)&InputBuffer1_conv,
.numSrc.srcOffset = (uint16_t*)&sensor1.bufIdx, // (ignore volatile here)
.fracExp = 2
};
label lbl_misc = {
.x = 360, .y = 25,
.font = 26, .options = 0, .text = "DL-size:",
.ignoreScroll = 1,
.numSrc.srcType = srcTypeNone
};
label lbl_misc_val = {
.x = 470, .y = 25,
.font = 26, .options = EVE_OPT_RIGHTX, .text = "%d",
.ignoreScroll = 1,
.numSrc.srcType = srcTypeInt, .numSrc.intSrc = &display_list_size, .numSrc.srcOffset = NULL
};
// Graph position and size. Here -> quick an dirty estimation where x, y, width and height must be to fill the whole main area
graph gph_monitor = {
.x = 10, // 10 px from left to leave some room
.y = (M_0_UPPERBOND + 15), // end of banner plus 10 to leave some room (for Y1=66: 66+15=81)
.width = (0 + EVE_HSIZE - 10 - (2*G_PADDING) - 10), // actual width of the data area, therefore x and the paddings left and right must me accommodated to "fill" the whole main area. Additional 10 px from right to leave some room (for 480x272: 480-10-20-10=440)
.height = (0 + EVE_VSIZE - (M_0_UPPERBOND + 15) - (2*G_PADDING) - 10), // actual height of the data area, therefore y and the paddings top and bottom must me accommodated to "fill" the whole main area. Additional 10 px from bottom to leave some room (for 480x272: 272-66+15-20-10=161)
.padding = G_PADDING,
.x_label = "t ",
.y_label = "V ",
.y_max = 4095.0, // maximum allowed amplitude y (here for 12bit sensor value);
.amp_max = 5.2, // volts - used at print of vertical grid value labels
.cx_max = 2.2, // seconds - used at print of horizontal grid value labels
.h_grid_lines = 4.0, // number of grey horizontal grid lines
.v_grid_lines = 2.2, // number of grey vertical grid lines
.graphmode = 0
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Dashboard Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#define BTN_STARTREC_TAG 10
control btn_startRec = {
.x = 350, .y = M_UPPER_PAD + M_1_UPPERBOND + 7,
.w0 = 90, .h0 = 60,
.mytag = BTN_STARTREC_TAG, .font = 28, .options = 0, .state = 0,
.text = "Record",
.controlType = Button,
.ignoreScroll = 1
};
label lbl_record = {
.x = M_COL_1, .y = M_UPPER_PAD + M_1_UPPERBOND,
.font = 27, .options = 0, .text = "",
.ignoreScroll = 0
};
label lbl_record_time = {
.x = 370, .y = M_UPPER_PAD + M_1_UPPERBOND + (M_ROW_DIST*2),
.font = 27, .options = 0, .text = "%d sec",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeInt,
.numSrc.intSrc = (int_buffer_t*)&record_time,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_dash_f = { //deflection front
.x = M_COL_1, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*0),
.font = 30, .options = 0, .text = "Front",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeNone,
.numSrc.floatSrc = NULL,
.numSrc.srcOffset = NULL,
.fracExp = 0
};
label lbl_dash_r = { //deflection rear
.x = 200, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*0),
.font = 30, .options = 0, .text = "Rear",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeNone,
.numSrc.floatSrc = NULL,
.numSrc.srcOffset = NULL,
.fracExp = 0
};
label lbl_dash_f_d = { //deflection front value
.x = M_COL_1 + 115, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),//.x = 130, .y = M_UPPER_PAD + M_1_UPPERBOND + (M_ROW_DIST*3),
.font = 30, .options = EVE_OPT_RIGHTX, .text = "%d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&f_deflection,
.numSrc.srcOffset = NULL,
.fracExp = 0
};
label lbl_dash_r_d = { //deflection rear value
.x = 200 + 100, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),//.x = 130, .y = M_UPPER_PAD + M_1_UPPERBOND + (M_ROW_DIST*2),
.font = 30, .options = EVE_OPT_RIGHTX, .text = "%d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&r_deflection,
.numSrc.srcOffset = NULL,
.fracExp = 0
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Setup1 Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
label lbl_recording = {
.x = M_COL_1, .y = M_UPPER_PAD + M_SETUP_UPPERBOND,
.font = 27, .options = 0, .text = "Recording",
.ignoreScroll = 0
};
#define TBX_FILENAME_TAG 20
textbox tbx_filename = {
.x = M_COL_2,
.y = M_UPPER_PAD + M_SETUP_UPPERBOND - TEXTBOX_PAD_V + FONT_COMP*1,
.width = EVE_HSIZE - M_COL_2 - 65 - 25,
.labelOffsetX = 65,
.labelText = "Filename:",
.mytag = TBX_FILENAME_TAG,
.text = filename_rec,
.text_maxlen = FILENAME_REC_MAXLEN,
.text_curlen = &filename_rec_curLength, // see globals.h/.c
.keypadType = Filename,
.active = 0,
.numSrc.srcType = srcTypeNone
};
label lbl_calibrate = {
.x = M_COL_1, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),
.font = 27, .options = 0, .text = "Calibrate",
.ignoreScroll = 0
};
#define TBX_SENSOR1_TAG 21
textbox tbx_sensor1 = {
.x = M_COL_2,
.y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1) - TEXTBOX_PAD_V + FONT_COMP*1,
.width = EVE_HSIZE - (M_COL_2) - 130 - 25,
.labelOffsetX = 130,
.labelText = "S1 Front: CAL File",
.mytag = TBX_SENSOR1_TAG,
.text = s1_filename_cal,
.text_maxlen = STR_SPEC_MAXLEN,
.text_curlen = (uint8_t*)&sensor1.fitFilename_curLen, //(ignore volatile here)
.keypadType = Standard,
.active = 0,
.numSrc.srcType = srcTypeNone
};
label lbl_curveset_S1 = {
.x = 205, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) + FONT_COMP*1,
.font = 26, .options = 0, .text = "Curve fit:",
.ignoreScroll = 0
};
#define BTN_CURVESET_S1_TAG 22
control btn_curveset_S1 = {
.x = 270, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 31,
.mytag = BTN_CURVESET_S1_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
label lbl_filterset_S1 = {
.x = 355, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) + FONT_COMP*1,
.font = 26, .options = 0, .text = "Filter:",
.ignoreScroll = 0
};
#define BTN_FILTERSET_S1_TAG 23
control btn_filterset_S1 = {
.x = EVE_HSIZE - 25 - 55, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 31,
.mytag = BTN_FILTERSET_S1_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
#define TBX_SENSOR2_TAG 24
textbox tbx_sensor2 = {
.x = M_COL_2,
.y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3) - TEXTBOX_PAD_V + FONT_COMP*1,
.width = EVE_HSIZE - (M_COL_2) - 130 - 25,
.labelOffsetX = 130,
.labelText = "S2 Rear: CAL File",
.mytag = TBX_SENSOR2_TAG,
.text = s2_filename_cal,
.text_maxlen = STR_SPEC_MAXLEN,
.text_curlen = (uint8_t*)&sensor2.fitFilename_curLen,
.keypadType = Standard,
.active = 0,
.numSrc.srcType = srcTypeNone
};
label lbl_curveset_S2 = {
.x = 205, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4) + FONT_COMP*1,
.font = 26, .options = 0, .text = "Curve fit:",
.ignoreScroll = 0
};
#define BTN_CURVESET_S2_TAG 25
control btn_curveset_S2 = {
.x = 270, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 31,
.mytag = BTN_CURVESET_S2_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
label lbl_filterset_S2 = {
.x = 355, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4) + FONT_COMP*1,
.font = 26, .options = 0, .text = "Filter:",
.ignoreScroll = 0
};
#define BTN_FILTERSET_S2_TAG 26
control btn_filterset_S2 = {
.x = EVE_HSIZE - 25 - 55, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 31,
.mytag = BTN_FILTERSET_S2_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Setup2 Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Sag section
#define REARXOFFSET 60
#define FRONTXOFFSET 60
#define ROWHEADERXOFFSET 90
label lbl_sag_header = {
.x = M_COL_1, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),
.font = 27, .options = 0, .text = "Sag:",
.ignoreScroll = 0
};
//float_buffer_t f_unloaded = 0.0;
//float_buffer_t r_unloaded = 0.0;
//float_buffer_t f_sag = 0.0;
//float_buffer_t r_sag = 0.0;
label lbl_front = {
.x = M_COL_2+FRONTXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),
.font = 26, .options = 0, .text = "Front:",
.ignoreScroll = 0
};
label lbl_rear = {
.x = M_COL_4-REARXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1),
.font = 26, .options = 0, .text = "Rear:",
.ignoreScroll = 0
};
label lbl_unloaded = { // origin point
.x = M_COL_1+ROWHEADERXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2),
.font = 26, .options = 0, .text = "Unloaded",
.ignoreScroll = 0
};
label lbl_sag = { //operating point offset
.x = M_COL_1+ROWHEADERXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3),
.font = 26, .options = 0, .text = "Driver Sag",
.ignoreScroll = 0
};
label lbl_deflection = { //deflection
.x = M_COL_1+ROWHEADERXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4),
.font = 26, .options = 0, .text = "Deflection",
.ignoreScroll = 0
};
// Definition of table separator lines
#define TBL_H_X1 (M_COL_1 + ROWHEADERXOFFSET)
#define TBL_H_Y1 (M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - (M_ROW_DIST/2) + 2)
#define TBL_H_X2 (M_COL_4 + 55)
#define TBL_H_Y2 (M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - (M_ROW_DIST/2) + 2)
#define TBL_V_X1 (M_COL_2 + FRONTXOFFSET - 8)
#define TBL_V_Y1 (M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*1))
#define TBL_V_X2 (M_COL_2 + FRONTXOFFSET - 8)
#define TBL_V_Y2 (M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4) + (M_ROW_DIST/2))
label lbl_f_unloaded = { // origin point front
.x = M_COL_2+FRONTXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&sensor1.originPoint,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_r_unloaded = { // origin point rear
.x = M_COL_4-REARXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&sensor2.originPoint,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_f_sag = { //operating point offset front
.x = M_COL_2+FRONTXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&sensor1.operatingPoint,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_r_sag = { //operating point offset rear
.x = M_COL_4-REARXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&sensor2.operatingPoint,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_f_deflection = { //deflection front
.x = M_COL_2+FRONTXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&f_deflection,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
label lbl_r_deflection = { //deflection rear
.x = M_COL_4-REARXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*4),
.font = 26, .options = 0, .text = "%d.%.1d mm",
.ignoreScroll = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&r_deflection,
.numSrc.srcOffset = NULL,
.fracExp = 1
};
#define BTN_F_UNLOADED_TAG 11
control btn_f_unloaded = {
.x = M_COL_3+FRONTXOFFSET+5, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 30,
.mytag = BTN_F_UNLOADED_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_R_UNLOADED_TAG 12
control btn_r_unloaded = {
.x = M_COL_4, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*2) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 30,
.mytag = BTN_R_UNLOADED_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_F_SAG_TAG 13
control btn_f_sag = {
.x = M_COL_3+FRONTXOFFSET+5, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 30,
.mytag = BTN_F_SAG_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_R_SAG_TAG 14
control btn_r_sag = {
.x = M_COL_4, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*3) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 55, .h0 = 30,
.mytag = BTN_R_SAG_TAG, .font = 27, .options = 0, .state = 0,
.text = "Set",
.controlType = Button,
.ignoreScroll = 0
};
// Section Backlight
label lbl_backlight = {
.x = M_COL_1, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*0),
.font = 27, .options = 0, .text = "Backlight",
.ignoreScroll = 0
};
#define BTN_DIMMER_TAG 10
control btn_dimmmer = {
.x = M_COL_1+ROWHEADERXOFFSET, .y = M_UPPER_PAD + M_SETUP_UPPERBOND + (M_ROW_DIST*0) - TEXTBOX_PAD_V + FONT_COMP*1,
.w0 = 80, .h0 = 30,
.mytag = BTN_DIMMER_TAG, .font = 27, .options = 0, .state = 0,
.text = "Dimmer",
.controlType = Button,
.ignoreScroll = 0
};
// RTC currently unused (Fromat "HH:mm:ss dd.MM.yy")
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// Common elements of set submenus -----------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
char str_submenu_header[25] = "";
#define BTN_BACK_TAG 10
control btn_back = {
.x = EVE_HSIZE-45, .y = 5,
.w0 = 40, .h0 = 30,
.mytag = BTN_BACK_TAG, .font = 27, .options = 0, .state = 0,
.text = "Back",
.controlType = Button,
.ignoreScroll = 1
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// CurveSet Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void curveset_prepare(volatile sensor* sens);
void curveset_setEditMode(uint8_t editMode);
// Size and current index of all data point related arrays
//uint16_t DP_size = 3;
uint16_t DP_cur = 0;
// Pointer to the currently being recorded sensor - set at prepare and e.g. used when getting the nominal value at display function or storing of the fit values
sensor* curveset_sens;
// The avgFilterInterval of the sensor is temporarily changed while curveset menu is active. This variable stores the original value it will be reset to when coming back from the submenu.
uint16_t curveset_previousAvgFilterInterval;
// Array to store the coefficients for the fitted polynomial and the state of the fit (0=OK everything else is error)
uint8_t fit_order = 1;
float coefficients[4] = {0,0,0,0}; //{25.0, -0.0235162665374, 0.00001617208884, 0, 0};
uint8_t fit_result = 0;
label lbl_curveset = {
.x = 20, .y = 9,
.font = 27, .options = 0, .text = &str_submenu_header[0],//"Curve fit - Sensor 0",
.ignoreScroll = 0
};
label lbl_fitorder = {
.x = M_COL_3 + 40, .y = 9 + FONT_COMP,
.font = 26, .options = 0, .text = "Function",
.ignoreScroll = 0
};
graph gph_curveset = {
.x = 10, // 10 px from left to leave some room
.y = 30 + M_UPPER_PAD, // end of banner plus 10 to leave some room (e.g. for Y1=66: 66+15=81)
.width = (0 + EVE_HSIZE - 10 - (2*G_PADDING) - 10), // actual width of the data area, therefore x and the paddings left and right must me accommodated to "fill" the whole main area. Additional 10 px from right to leave some room (for 480x272: 480-10-20-10=440)
.height = (0 + EVE_VSIZE - 15 - (2*G_PADDING) - 10 - (M_ROW_DIST*2)), // actual height of the data area, therefore y and the paddings top and bottom must me accommodated to "fill" the whole main area. Additional 10 px from bottom to leave some room (for 480x272: 272-66+15-20-10=161)
.padding = G_PADDING,
.x_label = "nominal",
.y_label = "actual in mm",
.y_max = 200.0, // maximum allowed amplitude y (here for 12bit sensor value);
.amp_max = 200.0, // in given unit - used at print of vertical grid value labels
.cx_initial = 0,
.cx_max = 4096, // seconds - used at print of horizontal grid value labels
.h_grid_lines = 4.0, // number of grey horizontal grid lines
.v_grid_lines = 2.0, // number of grey vertical grid lines
.graphmode = 1,
};
#define BTN_DP_LAST_TAG 11
control btn_db_last = {
.x = (M_COL_1/2) + 75 + 36 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 25 , .h0 = 30,
.mytag = BTN_DP_LAST_TAG, .font = 27, .options = 0, .state = 0,
.text = "<",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_DP_NEXT_TAG 12
control btn_db_next = {
.x = (M_COL_1/2) + 75 + 36 + 1 + 25 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 25 , .h0 = 30,
.mytag = BTN_DP_NEXT_TAG, .font = 27, .options = 0, .state = 0,
.text = ">",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_DP_DELETE_TAG 13
control btn_db_delete = {
.x = (M_COL_1/2) + 75 + 36 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 50 , .h0 = 30,
.mytag = BTN_DP_DELETE_TAG, .font = 27, .options = 0, .state = 0,
.text = "Delete",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_DP_SETCHANGE_TAG 14
control btn_setchange = {
.x = (M_COL_1/2) + 75 + 36 + 1 + 25 + 1 + 30 + 8 + 1 + 50 + 58 + 8 + 50 + 60 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 50, .h0 = 30,
.mytag = BTN_DP_SETCHANGE_TAG, .font = 26, .options = 0, .state = 0,
.text = "Change",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_ORDER_TAG 15
control btn_order = {
.x = M_COL_3 + 40 + 60 , .y = 5,
.w0 = 60, .h0 = 30,
.mytag = BTN_ORDER_TAG, .font = 26, .options = 0, .state = 0,
.text = "Linear",
.controlType = Button,
.ignoreScroll = 0
};
/// Textboxes
#define STR_DP_MAXLEN 3
char str_dp[STR_DP_MAXLEN] = "0";
uint8_t str_dp_curLength = 1;
#define TBX_DP_TAG 24
textbox tbx_dp = {
.x = (M_COL_1/2),
.y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.width = 36,
.labelOffsetX = 75,
.labelText = "Data Point:",
.mytag = 0, //TBX_DP_TAG, // Made read-only because there needs to be an border check before this is useful
.text = str_dp,
.text_maxlen = STR_DP_MAXLEN,
.text_curlen = &str_dp_curLength,
.keypadType = Numeric,
.active = 0,
.numSrc.srcType = srcTypeInt,
.numSrc.intSrc = (int_buffer_t*)&DP_cur,
.numSrc.srcOffset = NULL,
.numSrcFormat = "%d"
};
// The pointers the the x and y value arrays to be used with realloc and used by the textboxes and graph are inside tbx_nom and tbx_act.
#define STR_NOM_MAXLEN 10
char str_nom[STR_NOM_MAXLEN] = "4095";
uint8_t str_nom_curLength = 4;
//#define TBX_NOM_TAG 0
textbox tbx_nom = {
.x = (M_COL_1/2) + 75 + 36 + 1 + 25 + 1 + 30 + 5,
.y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.width = 53,
.labelOffsetX = 58,
.labelText = "Nominal:",
.mytag = 0,
.text = str_nom,
.text_maxlen = STR_NOM_MAXLEN,
.text_curlen = &str_nom_curLength,
.keypadType = Numeric,
.active = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = NULL,
.numSrc.srcOffset = NULL,
.numSrcFormat = "%d.%.0d",
.fracExp = 1
};
#define STR_ACT_MAXLEN 10
char str_act[STR_ACT_MAXLEN] = "";
uint8_t str_act_curLength = 0;
#define TBX_ACT_TAG 26
textbox tbx_act = {
.x = (M_COL_1/2) + 75 + 36 + 1 + 25 + 1 + 30 + 8 + 1 + 50 + 58 + 8,
.y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.width = 60,
.labelOffsetX = 50,
.labelText = "Actual:",
.mytag = 0,
.text = str_act,
.text_maxlen = STR_ACT_MAXLEN,
.text_curlen = &str_act_curLength,
.keypadType = Numeric,
.active = 0,
.numSrc.srcType = srcTypeFloat,
.numSrc.intSrc = NULL,
.numSrc.srcOffset = NULL,
.numSrcFormat = "%d.%.2d",
.fracExp = 2
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// FilterSet Elements -----------------------------------------------------------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void filterset_prepare(volatile sensor* sens);
void filterset_setEditMode(uint8_t editMode);
// Pointer to the currently being recorded sensor - set at prepare and e.g. used when getting the nominal value at display function or storing of the fit values
sensor* filterset_sens = NULL;
uint16_t filter_errorThreshold = 4095;
label lbl_filterset = {
.x = 20, .y = 9,
.font = 27, .options = 0, .text = &str_submenu_header[0], //"Filter set - Sensor 0",
.ignoreScroll = 0
};
// Current maximum error between filtered and unfiltered values
float_buffer_t filterset_maxError = 0;
label lbl_filterErrorText = {
.x = M_COL_2 + 60, .y = 9 + FONT_COMP,
.font = 26, .options = 0, .text = "Max error: ",
.ignoreScroll = 0
};
label lbl_filterError = {
.x = M_COL_2 + 60 + 65, .y = 9 + FONT_COMP,
.font = 26, .options = 0, .text = "%d.%.2d mm",
.numSrc.srcType = srcTypeFloat,
.numSrc.floatSrc = (float_buffer_t*)&filterset_maxError, //(ignore volatile here)
.numSrc.srcOffset = NULL,
.fracExp = 2,
.ignoreScroll = 0
};
graph gph_filterset = {
.x = 10, // 10 px from left to leave some room
.y = 30 + M_UPPER_PAD, // end of banner plus 10 to leave some room (e.g. for Y1=66: 66+15=81)
.width = (0 + EVE_HSIZE - 10 - (2*G_PADDING) - 10), // actual width of the data area, therefore x and the paddings left and right must me accommodated to "fill" the whole main area. Additional 10 px from right to leave some room (for 480x272: 480-10-20-10=440)
.height = (0 + EVE_VSIZE - 15 - (2*G_PADDING) - 10 - (M_ROW_DIST*2)), // actual height of the data area, therefore y and the paddings top and bottom must me accommodated to "fill" the whole main area. Additional 10 px from bottom to leave some room (for 480x272: 272-66+15-20-10=161)
.padding = G_PADDING,
.x_label = "time",
.y_label = "ADC values",
.y_max = 4096.0, // maximum allowed amplitude y (here for 12bit sensor value);
.amp_max = 4096.0, // in given unit - used at print of vertical grid value labels
.cx_initial = 0,
.cx_max = 2.2, // seconds - used at print of horizontal grid value labels
.h_grid_lines = 4.0, // number of grey horizontal grid lines
.v_grid_lines = 2.0, // number of grey vertical grid lines
.graphmode = 0,
};
#define BTN_FILTER_DOWN_TAG 11
control btn_filter_down = {
.x = M_COL_1 + 90 + 40 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 30 , .h0 = 30,
.mytag = BTN_DP_LAST_TAG, .font = 27, .options = 0, .state = 0,
.text = "-",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_FILTER_UP_TAG 12
control btn_filter_up = {
.x = M_COL_1 + 90 + 40 + 1 + 30 + 1, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 30 , .h0 = 30,
.mytag = BTN_DP_NEXT_TAG, .font = 27, .options = 0, .state = 0,
.text = "+",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_FILTER_SETCHANGE_TAG 13
control btn_filter_setchange = {
.x = EVE_HSIZE - 55 - 25, .y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.w0 = 55, .h0 = 30,
.mytag = BTN_FILTER_SETCHANGE_TAG, .font = 26, .options = 0, .state = 0,
.text = "Change",
.controlType = Button,
.ignoreScroll = 0
};
#define BTN_FILTERERROR_RESET 14
control btn_filterError_reset = {
.x = M_COL_3 + 105 + 26 + 5 , .y = 5,
.w0 = 50 , .h0 = 30,
.mytag = BTN_FILTERERROR_RESET, .font = 27, .options = 0, .state = 0,
.text = "Reset",
.controlType = Button,
.ignoreScroll = 0
};
/// Textboxes
#define STR_FILTER_INTERVAL_MAXLEN 3
char str_filter_interval[STR_FILTER_INTERVAL_MAXLEN] = "0";
uint8_t str_filter_interval_curLength = 1;
#define TBX_FILTER_INTERVAL_TAG 24
textbox tbx_filter_interval = {
.x = M_COL_1,
.y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.width = 40,
.labelOffsetX = 90,
.labelText = "Filter Interval:",
.mytag = 0,
.text = str_filter_interval,
.text_maxlen = STR_FILTER_INTERVAL_MAXLEN,
.text_curlen = &str_filter_interval_curLength,
.keypadType = Numeric,
.active = 0,
.numSrc.srcType = srcTypeInt,
.numSrc.intSrc = NULL,
.numSrc.srcOffset = NULL,
.numSrcFormat = "%d"
};
#define STR_ERROR_THRESHOLD_MAXLEN 5
char str_error_threshold[STR_ERROR_THRESHOLD_MAXLEN] = "4095";
uint8_t str_error_threshold_curLength = 4;
#define TBX_FILTER_ERROR_THRESHOLD_TAG 25
textbox tbx_error_threshold = {
.x = EVE_HSIZE - 55 - 25 - 55 - 105 - 5,
.y = EVE_VSIZE - M_UPPER_PAD - M_ROW_DIST,
.width = 55,
.labelOffsetX = 105,
.labelText = "Error Threshold:",
.mytag = 0,
.text = str_error_threshold,
.text_maxlen = STR_ERROR_THRESHOLD_MAXLEN,
.text_curlen = &str_error_threshold_curLength,
.keypadType = Numeric,
.active = 0,
.numSrc.srcType = srcTypeInt,
.numSrc.intSrc = &filter_errorThreshold,
.numSrc.srcOffset = NULL,
.numSrcFormat = "%d"
};
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// End of Element definition ----------------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifdef DEBUG_ENABLE
void TFT_recordScreenshot(void){
/// Create a screenshot and write it to sd-card
printf("Making screenshot\n");
// Open/create bmp file
uint8_t openOK = record_openBMP("SC.BMP");
if (openOK == 1){
// Number of pixels an bytes
#define SS_PIXELS (EVE_HSIZE * EVE_VSIZE)
#define SS_BYTES (SS_PIXELS * 4) // 32 bit
// Create Screenshot in display memory
EVE_cmd_snapshot2(0x20, 0, 0, 0, EVE_HSIZE*2, EVE_VSIZE);
// Get pixel per pixel (32bit) from display and write it to sd-card
printf("Writing screenshot\n");
uint32_t bmp = 0;
for (uint32_t i = 0; i < SS_PIXELS; i++) {
bmp = EVE_memRead32(0 + (i*4));
record_writeBMP(&bmp, 4);
if(i % 1000 == 0)
printf("%d\n", (int)i);
}
printf("Finished\n");
// Close bmp file
record_closeBMP();
// Refresh display
TFT_setMenu(-1);
}
else
printf("Unable to open screenshot\n");
}
#endif
void TFT_display_get_values(void){