forked from mstrens/grbl_controller_esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.cpp
1469 lines (1329 loc) · 67.5 KB
/
draw.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 "config.h"
#include "draw.h"
#include "language.h"
#include "TFT_eSPI_ms/TFT_eSPI.h"
#include "FS.h"
#include "actions.h"
#include "menu_file.h"
#include "SdFat.h"
#include "browser.h"
#include "com.h"
#include "log.h"
#define LABELS9_FONT &FreeSans9pt7b // Key label font 2
#define LABELS12_FONT &FreeSans12pt7b
#define LABELSB9_FONT &FreeSansBold9pt7b
#define LABELCB12_FONT &FreeSansBold12pt7b
#define LABELM9_FONT &FreeMono9pt7b // Key label font 2
#define LABELM12_FONT &FreeMono12pt7b
#define LABELMB9_FONT &FreeMonoBold9pt7b
#define LABELMB12_FONT &FreeMonoBold12pt7b
//#define NORMAL_BORDER TFT_WHITE
//#define SELECTED_BORDER TFT_RED
// create for touchscreeen
TFT_eSPI tft = TFT_eSPI();
M_Button mButton[_MAX_BTN] ;
M_Page mPages[_P_MAX_PAGES];
extern uint8_t prevPage , currentPage ;
extern boolean updateFullPage ;
extern boolean updatePartPage ;
extern uint8_t justPressedBtn , justReleasedBtn, longPressedBtn , lastBtn ,currentBtn;
extern boolean waitReleased ;
extern uint32_t beginChangeBtnMillis ;
//extern uint8_t sdStatus ;
extern int8_t dirLevel ;
extern uint16_t sdFileDirCnt ;
extern uint32_t sdFileSize ;
extern uint32_t sdNumberOfCharSent ;
extern char fileNames[4][23] ; // 22 car per line + "\0"
extern uint16_t firstFileToDisplay ; // 0 = first file in the directory
extern SdFat sd; // is created in ino file
extern SdBaseFile aDir[DIR_LEVEL_MAX] ;
extern char cmdName[11][17] ; // contains the names of the commands
extern uint8_t statusPrinting ;
extern float wposXYZA[4] ;
extern float mposXYZA[3] ;
extern char machineStatus[9];
extern float feedSpindle[2] ;
extern float overwritePercent[3] ; // first is for feedrate, second for rapid (G0...), third is for RPM
extern char lastMsg[80] ; // last message to display
extern uint16_t lastMsgColor ; // color of last Msg
extern uint8_t logBuffer[MAX_BUFFER_SIZE] ;
extern uint8_t * pNext ; // position of the next char to be written
extern uint8_t * pFirst ; // position of the first char
extern uint8_t * pGet ; // position of the last char to be read for display
//char sdStatusText[][20] = { "No Sd card" , "Sd card to check" , "Sd card OK" , "Sd card error"} ; // pour affichage en clair sur le lcd;
char printingStatusText[][20] = { " " , "SD-->Grbl" , "Error SD-->Grbl" , "Pause SD-->Grbl" , "Usb-->Grbl" , "CMD" , "Telnet-->Grbl" , "Set cmd"} ;
//extern int8_t prevMoveX ;
//extern int8_t prevMoveY ;
//extern int8_t prevMoveZ ;
//extern int8_t prevMoveA ;
extern float moveMultiplier ;
// used by nunchuck
extern uint8_t jog_status ;
extern boolean jogCancelFlag ;
extern boolean jogCmdFlag ;
extern boolean statusTelnetIsConnected ;
extern uint8_t logBuffer[MAX_BUFFER_SIZE] ; // log data
//extern uint8_t * pNext ; // position of the next char to be written
//extern uint8_t * pFirst ; // position of the first char
extern uint8_t * pGet ; // position of the last char to be read for display
uint8_t * pLastLogLine ; // pointer to the last Log line
boolean endOfLog = true ;
float wposMoveInitXYZA[4] ;
// previous values used to optimise redraw of INFO screen
uint8_t statusPrintingPrev;
uint8_t machineStatus0Prev; // we keep only the first char for fast testing, so we can't use ir when equal to A or H
extern boolean lastMsgChanged ;
boolean statusTelnetIsConnectedPrev ;
boolean newInfoPage ;
char lineOfText[50] ; // Store 1 line of text for Log screen
extern char grblLastMessage[STR_GRBL_BUF_MAX_SIZE] ;
extern boolean grblLastMessageChanged;
//**************** normal screen definition.
#define B0 3
#define E0 3+74
#define B1 3+80
#define E1 3+80+74
#define B2 3+160
#define E2 3+160+74
#define B3 3+240
#define E3 3+240+74
#define FXB 3
#define FXE 3+80+74
#define FYB0 2
#define FYE0 2 + 56
#define FYB1 2 + 56 + 4
#define FYE1 2 + 56 + 4 + 56
#define FYB2 2 + 56 + 4 + 56 + 4
#define FYE2 2 + 56 + 4 + 56 + 4 + 56
#define FYB3 2 + 56 + 4 + 56 + 4 + 56 + 4
#define FYE3 2 + 56 + 4 + 56 + 4 + 56 + 4 + 56
uint16_t btnDefNormal[12][4] = {{ B0 , E0 , B0 , E0 } , // each line contains the Xmin, Xmax, Ymin , Ymax of one button.
{ B1 , E1 , B0 , E0 } ,
{ B2 , E2 , B0 , E0 } ,
{ B3 , E3 , B0 , E0 } ,
{ B0 , E0 , B1 , E1 } ,
{ B1 , E1 , B1 , E1 } ,
{ B2 , E2 , B1 , E1 } ,
{ B3 , E3 , B1 , E1 } ,
{ B0 , E0 , B2 , E2 } ,
{ B1 , E1 , B2 , E2 } ,
{ B2 , E2 , B2 , E2 } ,
{ B3 , E3 , B2 , E2 } } ;
uint16_t btnDefFiles[12][4] = {{ FXB , FXE , FYB0 , FYE0 } , // each line contains the Xmin, Xmax, Ymin , Ymax of one button.
{ FXB , FXE , FYB1 , FYE1 } ,
{ FXB , FXE , FYB2 , FYE2 } ,
{ FXB , FXE , FYB3 , FYE3 } ,
{ B2 , E2 , B0 , E0 } ,
{ B3 , E3 , B0 , E0 } ,
{ B2 , E2 , B1 , E1 } ,
{ B3 , E3 , B1 , E1 } ,
{ B2 , E2 , B2 , E2 } ,
{ B3 , E3 , B2 , E2 } ,
{ 0 , 0 , 0 , 0 } ,
{ 0 , 0 , 0 , 0 } } ;
// rempli le paramétrage des boutons de chaque page
void fillMPage (uint8_t _page , uint8_t _btnPos , uint8_t _boutons, uint8_t _actions , void (*_pfNext)(uint8_t) , uint8_t _parameters ) {
mPages[_page].boutons[_btnPos] = _boutons ;
mPages[_page].actions[_btnPos] = _actions ;
mPages[_page].pfNext[_btnPos] = _pfNext ;
mPages[_page].parameters[_btnPos] = _parameters ;
}
void initButtons() {
mButton[_SETUP].pLabel = __SETUP ;
mButton[_PRINT].pLabel = __PRINT ;
mButton[_HOME].pLabel = __HOME ;
mButton[_UNLOCK].pLabel = __UNLOCK ;
mButton[_RESET].pLabel = __RESET ;
mButton[_SD].pLabel = __SD ;
mButton[_USB_GRBL].pLabel = __USB_GRBL ;
mButton[_TELNET_GRBL].pLabel = __TELNET_GRBL ;
mButton[_PAUSE].pLabel = __PAUSE ;
mButton[_CANCEL].pLabel = __CANCEL ;
mButton[_INFO].pLabel = __INFO ;
mButton[_CMD].pLabel = __CMD ;
mButton[_MOVE].pLabel = __MOVE ;
mButton[_RESUME].pLabel = __RESUME ;
mButton[_STOP_PC_GRBL].pLabel = __STOP_PC_GRBL ;
mButton[_XP].pLabel = "X+" ;
mButton[_XM].pLabel = "X-" ;
mButton[_YP].pLabel = "Y+" ;
mButton[_YM].pLabel = "Y-" ;
mButton[_ZP].pLabel = "Z+" ;
mButton[_ZM].pLabel = "Z-" ;
mButton[_AP].pLabel = "A+" ;
mButton[_AM].pLabel = "A-" ;
mButton[_D_AUTO].pLabel = __D_AUTO ;
mButton[_D0_01].pLabel = "0.01" ;
mButton[_D0_1].pLabel = "0.1" ;
mButton[_D1].pLabel = "1" ;
mButton[_D10].pLabel = "10" ;
mButton[_SET_WCS].pLabel = __SET_WCS ;
mButton[_SETX].pLabel = __SETX ;
mButton[_SETY].pLabel = __SETY ;
mButton[_SETZ].pLabel = __SETZ ;
mButton[_SETA].pLabel = __SETA ;
mButton[_SETXYZ].pLabel = __SETXYZ ;
mButton[_SETXYZA].pLabel = __SETXYZA ;
mButton[_TOOL].pLabel = __TOOL ;
mButton[_SET_CHANGE].pLabel = __SET_CHANGE ;
mButton[_SET_PROBE].pLabel = __SET_PROBE ;
mButton[_SET_CAL].pLabel = __SET_CAL ;
mButton[_GO_CHANGE].pLabel = __GO_CHANGE ;
mButton[_GO_PROBE].pLabel = __GO_PROBE ;
mButton[_BACK].pLabel = __BACK ;
mButton[_LEFT].pLabel = __LEFT ;
mButton[_RIGHT].pLabel = __RIGHT ;
mButton[_UP].pLabel = __UP ;
mButton[_CMD1].pLabel = &cmdName[0][0] ;
mButton[_CMD2].pLabel = &cmdName[1][0] ;
mButton[_CMD3].pLabel = &cmdName[2][0] ;
mButton[_CMD4].pLabel = &cmdName[3][0] ;
mButton[_CMD5].pLabel = &cmdName[4][0] ;
mButton[_CMD6].pLabel = &cmdName[5][0] ;
mButton[_CMD7].pLabel = &cmdName[6][0] ;
mButton[_CMD8].pLabel = &cmdName[7][0] ;
mButton[_CMD9].pLabel = &cmdName[8][0] ;
mButton[_CMD10].pLabel = &cmdName[9][0] ;
mButton[_CMD11].pLabel = &cmdName[10][0] ;
mButton[_MORE_PAUSE].pLabel = __MORE_PAUSE ;
mButton[_FILE0].pLabel = fileNames[0] ; // labels are defined during execution in a table
mButton[_FILE1].pLabel = fileNames[1] ;
mButton[_FILE2].pLabel = fileNames[2] ;
mButton[_FILE3].pLabel = fileNames[3] ;
mButton[_MASKED1].pLabel = "" ; // this is a hidden button; so must be empty
mButton[_PG_PREV].pLabel = __PREV ;
mButton[_PG_NEXT].pLabel = __NEXT ;
mButton[_SD_SHOW].pLabel = __SD_SHOW ;
mButton[_OVERWRITE].pLabel = "" ; // this is a hidden button; so must be empty
mButton[_OVER_SWITCH_TO_FEEDRATE].pLabel = __OVER_SWITCH_TO_FEEDRATE ;
mButton[_OVER_SWITCH_TO_SPINDLE].pLabel = __OVER_SWITCH_TO_SPINDLE ;
mButton[_OVER_10P].pLabel = __OVER_10P ;
mButton[_OVER_10M].pLabel = __OVER_10M ;
mButton[_OVER_1P].pLabel = __OVER_1P ;
mButton[_OVER_1M].pLabel = __OVER_1M ;
mButton[_OVER_100].pLabel = __OVER_100 ;
mPages[_P_INFO].titel = "Info" ;
mPages[_P_INFO].pfBase = fInfoBase ;
fillMPage (_P_INFO , 0 , _MASKED1 , _JUST_PRESSED , fGoToPage , _P_LOG ) ; // this button is masked but clicking on the zone call another screen
fillMPage (_P_INFO , 3 , _OVERWRITE , _JUST_PRESSED , fGoToPage , _P_OVERWRITE ) ; // this button is masked but clicking on the zone call another screen
fillMPage (_P_INFO , 7 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP) ; // those buttons are changed dynamically based on status (no print, ...)
fillMPage (_P_INFO , 11 , _PRINT , _JUST_PRESSED , fGoToPage , _P_PRINT) ; // those buttons are changed dynamically based on status (no print, ...)
mPages[_P_SETUP].titel = "Setup" ;
mPages[_P_SETUP].pfBase = fSetupBase ;
fillMPage (_P_SETUP , 4 , _HOME , _JUST_PRESSED , fHome , 0) ;
fillMPage (_P_SETUP , 5 , _UNLOCK , _JUST_PRESSED , fUnlock , 0) ;
fillMPage (_P_SETUP , 6 , _RESET , _JUST_PRESSED , fReset , 0) ;
fillMPage (_P_SETUP , 7 , _CMD , _JUST_PRESSED , fGoToPage , _P_CMD ) ;
fillMPage (_P_SETUP , 8 , _MOVE , _JUST_PRESSED , fGoToPage , _P_MOVE ) ;
fillMPage (_P_SETUP , 9 , _SET_WCS , _JUST_PRESSED , fGoToPage , _P_SETXYZ ) ;
fillMPage (_P_SETUP , 10 , _TOOL , _JUST_PRESSED , fGoToPage , _P_TOOL ) ;
fillMPage (_P_SETUP , 11 , _INFO , _JUST_PRESSED , fGoToPageAndClearMsg , _P_INFO) ;
mPages[_P_PRINT].titel = "Print" ;
mPages[_P_PRINT].pfBase = fNoBase ;
fillMPage (_P_PRINT , 4 , _SD , _JUST_PRESSED , fGoToPage , _P_SD) ;
fillMPage (_P_PRINT , 5 , _USB_GRBL , _JUST_PRESSED , fStartUsb , 0) ;
fillMPage (_P_PRINT , 6 , _TELNET_GRBL , _JUST_PRESSED , fStartTelnet , 0) ;
fillMPage (_P_PRINT , 7 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP) ;
fillMPage (_P_PRINT , 10 , _CMD , _JUST_PRESSED , fGoToPage , _P_CMD ) ;
fillMPage (_P_PRINT , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO) ;
mPages[_P_PAUSE].titel = "Paused" ;
mPages[_P_PAUSE].pfBase = fNoBase ;
fillMPage (_P_PAUSE , 4 , _CANCEL , _JUST_PRESSED , fCancel , 0) ;
fillMPage (_P_PAUSE , 5 , _RESUME , _JUST_PRESSED , fResume , 0) ;
fillMPage (_P_PAUSE , 6 , _SD_SHOW , _JUST_PRESSED , fGoToPage , _P_SD_SHOW ) ;
fillMPage (_P_PAUSE , 7 , _MOVE , _JUST_PRESSED , fGoToPage , _P_MOVE) ;
fillMPage (_P_PAUSE , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO) ;
mPages[_P_MOVE].titel = "Move" ;
mPages[_P_MOVE].pfBase = fMoveBase ;
#ifdef AA_AXIS
fillMPage (_P_MOVE , 0 , _XM , _JUST_LONG_PRESSED_RELEASED , fMove , _XM) ;
fillMPage (_P_MOVE , 1 , _YP , _JUST_LONG_PRESSED_RELEASED , fMove , _YP) ;
fillMPage (_P_MOVE , 2 , _XP , _JUST_LONG_PRESSED_RELEASED , fMove , _XP) ;
fillMPage (_P_MOVE , 3 , _ZP , _JUST_LONG_PRESSED_RELEASED , fMove , _ZP) ;
fillMPage (_P_MOVE , 4 , _AM , _JUST_LONG_PRESSED_RELEASED , fMove , _AM) ;
fillMPage (_P_MOVE , 5 , _YM , _JUST_LONG_PRESSED_RELEASED , fMove , _YM) ;
fillMPage (_P_MOVE , 6 , _AP , _JUST_LONG_PRESSED_RELEASED , fMove , _AP) ;
fillMPage (_P_MOVE , 7 , _ZM , _JUST_LONG_PRESSED_RELEASED , fMove , _ZM) ;
#else
fillMPage (_P_MOVE , 1 , _YP , _JUST_LONG_PRESSED_RELEASED , fMove , _YP) ;
fillMPage (_P_MOVE , 3 , _ZP , _JUST_LONG_PRESSED_RELEASED , fMove , _ZP) ;
fillMPage (_P_MOVE , 5 , _YM , _JUST_LONG_PRESSED_RELEASED , fMove , _YM) ;
fillMPage (_P_MOVE , 7 , _ZM , _JUST_LONG_PRESSED_RELEASED , fMove , _ZM) ;
fillMPage (_P_MOVE , 8 , _XM , _JUST_LONG_PRESSED_RELEASED , fMove , _XM) ;
fillMPage (_P_MOVE , 10 , _XP , _JUST_LONG_PRESSED_RELEASED , fMove , _XP) ;
#endif
fillMPage (_P_MOVE , POS_OF_MOVE_D_AUTO , _D_AUTO , _JUST_PRESSED , fDist, _D_AUTO) ; // -1 because range here is 0...11
fillMPage (_P_MOVE , 11 , _BACK , _JUST_PRESSED , fGoBack , 0) ;
mPages[_P_SETXYZ].titel = "Set X, Y, Z to 0" ;
mPages[_P_SETXYZ].pfBase = fSetXYZBase ;
fillMPage (_P_SETXYZ , 4 , _SETX , _JUST_PRESSED , fSetXYZ , _SETX) ;
fillMPage (_P_SETXYZ , 5 , _SETY , _JUST_PRESSED , fSetXYZ , _SETY) ;
fillMPage (_P_SETXYZ , 6 , _SETZ, _JUST_PRESSED , fSetXYZ , _SETZ) ;
#ifdef AA_AXIS
fillMPage (_P_SETXYZ , 7 , _SETA, _JUST_PRESSED , fSetXYZ , _SETA) ;
fillMPage (_P_SETXYZ , 8 , _SETXYZ , _JUST_PRESSED , fSetXYZ , _SETXYZ) ;
fillMPage (_P_SETXYZ , 9 , _SETXYZA , _JUST_PRESSED , fSetXYZ , _SETXYZA) ;
#else
fillMPage (_P_SETXYZ , 8 , _SETXYZ , _JUST_PRESSED , fSetXYZ , _SETXYZ) ;
#endif
fillMPage (_P_SETXYZ , 10 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP ) ;
fillMPage (_P_SETXYZ , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
mPages[_P_SD].titel = "Select a file on Sd card" ; // this screen has only 10 buttons instead of 12
mPages[_P_SD].pfBase = fSdBase ; // cette fonction doit remplir les 4 premiers boutons en fonction des fichiers disponibles
fillMPage (_P_SD , 6 , _PG_PREV , _JUST_PRESSED , fSdMove , _PG_PREV ) ;
fillMPage (_P_SD , 7 , _UP , _JUST_PRESSED , fSdMove , _UP ) ;
fillMPage (_P_SD , 8 , _PG_NEXT , _JUST_PRESSED , fSdMove , _PG_NEXT) ;
fillMPage (_P_SD , 9 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
mPages[_P_CMD].titel = "Select a command" ;
mPages[_P_CMD].pfBase = fCmdBase ; //
if (cmdName[0][0] ) fillMPage (_P_CMD , 0 , _CMD1 , _JUST_PRESSED , fCmd , _CMD1) ; // le paramètre contient le n° du bouton
if (cmdName[1][0] ) fillMPage (_P_CMD , 1 , _CMD2 , _JUST_PRESSED , fCmd , _CMD2) ; // le paramètre contient le n° du bouton
if (cmdName[2][0] ) fillMPage (_P_CMD , 2 , _CMD3 , _JUST_PRESSED , fCmd , _CMD3) ; // le paramètre contient le n° du bouton
if (cmdName[3][0] ) fillMPage (_P_CMD , 3 , _CMD4 , _JUST_PRESSED , fCmd , _CMD4) ; // le paramètre contient le n° du bouton
if (cmdName[4][0] ) fillMPage (_P_CMD , 4 , _CMD5 , _JUST_PRESSED , fCmd , _CMD5) ; // le paramètre contient le n° du bouton
if (cmdName[5][0] ) fillMPage (_P_CMD , 5 , _CMD6 , _JUST_PRESSED , fCmd , _CMD6) ; // le paramètre contient le n° du bouton
if (cmdName[6][0] ) fillMPage (_P_CMD , 6 , _CMD7 , _JUST_PRESSED , fCmd , _CMD7) ; // le paramètre contient le n° du bouton
if (cmdName[7][0] ) fillMPage (_P_CMD , 7 , _CMD8 , _JUST_PRESSED , fCmd , _CMD8) ; // le paramètre contient le n° du bouton
if (cmdName[8][0] ) fillMPage (_P_CMD , 8 , _CMD9 , _JUST_PRESSED , fCmd , _CMD9) ; // le paramètre contient le n° du bouton
if (cmdName[9][0] ) fillMPage (_P_CMD , 9 , _CMD10 , _JUST_PRESSED , fCmd , _CMD10) ; // le paramètre contient le n° du bouton
if (cmdName[10][0] ) fillMPage (_P_CMD , 10 , _CMD11 , _JUST_PRESSED , fCmd , _CMD11) ; // le paramètre contient le n° du bouton
fillMPage (_P_CMD , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
mPages[_P_LOG].titel = "Log" ;
mPages[_P_LOG].pfBase = fLogBase ;
fillMPage (_P_LOG , POS_OF_LOG_PG_PREV , _PG_PREV , _JUST_PRESSED , fLogPrev , 0) ;
fillMPage (_P_LOG , POS_OF_LOG_PG_NEXT , _PG_NEXT , _JUST_PRESSED , fLogNext , 0) ;
fillMPage (_P_LOG , 11 , _BACK , _JUST_PRESSED , fGoBack , 0) ;
mPages[_P_TOOL].titel = "Change tool" ;
mPages[_P_TOOL].pfBase = fToolBase ;
fillMPage (_P_TOOL , 4 , _SETXYZ , _JUST_PRESSED , fSetXYZ , _SETXYZ) ;
fillMPage (_P_TOOL , 5 , _SET_CAL , _JUST_PRESSED , fSetXYZ , _SET_CAL) ;
fillMPage (_P_TOOL , 6 , _GO_CHANGE , _JUST_PRESSED , fSetXYZ , _GO_CHANGE) ;
fillMPage (_P_TOOL , 7 , _GO_PROBE , _JUST_PRESSED , fSetXYZ , _GO_PROBE) ;
fillMPage (_P_TOOL , 8 , _SET_CHANGE , _JUST_PRESSED , fSetXYZ , _SET_CHANGE ) ;
fillMPage (_P_TOOL , 9 , _SET_PROBE , _JUST_PRESSED , fSetXYZ , _SET_PROBE) ;
fillMPage (_P_TOOL , 10 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP ) ;
fillMPage (_P_TOOL , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
mPages[_P_SD_SHOW].titel = "Show Sd" ;
mPages[_P_SD_SHOW].pfBase = fSdShowBase ;
fillMPage (_P_SD_SHOW , POS_OF_SD_SHOW_PG_PREV , _PG_PREV , _JUST_PRESSED , fSdShowPrev , 0) ;
fillMPage (_P_SD_SHOW , POS_OF_SD_SHOW_PG_NEXT , _PG_NEXT , _JUST_PRESSED , fSdShowNext , 0) ;
fillMPage (_P_SD_SHOW , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
mPages[_P_OVERWRITE].titel = "Change tool" ;
mPages[_P_OVERWRITE].pfBase = fOverBase ;
fillMPage (_P_OVERWRITE , POS_OF_OVERWRITE_OVERWRITE , _OVER_SWITCH_TO_SPINDLE , _JUST_PRESSED , fOverSwitch , _OVER_SWITCH_TO_SPINDLE ) ;
fillMPage (_P_OVERWRITE , 4 , _OVER_10M , _JUST_PRESSED , fOverModify , _OVER_10M) ;
fillMPage (_P_OVERWRITE , 5 , _OVER_1M , _JUST_PRESSED , fOverModify , _OVER_1M) ;
fillMPage (_P_OVERWRITE , 6 , _OVER_1P , _JUST_PRESSED , fOverModify , _OVER_1P) ;
fillMPage (_P_OVERWRITE , 7 , _OVER_10P , _JUST_PRESSED , fOverModify , _OVER_10P) ;
fillMPage (_P_OVERWRITE , 10 , _OVER_100 , _JUST_PRESSED , fOverModify , _OVER_100) ;
fillMPage (_P_OVERWRITE , 11 , _INFO , _JUST_PRESSED , fGoToPage , _P_INFO ) ;
} // end of init
void tftInit() {
tft.init() ; // Initialise l'écran avec les pins définies dans setup (par exemple)
// #define TFT_MISO 19
//#define TFT_MOSI 23
//#define TFT_SCLK 18
//#define TFT_CS 15 // Chip select control pin
//#define TFT_DC 2 // Data Command control pin (to connect to RS pin of LDC probably)
//#define TFT_RST 4 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
//Cette fonction met les pins en mode input/output; elle envoie aussi les commandes d'initialisation
// Set the rotation before we calibrate
tft.setRotation(1); // normally, this is already done in tft.int() but it is not clear how is rotation set (probably 0); so it can be usefull to change it here
touch_calibrate(); // call screen calibration
//tft.printCalibration() ; // print calibration data (print on Serial port the calibration data ; only for debug
clearScreen(); // clear screen
}
boolean convertPosToXY( uint8_t pos , int32_t *_x, int32_t *_y , uint16_t btnDef[12][4]){
if (pos > 0 && pos < 13 ) { // accept only value from 1 to 12
*_x = btnDef[pos-1][0];
*_y = btnDef[pos-1][2];
return true ;
} else {
return false ;
}
} ;
uint8_t convertBtnPosToBtnIdx( uint8_t page , uint8_t btn ) { // retrieve the type of button based on the position on TFT (in range 1...12)
return mPages[page].boutons[btn - 1] ;
}
void drawAllButtons(){
uint8_t i = 0;
uint8_t btnIdx;
while ( i < 12 ) { // pour chacun des 12 boutons possibles
btnIdx = mPages[currentPage].boutons[i] ;
//if ( btnIdx && btnIdx != _MASKED1 ) { // si un n° de bouton est précisé, l'affiche sauf si c'est un bouton masqué (ex: _MASKED1)
if ( btnIdx && mButton[btnIdx].pLabel[0] != 0 ) { // si un n° de bouton est précisé, l'affiche sauf si c'est un bouton masqué (dont le label est vide)
//Serial.print("va afficher le bouton ") ; Serial.println( i) ;
//Serial.print("bouton code= " ) ; Serial.println( mPages[currentPage].boutons[i] ) ;
mButtonDraw( i + 1 , btnIdx ) ; // affiche le bouton
}
i++ ;
}
}
void mButtonDraw(uint8_t pos , uint8_t btnIdx) { // draw a button at position (from 1 to 12) ; btnIdx = n° du bouton à afficher
// si le texte a moins de 5 char, affiche 1 ligne en size 2
// 9 1 1
// 17 2 1 ; le . sert de séparateur pour répartir les noms de fichier sur 2 lignes si possible
// si le btnIdx est un bouton masqué (ex _MASKED1), alors on n'affiche rien
int32_t _xl , _yl ;
int32_t _w = 76 ;
int32_t _h = 76 ;
int32_t fill = BUTTON_BACKGROUND ;
int32_t outline = BUTTON_BORDER_NOT_PRESSED ;
int32_t text = BUTTON_TEXT ;
const char * pbtnLabel ;
boolean isFileName = false ;
//int32_t y1 ;
//char tempText[9] ; // keep max 8 char + /0
char * pExtensionChar;
char * pch;
uint8_t numbChar = 8 ;
char tempLabel[50] ;
char fileExtension[14] = "." ;
char fileNameReduced[21] = "0123456789012345..." ;
boolean convertPosIsTrue ;
pbtnLabel = mButton[btnIdx].pLabel ;
if ( currentPage == _P_SD && btnIdx >= _FILE0 && btnIdx <= _FILE3 ) { // if it is a button for a file name
_w = 74+6+80 ;
_h = 56 ;
isFileName = true ;
if ( *mButton[btnIdx].pLabel == '/' ) { // when first char is "/", invert the color and skip the first char
fill = BUTTON_BORDER_NOT_PRESSED ;
text = BUTTON_BACKGROUND ;
pbtnLabel++ ;
}
// remove extension if any and put it in fileExtension[]
pExtensionChar = strrchr( pbtnLabel , '.' ); // search for first . from the right
if ( pExtensionChar ) {
*pExtensionChar = 0 ; // if any, replace . by 0 to truncate the string
memccpy( fileExtension +1 , pExtensionChar + 1 , '\0' , 12) ; // copy max 12 char
fileExtension[12] = 0 ; // put a 0 as last Char for security
} else {
fileExtension[0] = 0 ; // reduce size of extension to 0
}
memccpy( fileNameReduced , pbtnLabel , '\0' , 16) ; // copy max 16 char
}
// Serial.print("pos="); Serial.print( pos ) ; Serial.print(" btnIdx="); Serial.print( btnIdx ) ;
// Serial.print("first char of btnName ="); Serial.println( *pbtnLabel ) ;
if ( currentPage == _P_SD ) {
convertPosIsTrue = convertPosToXY( pos , &_xl, &_yl , btnDefFiles ) ; // Convert position index to colonne and line (top left corner)
} else {
convertPosIsTrue = convertPosToXY( pos , &_xl, &_yl , btnDefNormal ) ; // Convert position index to colonne and line (top left corner)
}
if ( convertPosIsTrue ) {
tft.setTextColor(text);
tft.setTextSize(1);
//tft.setTextFont(2);
uint8_t r = min(_w, _h) / 4; // Corner radius
tft.fillRoundRect( _xl , _yl , _w, _h, r, fill);
tft.drawRoundRect( _xl, _yl , _w, _h, r, outline);
uint8_t tempdatum = tft.getTextDatum();
tft.setTextDatum(MC_DATUM);
if (isFileName ) { // print filename in a special way (larger button)
tft.setTextDatum(BC_DATUM);
tft.setFreeFont(LABELS9_FONT);
tft.drawString( fileNameReduced , _xl + (_w/2), _yl + (_h/2));
tft.setTextDatum(TC_DATUM);
tft.drawString( fileExtension , _xl + (_w/2), _yl + (_h/2));
tft.setTextDatum(tempdatum);
return ;
}
memccpy( tempLabel , pbtnLabel , '\0' , 16); // copy max 16 char
pch = strchr(tempLabel , '*') ; //check for a separator in the name in order to split on 2 lines
if ( pch!=NULL ) {
numbChar = pch - tempLabel ;
if (numbChar <= 8 ) {
tempLabel[numbChar] = 0 ; // replace * by end of string
tft.setFreeFont(LABELS9_FONT);
//tft.setTextFont(2);
tft.drawString( &tempLabel[0] , _xl + (_w/2), _yl + (_h/3)); // affiche max 8 char sur la première ligne
tempLabel[numbChar + 9] = 0 ; // set a 0 to avoid that second part of name exceed 8 char
tft.drawString( &tempLabel[numbChar + 1] , _xl + (_w/2), _yl + 2 * (_h/3)); // affiche la seconde ligne avec max 8 char
return;
}
}
// here it is asked to split in 2 lines (or the split was asked after the 8th char)
// we can still split if there is more than 8 char; if there is less than 4, we use another font
tft.setFreeFont(LABELS9_FONT);
uint8_t txtLength = strlen( pbtnLabel ) ; // get the length of text to be displayed
if ( txtLength <= 4 ) { // imprime 1 ligne au milieu en grand
tft.setFreeFont(LABELS12_FONT);
tft.drawString( pbtnLabel , _xl + (_w/2), _yl + (_h/2));
} else if ( txtLength <= 8 ) { // imprime 1 ligne au milieu
tft.drawString( pbtnLabel , _xl + (_w/2), _yl + (_h/2));
} else {
if( memccpy( tempLabel , pbtnLabel , '\0' , 16) == NULL ) tempLabel[16] = 0 ; // copy the label in tmp
pch = strchr(tempLabel , '.') ;
if ( pch!=NULL ) {
numbChar = pch - tempLabel ;
if (numbChar >= 8 ) numbChar = 8 ;
}
uint8_t tempChar = tempLabel[numbChar] ; // sauvegarde le charactère '.' ou un autre
// Serial.print("numChar="); Serial.print(numbChar) ;
// Serial.print("txtLenth="); Serial.print(txtLength) ;
// Serial.print("tempChar="); Serial.print(tempChar) ; Serial.print(" , "); Serial.print(tempChar , HEX) ;
tempLabel[numbChar] = 0 ; // put a 0 instead
tft.drawString( tempLabel , _xl + (_w/2), _yl + (_h/3)); // affiche max 7 char sur la première ligne (ou la partie avant .)
tempLabel[numbChar] = tempChar ; // restore the char
if ( (txtLength - numbChar) >= 8 ) {
tempLabel[numbChar + numbChar + 9 ] = 0 ; // put a 0 to avoid a too long string
}
tft.drawString( &tempLabel[numbChar] , _xl + (_w/2), _yl + 2 * (_h/3)); // affiche la seconde ligne avec max 8 char
}
tft.setTextDatum(tempdatum);
}
}
void mButtonBorder(uint8_t pos , uint16_t outline) { // draw the border of a button at position (from 1 to 12)
int32_t _xl , _yl ;
int32_t _w = 76 ;
int32_t _h = 76 ;
if (currentPage == _P_SD ) {
convertPosToXY( pos , &_xl, &_yl , btnDefFiles) ;
if ( pos <= 4) { // if it is a button for a file name
_w = 74+6+80 ;
_h = 56 ;
}
} else {
convertPosToXY( pos , &_xl, &_yl , btnDefNormal) ;
}
uint8_t r = min(_w, _h) / 4; // Corner radius
tft.drawRoundRect( _xl, _yl , _w, _h, r, outline);
}
uint8_t getButton( int16_t x, int16_t y , uint16_t btnDef[12][4]) { // convert x y into a button if possible
// return 1 à 12 suivant le bouton; return 0 if no button
if ( y > 240 || x > 320 ) return 0 ;
uint8_t i = 12 ;
while ( i ) {
i--;
if ( x > btnDef[i][0] && x < btnDef[i][1] && y > btnDef[i][2] && y < btnDef[i][3] ) return i+1 ;
}
return 0 ;
}
//********************************************************************************
// look if touch screen has been pressed/released
// if pressed, convert the x,y position into a button number (from 1 ...12)
// compare to previous state; if previous state is the same, then take new state into account
// fill justPressedBtn, justReleasedBtn, currentBtn , longPressedBtn , beginChangeBtnMillis
//*********************************************************************************
#define WAIT_TIME_BETWEEN_TOUCH 50
void updateBtnState( void) {
int16_t x , y ;
static uint32_t nextMillis ;
static uint8_t prevBt0 ;
uint32_t touchMillis = millis();
//uint8_t bt ;
uint8_t bt0 = 0; // bt0 is the button nr based on the touched position (0 if not touched, or if touched is not at a valid position, otherwise 1...12)
boolean touchPressed ;
justPressedBtn = 0 ;
justReleasedBtn = 0 ;
if ( touchMillis > nextMillis ) { // s'il n'y a pas assez longtemps depuis la dernière lecture, on fait juste un reset des justPressedBtn et justReleasedBtn
touchPressed = tft.getTouch( &x, &y, 600); // read the touch screen; // later perhaps exit immediately if IrqPin is HIGH (not touched)
// false = key not pressed
nextMillis = touchMillis + WAIT_TIME_BETWEEN_TOUCH ;
if ( touchPressed) {
if ( currentPage == _P_SD ) { // conversion depend on current screen.
bt0 = getButton(x , y , btnDefFiles) ; // convertit x, y en n° de bouton ; retourne 0 si en dehors de la zone des boutons; sinon retourne 1 à 12
} else {
bt0 = getButton(x , y , btnDefNormal) ; // convertit x, y en n° de bouton ; retourne 0 si en dehors de la zone des boutons; sinon retourne 1 à 12
}
// Serial.print("x=") ; Serial.print(x) ; Serial.print( " ," ) ; Serial.print( y) ; Serial.print( " ," ) ; Serial.println(bt0) ;
} else {
// Serial.print("!") ;
}
if ( prevBt0 != bt0 ) { // compare bt0 with previous,
prevBt0 = bt0 ; // if different, only save the new state but do not handel
} else { // traite uniquement si 2 fois le même bouton consécutivement
if ( currentBtn != bt0 ) { // en cas de changement, active justPressedBtn et justReleasedBtn et reset waitReleased
// Serial.print(" x=") ; Serial.print(x) ; Serial.print(" y=") ; Serial.print(y) ; Serial.print(" bt=") ; Serial.println(bt0) ;
justPressedBtn = bt0 ;
justReleasedBtn = currentBtn ;
currentBtn = bt0 ;
waitReleased = false ;
beginChangeBtnMillis = touchMillis ; // save the timestamp when bt has just changed
longPressedBtn = 0 ; // reset long press
} else { // same button pressed
if ( ( touchMillis - beginChangeBtnMillis ) > 500 ) {
longPressedBtn = currentBtn ; // if the same button is pressed for a long time, update longPressedBtn (can be 0)
}
}
}
}
//if (justPressedBtn){
// Serial.print( "just pressed") ; Serial.println( justPressedBtn) ;
//}
//if (justReleasedBtn){
// Serial.print( "just released") ; Serial.println( justReleasedBtn) ;
//}
}
void drawUpdatedBtn( ) { // update the color of the buttons on a page (based on currentPage, justPressedBtn , justReleasedBtn, longPressedBtn)
if ( justReleasedBtn && mPages[currentPage].boutons[justReleasedBtn - 1] &&
( mButton[mPages[currentPage].boutons[justReleasedBtn - 1]].pLabel[0] != 0 ) ) { // si justReleased contient un bouton et que ce bouton est affiché sur la page
mButtonBorder( justReleasedBtn , BUTTON_BORDER_NOT_PRESSED ) ; // affiche le bord du bouton dans sa couleur normale
}
if ( justPressedBtn && mPages[currentPage].boutons[justPressedBtn - 1] && ( mButton[mPages[currentPage].boutons[justPressedBtn - 1]].pLabel[0] != 0 ) ) { // si justPressed contient un bouton et que ce bouton est affiché sur la page
mButtonBorder( justPressedBtn , BUTTON_BORDER_PRESSED ) ; // affiche le bord du bouton dans la couleur de sélection
}
}
void executeMainActionBtn( ) { // find and execute main action for ONE button (if any)
uint8_t actionBtn = 0 ;
if ( ( justPressedBtn ) && ( (mPages[currentPage].actions[justPressedBtn - 1] == _JUST_PRESSED ) \
|| (mPages[currentPage].actions[justPressedBtn - 1 ] == _JUST_LONG_PRESSED ) \
|| (mPages[currentPage].actions[justPressedBtn - 1 ] == _JUST_LONG_PRESSED_RELEASED )) ) {
actionBtn = justPressedBtn ;
} else if ( ( longPressedBtn ) && ( (mPages[currentPage].actions[longPressedBtn - 1 ] == _LONG_PRESSED ) \
|| (mPages[currentPage].actions[longPressedBtn - 1 ] == _JUST_LONG_PRESSED ) \
|| (mPages[currentPage].actions[longPressedBtn - 1 ] == _JUST_LONG_PRESSED_RELEASED )) ) {
actionBtn = longPressedBtn ;
} else if ( ( justReleasedBtn ) && ( ( mPages[currentPage].actions[justReleasedBtn - 1 ] == _JUST_RELEASED ) \
|| ( mPages[currentPage].actions[justReleasedBtn - 1 ] == _JUST_LONG_PRESSED_RELEASED ) ) ) {
actionBtn = justReleasedBtn ;
}
if ( actionBtn) {
(*mPages[currentPage].pfNext[actionBtn - 1 ])(mPages[currentPage].parameters[actionBtn - 1 ]) ;// execute the action with the predefined parameter
}
}
// Basis functions
void blankTft(char * titel, uint16_t x , uint16_t y) { // blank screen and display one titel
clearScreen() ;
//tft.fillScreen( SCREEN_BACKGROUND ) ;
// currently titel is not used so folowwing lines can be skipped; uncomment if titel would be used
//tft.setTextFont( 2 ); // use Font2 = 16 pixel X 7 probably
//tft.setTextColor(TFT_GREEN , TFT_BLACK) ; // when oly 1 parameter, background = fond);
//tft.setTextSize(1) ; // char is 2 X magnified =>
//tft.setTextDatum( TL_DATUM ) ; // align rigth ( option la plus pratique pour les float ou le statut GRBL)
//tft.drawString( titel , x , y ) ; // affiche un texte
//tft.setCursor( x , y + 30 , 2) ; // x, y, font
}
void clearScreen() {
tft.fillScreen( SCREEN_BACKGROUND ) ;
}
void printTft(char * text ) { // print a text on screen
tft.print( text ) ;
}
// affichage d'une nouvelle page = fonction drawPage(pageIdx)
// remplir la page d'une couleur
// exécuter le pointeur correspondant aux paramètres de la page
// 12 fois:
// si le n° du bouton existe
// afficher le bouton
void drawFullPage() {
//uint32_t fullPageMillis = millis();
clearScreen() ;
mPages[currentPage].pfBase(); // exécute la fonction de base prévue pour la page
//Serial.println("drawFullPage: fin de l'appel de la page de base") ;
//Serial.print("drawFullPage takes");Serial.println(millis() - fullPageMillis); // most of time it takes about 100msec to redraw the full screen
drawAllButtons();
}
void drawPartPage() { // update only the data on screen (not the button)
// si la page courante est celle d'info, met à jour certaines données (positions, statut...)
// si la page courante est celle de Move, met à jour certaines données (positions, statut...)
// etc...
if ( currentPage == _P_INFO) {
drawDataOnInfoPage() ;
} else if ( currentPage == _P_MOVE) {
drawWposOnMovePage() ;
} else if (currentPage == _P_SETUP ){
drawDataOnSetupPage() ;
} else if (currentPage == _P_SETXYZ ){
drawDataOnSetXYZPage() ;
} else if (currentPage == _P_TOOL ){
drawDataOnToolPage() ;
} else if (currentPage == _P_OVERWRITE ){
drawDataOnOverwritePage() ;
}
}
//******************************** Fonctions appelées quand on entre dans un écran (appelée via drawFullPage)
// Elles changent seulement les paramètres des boutons.
//************************************************************************************************************
void fInfoBase(void) {
updateButtonsInfoPage() ; // met à jour le set up de la page en fonction du statut d'impression
statusPrintingPrev = 0xFF ; // fill with a dummy value to force a redraw
machineStatus0Prev = 0 ; // fill with a dummy value to force a redraw
lastMsgChanged = true ; // force a redraw of Last Msg
grblLastMessageChanged = true ;
statusTelnetIsConnectedPrev = ! statusTelnetIsConnected ;
newInfoPage = true ;
drawDataOnInfoPage() ; // affiche les données sur la page info
}
void updateButtonsInfoPage (void) { // met à jour le set up de la page en fonction du statut d'impression
switch ( statusPrinting ) {
case PRINTING_STOPPED :
fillMPage (_P_INFO , 7 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP) ;
fillMPage (_P_INFO , 11 , _PRINT , _JUST_PRESSED , fGoToPage , _P_PRINT) ;
break ;
case PRINTING_FROM_SD :
fillMPage (_P_INFO , 7 , _PAUSE , _JUST_PRESSED , fPause , 0 ) ;
fillMPage (_P_INFO , 11 , _CANCEL , _JUST_PRESSED , fCancel , 0 ) ;
break ;
case PRINTING_ERROR : // to do; not clear what we should do
fillMPage (_P_INFO , 7 , _SETUP , _JUST_PRESSED , fGoToPage , _P_SETUP) ;
fillMPage (_P_INFO , 11 , _PRINT , _JUST_PRESSED , fGoToPage , _P_PRINT) ;
break ;
case PRINTING_PAUSED :
fillMPage (_P_INFO , 7 , _RESUME , _JUST_PRESSED , fResume , 0 ) ;
fillMPage (_P_INFO , 11 , _MORE_PAUSE , _JUST_PRESSED , fGoToPage , _P_PAUSE) ;
break ;
case PRINTING_FROM_USB :
fillMPage (_P_INFO , 7 , _STOP_PC_GRBL , _JUST_PRESSED , fStopPc , 0 ) ;
fillMPage (_P_INFO , 11 , _NO_BUTTON , _NO_ACTION , fGoToPage , _P_INFO ) ;
break ;
case PRINTING_FROM_TELNET :
fillMPage (_P_INFO , 7 , _STOP_PC_GRBL , _JUST_PRESSED , fStopPc , 0 ) ;
fillMPage (_P_INFO , 11 ,_NO_BUTTON , _NO_ACTION , fGoToPage, _P_INFO ) ;
break ;
case PRINTING_CMD :
fillMPage (_P_INFO , 7 , _PAUSE , _JUST_PRESSED , fPause , 0 ) ;
fillMPage (_P_INFO , 11 , _CANCEL , _JUST_PRESSED , fCancel , 0 ) ;
break ;
case PRINTING_STRING :
fillMPage (_P_INFO , 7 , _NO_BUTTON , _NO_ACTION , fPause , 0 ) ;
fillMPage (_P_INFO , 11 , _CANCEL , _JUST_PRESSED , fCancel , 0 ) ;
break ;
}
}
void drawDataOnInfoPage() { // to do : affiche les données sur la page d'info
// USB<-->Grbl Idle (or Run, Alarm, ... grbl status)
// So, printing status (blanco, ,SD-->Grbl xxx%, USB<-->Grbl , Pause, Cmd) = printing status
// and GRBL status (or Run, Alarm, ... grbl status)
// Last message (ex : card inserted, card removed, card error, Error: 2
// Wifi icon
// Wpos Mpos
// X xxxxxpos xxxxxpos
// Y yyyyypos yyyyypos
// Z zzzzzpos zzzzzpos
// F 100 S 10000
if ( statusPrintingPrev != statusPrinting ) {
tft.setFreeFont (LABELS12_FONT) ;
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ; // when only 1 parameter, background = fond);
tft.setTextDatum( TL_DATUM ) ; // align Left
tft.setTextPadding (200) ;
tft.drawString ( &printingStatusText[statusPrinting][0] , 5 , 0 ) ;
statusPrintingPrev = statusPrinting ;
}
if ( statusPrinting == PRINTING_FROM_SD ) {
tft.setFreeFont (LABELS12_FONT) ;
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ; // when only 1 parameter, background = fond);
tft.setTextDatum( TR_DATUM ) ;
tft.setTextPadding (40) ;
tft.drawNumber( ( (100 * sdNumberOfCharSent) / sdFileSize), 170 , 0 ) ;
tft.setTextPadding (1) ;
tft.drawString( "%" , 190 , 0 ) ;
// Serial.print( sdNumberOfCharSent ); Serial.print( " / ") ; Serial.println( sdFileSize );
}
if ( machineStatus0Prev != machineStatus[0] || machineStatus[0] == 'A' || machineStatus[0] == 'H') {
drawMachineStatus() ;
machineStatus0Prev = machineStatus[0] ;
}
if ( lastMsgChanged ) {
drawLastMsg() ;
lastMsgChanged = false ;
}
if ( statusTelnetIsConnectedPrev != statusTelnetIsConnected) {
tft.setTextFont( 4); // font 4has been modified to have a wifi Icon for 0X7F
tft.setTextPadding (10) ;
tft.setTextSize(1) ;
if ( statusTelnetIsConnected ) {
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ; // display in green when connected
} else {
tft.setTextColor(SCREEN_ALERT_TEXT , SCREEN_BACKGROUND ) ; // display in red when not connected
}
tft.setTextDatum( TL_DATUM ) ;
tft.drawChar ( 0x7F , 2 , 62 ) ; // char 0x7E in font 4 has been redesigned to get the Wifi logo
statusTelnetIsConnectedPrev = statusTelnetIsConnected ;
}
if ( grblLastMessageChanged ) {
tft.setTextSize(1) ;
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ;
tft.setTextDatum( TL_DATUM ) ; // align Left
tft.setTextPadding (290) ;
tft.setFreeFont(LABELS9_FONT);
if ( strlen( grblLastMessage) > 30 ) {
tft.drawString ( " " , 30 , 62) ; // print space first in the larger font to clear the pixels
tft.setTextFont( 1 );
}
tft.drawString ( &grblLastMessage[0] , 30 , 62) ;
grblLastMessageChanged = false ;
}
tft.setTextDatum( TR_DATUM ) ;
uint16_t line = 90 ;
if (newInfoPage ) {
tft.setTextColor( SCREEN_HEADER_TEXT , SCREEN_BACKGROUND ) ;
tft.setTextFont( 2 );
tft.setTextSize(1) ;
tft.setTextPadding (0) ; // expect to clear 70 pixel when drawing text or
tft.drawString( __WPOS , 70 , line ) ; // affiche un texte
tft.drawString( __MPOS , 190 , line ) ; // affiche un texte
newInfoPage = false ;
}
//tft.setTextSize(2) ;
//tft.setTextFont( 2 );
tft.setFreeFont (LABELS12_FONT) ;
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ;
tft.setTextPadding (120) ; // expect to clear 120 pixel when drawing text or float
uint8_t c1 = 120, c2 = c1 + 120 ;
#ifdef AA_AXIS
uint8_t lineSpacing1 = 24 ;
#else
uint8_t lineSpacing1 = 34 ; // we have more space for 3 axis
#endif
line += 20 ; tft.drawFloat( wposXYZA[0] , 2 , c1 , line ); tft.drawFloat( mposXYZA[0] , 2 , c2 , line );
line += lineSpacing1 ; tft.drawFloat( wposXYZA[1] , 2 , c1 , line ); tft.drawFloat( mposXYZA[1] , 2 , c2 , line );
line += lineSpacing1 ; tft.drawFloat( wposXYZA[2] , 2 , c1 , line ); tft.drawFloat( mposXYZA[2] , 2 , c2 , line );
#ifdef AA_AXIS
line += lineSpacing1 ; tft.drawFloat( wposXYZA[3] , 2 , c1 , line ); tft.drawFloat( mposXYZA[3] , 2 , c2 , line );
#endif
tft.setTextFont( 2 );
tft.setTextSize(1) ;
tft.setTextPadding (0) ;
tft.setTextDatum( TL_DATUM ) ;
tft.setTextColor(SCREEN_HEADER_TEXT , SCREEN_BACKGROUND) ;
line += lineSpacing1 ; tft.drawString(__FEED , 90 , line) ; tft.drawString(__RPM , 205 , line) ;
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND) ;
tft.setTextPadding (80) ;
tft.setTextDatum( TR_DATUM ) ;
tft.drawNumber( (long) feedSpindle[0] , 80 , line) ; // here we could add the Feed rate and the spindle rpm
tft.drawNumber( (long) feedSpindle[1] , 200 , line) ; // here we could add the Feed rate and the spindle rpm
}
void fNoBase(void) {
}
void fSetupBase(void) {
tft.setFreeFont (LABELS9_FONT) ;
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ; // when oly 1 parameter, background = fond);
tft.setTextDatum( TL_DATUM ) ; // align rigth ( option la plus pratique pour les float ou le statut GRBL)
uint8_t line = 2 ;
uint8_t col = 1 ;
char ipBuffer[20] ;
if ( getWifiIp( ipBuffer ) ) {
tft.drawString( "IP:" , col , line );
tft.drawString( ipBuffer , col + 20 , line ); // affiche la valeur avec 3 décimales
} else {
tft.drawString( "No WiFi" , col , line );
}
tft.drawString( ESP32_VERSION, col + 140 , line ) ;
}
void drawDataOnSetupPage() {
drawMachineStatus() ; // draw machine status in the upper right corner
drawLastMsg() ;
}
void fMoveBase(void) {
fillMPage (_P_MOVE , POS_OF_MOVE_D_AUTO , _D_AUTO , _JUST_LONG_PRESSED , fDist , _D_AUTO) ; // reset the button for autochange of speed
wposMoveInitXYZA[0] = wposXYZA[0]; // save the position when entering (so we calculate distance between current pos and init pos on this screen)
wposMoveInitXYZA[1] = wposXYZA[1];
wposMoveInitXYZA[2] = wposXYZA[2];
wposMoveInitXYZA[3] = wposXYZA[3];
drawWposOnMovePage() ;
// multiplier = 0.01 ; // à voir si cela sera encore utilisé (si on met à jour le bouton distance au fur et à mesure, on peut l'utiliser pour calculer
// movePosition = 0 ; à utiliser si on l'affiche
// afficher la position des axes
}
void fSetXYZBase(void) {
drawWposOnSetXYZPage() ;
}
void drawMachineStatus() {
tft.setFreeFont (LABELS12_FONT) ;
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND) ; // when only 1 parameter, background = fond);
tft.setTextDatum( TR_DATUM ) ;
tft.setTextPadding (120) ; // expect to clear 70 pixel when drawing text or
tft.drawString( &machineStatus[0] , 315 , 0 ) ; // affiche le status GRBL (Idle,....)
}
void drawLastMsg() { // affiche le lastMsg en ligne 32
tft.setTextSize(1) ;
tft.setTextColor(lastMsgColor , SCREEN_BACKGROUND ) ; // color is defined in lastMsgColor ; previously SCREEN_ALERT_TEXT
tft.setTextDatum( TL_DATUM ) ; // align Left
tft.setTextPadding (320) ;
tft.setFreeFont(LABELS9_FONT);
if ( strlen( lastMsg) > 30 ) {
tft.drawString ( " " , 2 , 32) ; // print space first in the larger font to clear the pixels
tft.setTextFont( 1 );
}
tft.drawString ( &lastMsg[0] , 2 , 32) ;
}
void drawDataOnSetXYZPage() {
drawWposOnSetXYZPage() ;
}
void drawWposOnSetXYZPage() {
drawMachineStatus() ;
drawLastMsg() ;
tft.setTextFont( 2 ); // use Font2 = 16 pixel X 7 probably
tft.setTextSize(1) ; // char is 2 X magnified =>
tft.setTextColor(SCREEN_NORMAL_TEXT , SCREEN_BACKGROUND ) ; // when oly 1 parameter, background = fond);
tft.setTextDatum( TR_DATUM ) ; // align rigth ( option la plus pratique pour les float ou le statut GRBL)
tft.setTextPadding (80) ; // expect to clear 70 pixel when drawing text or
uint8_t line = 60 ; // was 60 ;
uint8_t col = 60 ;
tft.drawString( __WPOS , col , line);
tft.drawFloat( wposXYZA[0] , 2 , col , line ); // affiche la valeur avec 3 décimales
tft.drawFloat( wposXYZA[1] , 2 , col + 80 , line );
tft.drawFloat( wposXYZA[2] , 2 , col + 160 , line );
#ifdef AA_AXIS
tft.drawFloat( wposXYZA[3] , 2 , col + 240 , line );
#endif
//tft.drawString( __WPOS , col + 240 , line);
}
void fSdBase(void) { // cette fonction doit vérifier que la carte est accessible et actualiser les noms des fichiers disponibles sur la carte sd
if ( ! sdStart() ) { // try to read the SD card; en cas d'erreur, rempli last message et retourne false
currentPage = _P_INFO ; // in case of error, go back to Info
dirLevel = -1 ; // force a reload of sd data next time we goes to SD card menu
fInfoBase () ; // prepare info page (affiche les data et redétermine les boutons à afficher)
} else { // if SD seems OK
sdFileDirCnt = fileCnt(dirLevel) ; // count the number of files in working dir
if (sdFileDirCnt == 0) {
firstFileToDisplay = 0 ;
} else if ( firstFileToDisplay == 0 ) {
firstFileToDisplay = 1 ;
} else if ( (firstFileToDisplay + 4) > sdFileDirCnt ) {
if ( sdFileDirCnt <= 4 ) {
firstFileToDisplay = 1 ; // reset firstFileToDisplay 0 if less than 5 files
} else {
firstFileToDisplay = sdFileDirCnt - 3 ; // keep always 4 files on screen
}
}
//Serial.print("Nbr de fichiers") ; Serial.println(sdFileDirCnt) ;
//Serial.print("firstFileToDisplay") ; Serial.println(firstFileToDisplay) ;
//tft.setTextSize(2) ;
tft.setFreeFont (LABELS9_FONT) ;
tft.setTextSize(1) ;
tft.setTextDatum( TL_DATUM ) ;
tft.setCursor(180 , 20 ) ; // x, y, font
tft.print( firstFileToDisplay ) ;
tft.print( " / " ) ;
tft.print( sdFileDirCnt ) ;
tft.setTextDatum( TR_DATUM ) ;
char dirName[23] ;
if ( ! aDir[dirLevel].getName( dirName , 16 ) ) {
fillMsg (__DIR_NAME_NOT_FOUND );
currentPage = _P_INFO ; // in case of error, go back to Info
dirLevel = -1 ; // force a reload of sd data next time we goes to SD card menu
fInfoBase () ; // fill info page with basis data (affiche les data et redétermine les boutons à afficher sans les afficher)
return ;