-
Notifications
You must be signed in to change notification settings - Fork 2
/
temp_logger.h
1522 lines (1274 loc) · 38.6 KB
/
temp_logger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
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
#ifndef temp_logger_h
#define temp_logger_h
// #include <config.h>
// #ifdef ESP32
// #include <analogWrite.h>
// #endif
#include <buttons.h>
#include <i2c_fans.h>
// #include <serialcmd.h>
// #include <telnet_cmd.h>
#include <ota.h>
#include <wifi_funcs.h>
// #include <motor.h>
#include <ssr.h>
// #include <max31855.h>
// #include <adafruit_tft.h>
#include <tft_spi_shared.h>
#include <tft_graph.h>
#include <io_utils.h>
#include <time_funcs.h>
#include <pid.h>
// ota bargraph
#include <BarGraph.h>
#define SCALECOLOR 0xFFFF
BarGraph bar0;
#define TFTROT 3
#define USENEOIND // use neopixel indicator
#ifdef USENEOIND
#ifdef ESP32
#define NEOINDPIN 19
#else
#define NEOINDPIN 2
#endif
#include <neoindicator.h>
#include <neo_ind_accent.h>
#endif
#define USENTC // use thermistor
#ifdef USENTC
#include <ntc_multi.h>
#endif
// symbol glyph font for icons
#include "SymbolMono18pt7b.h"
#define AA_FONT_SMALL &SymbolMono18pt7b
#define GFXFF 1
// #include "/Users/shawn/.platformio/lib/TFT_eSPI_ID1559/Fonts/GFXFF/FreeMono24pt7b.h"
// #include "FreeMono24pt7b.h"
#include "Free_Fonts.h"
#include "NotoSansBold15.h"
#include "NotoSansBold36.h"
#include "NotoSansMonoSCB20.h"
// The font names are arrays references, thus must NOT be in quotes ""
#define AA_FONT_MED NotoSansBold15
#define AA_FONT_LARGE NotoSansBold36
#define AA_FONT_MONO NotoSansMonoSCB20 // NotoSansMono-SemiCondensedBold 20pt
#define GFXX18pt &FreeSans18pt7b
// #define GFXX18pt &FreeMono18pt7b
int fpsmicros = 0;
bool USEWIFI = true; // enabled wifi, NOT connect wifi
Average<float> fps(10); // init stats for avg (samples)
// ICONS
// states for fan animations, only 2 state atm
bool animStateA = true;
bool animStateB = false;
bool testIcons = false; // set icons states randomly/Demo mode
unsigned long stateStartMS = 0; // state start timers
// app states
int reflowState = 0; // @todo add enum state, maybe queue
int reflowGraphCounter = 0; // counter period for graphing graphInterval
// temperature vars
int hotTemp = 70; // C burn temperature for HOT indication, 0=disable
int coolTemp = 50; // C safe temperature for HOT indication, 0=disable
int lowTemp = 30; // C of TC warmed than typical CJ
int shutDownTemp = 210; // degrees C
int fanTemp = lowTemp+5; // cooldown complete fan off low temp
bool enableThermalCheck = false;
// strings
// String TITLE = "TITLE";
String TITLE = ""; // Top left
String OPT1 = ""; // BR A
String OPT2 = ""; // BR B
String STATUSLINE = ""; // footer center
bool SCROLL = false; // center is scroll
String DETAILS = ""; // top center
String SUBDATA = ""; // top right
String FOOTERA = ""; // bottom left
float FOOTERA_FLOAT = 0; // bottom left float num
String FOOTERCENTER = ""; // footer center
String FOOTERCENTERL1 = ""; // footer center
String FOOTERCENTERL2 = ""; // footer center
String FOOTERB = ""; // footer center
String FOOTERC = ""; // opt1
String FOOTERD = ""; // opt2
String ERRORSTR = ""; // errors
String TEMPA = "";
String TEMPB = "";
String TEMPC = "";
// DEBUGS
bool DEBUG_POINT = false; // Debug graph point
bool DEBUG_BOX = false; // debug show box bounds
bool DEBUG_DATUM = false; // NI debug show datum origin point
int footerBG = HC2;
// init_graph(320,240-(FOOTERH+ypad),0,HEADERH+ypad);
int SCREENWIDTH = 320; // TFT_HEIGHT
int SCREENHEIGHT = 240; // TFT_WIDTH
int GRAPHHEIGHT = SCREENHEIGHT-(FOOTERH); //padding 200px
int GRAPHWIDTH = SCREENWIDTH;
int graphInterval = 15000; // graph update rate ms
TFT_eSprite spr = TFT_eSprite(&tft);
unsigned int ICONACTIVECOLOR = SILVER;
// FANS
bool coolOnAbort = true; // cool down on abort
bool coolOnBoot = true; // cool down on boot
// DOOR
int doorAbortTime = 50000; // time we expect door full operations to take, will disable door motor after this time
// TASKMANAGER
int doorAbortTaskID = -1; // timer task
int reflowStepTaskID = -1;
int PIDTaskID = -1;
int coolAbortTaskID = -1; // -1 empty
uint16_t NTC_TEMP = 0;
// REFLOW STATES
#define RS_IDLE 0
#define RS_PREHEAT 1 // wait for reflow sync, pid or no pid
#define RS_START 2 // for setup of reflow curve and any pre reflow tasks
#define RS_REFLOW 3 // actual reflow
#define RS_PEAK 4 // run safety, logging for reflow etc,
#define RS_COOL 5 // do cooldown
#define RS_ABORT 999 // special mode for abort, stay in abort until reset!
// TIMING
void stateTimerReset(){
stateStartMS = millis();
}
// return millis since start of state
int getStateDuration(){
return millis()-stateStartMS;
}
void setgraphInterval(int intv){
graphInterval = intv;
}
int tempgraph_H = 50;
void temp_graph_1(){
int ypad = 3; // padding
init_graph(GRAPHWIDTH,tempgraph_H,0,HEADERH+ypad);
}
void temp_graph_2(){
int ypad = tempgraph_H+10; // padding
init_graph(GRAPHWIDTH,tempgraph_H,0,HEADERH+ypad);
}
void temp_graph_3(){
int ypad = (tempgraph_H*2)+17; // padding
init_graph(GRAPHWIDTH,tempgraph_H,0,HEADERH+ypad);
}
void reflow_graph(){
int ypad = 3; // padding
// int FOOTERH = 40;
// int HEADERH = 30;
// init_graph(GRAPHWIDTH,120-(FOOTERH+ypad),0,HEADERH+ypad);
// graphPaste();
setGraphInstance(1);
temp_graph_1();
setGraphInstance(2);
temp_graph_2();
setGraphInstance(3);
temp_graph_3();
}
// int filteredId = -1; // filter graph line indexs -1 off
// fan aliases
// fanA 12v fume exhaust
// fanB 5v cool vent
// set filter id, filters graph only filter line will display
int SetFilterId(int id){
filteredId = id;
}
void SetTempA(String str){
TEMPA = str;
}
void SetTempB(String str){
TEMPB = str;
}
void SetTempC(String str){
TEMPC = str;
}
void SetTitle(String str){
TITLE = str;
}
void SetTitleB(String str){
DETAILS = str;
}
void SetTitleC(String str){
SUBDATA = str;
}
void SetFooterA(String str){
FOOTERA = str;
}
void SetFooterA(float str){
FOOTERA_FLOAT = str;
}
void SetFooterB(String str){
FOOTERCENTER = str;
}
void setFooterBL1(String str){
FOOTERCENTERL1 = str;
}
void SetFooterBSCROLL(String str){
SCROLL = true;
STATUSLINE = str;
}
void SetFooterC(String str){
OPT1 = FOOTERC = str;
}
void SetFooterD(String str){
OPT2 = FOOTERD = str;
}
void setERRORSTR(String str){
ERRORSTR = str;
}
// alias
void setTempDisp(){
// NI, not using colored temps, using colored footer line instead
// color code temperature
// if(currentTemp > hotTemp) tft.setTextColor( RED, BLACK );
// else if(currentTemp < coolTemp) tft.setTextColor( GREEN, BLACK );
// else tft.setTextColor( YELLOW, BLACK );
// SetFooterA();
}
void doorCancelAbort(){
if(doorAbortTaskID >-1) taskManager.cancelTask(doorAbortTaskID);
doorAbortTaskID = -1;
}
void doorAbort(){
//@todo set state, so stall can cancel scheduled aborts
Serial.println("[TASK] Door Abort");
motor(0,0);
}
/**
* open door, add failsafe stop timer
*/
void doorOpen(){
motorDir = 1;
motorChange = true;
doorCancelAbort();
doorAbortTaskID = taskManager.scheduleOnce(doorAbortTime, doorAbort);
}
void doorClose(){
motorDir = 2;
motorChange = true;
doorCancelAbort();
doorAbortTaskID = taskManager.scheduleOnce(doorAbortTime, doorAbort);
}
// MACROS
void extract(){
fanA(50); // extract 50%
}
// cancel a task, pass ref?
// add ojbect to handle tasks and ids
int cancelTask(uint16_t taskid){
Serial.println("[TASK] cancel task: " + (String)taskid);
if(taskid >-1){
taskManager.cancelTask(taskid);
return -1;
}
return taskid;
}
void coolCancel(){
if(coolAbortTaskID >-1){
coolAbortTaskID = cancelTask(coolAbortTaskID);
}
}
void coolCompleteWatcher(){
if(currentTempAvg < fanTemp){
Serial.println("[COOL] Cooldown Complete");
coolCancel();
Serial.println("[COOL] Closing Door, shutoff fans");
doorClose();
fanB(0);
SSRFan(false);
}
}
void cool(bool dooropen){
Serial.println("[COOL] cooldown");
coolCancel(); // make sure we do not create multiples timers
if(currentTempAvg < fanTemp){
Serial.println("[COOL] cooldown not needed, skipping");
return;
}
if(dooropen) doorOpen();
fanB(100); // outake 100%
Serial.println("[COOL] setup cooldown timer");
coolAbortTaskID = taskManager.scheduleFixedRate(1000, coolCompleteWatcher);
}
void coolDown(){
cool(true);
}
void standby(){
doorClose();
fanB(0);
fanA(0);
SSRFan(true); // ssr fan full
}
void sleep(){
doorClose();
fanB(0);
fanA(0);
SSRFan(false); // ssr fan off
}
void setReflowState(int state){
reflowState = state;
}
int getReflowState(){
return reflowState;
}
void reflow(){
// setPasteId = 0;
// doPasteReflow();
}
void reflowAbort(){
setReflowState(RS_ABORT);
// abort immediate for safety
setSSR(0);
SetTitle("ABORTED");
}
void reboot(){
tft.fillScreen(BLACK);
tft.setTextSize(2);
tft.setTextFont(2);
Serial.println("REBOOTING");
delay(1000);
ESP.restart();
}
// some placeholders for menu actions etc
void cancel(){
}
void hold(){
}
void reset(){
}
void save(){
}
void load(){
}
// sanity/safety
// what to do if tc fails
// main tc, alarm , abort
void TCSafe(){
// reflowAbort();
}
void tempIsSafe(){
// if(currentTemp > shutDownTemp){
// }
// tc is above max limit
// fan failing, no way to detect other than cooling state slope not moving or negative..
// ssr above temp (NTC)
// cold junction temp above temp
}
void restartDetector(){
// check for spurious restarts
// not sure if this is needed other than burn in testing
// if reset reason was bad, and was in a reflow, use flash to save state ?
// resume or warn or just alarm and leave to user.. Allow reflow resume, skip preheat
}
void userAbort(){
if(getReflowState() != RS_IDLE){
reflowAbort();
}
// pressing any button during reflow , add stop buttons
// push encoder
// spin encoder fast
// door open detect ( if door input present )
}
// set fan status display
void SetFanInd(){
int fan1 = getFanStatus(1);
int fan2 = getFanStatus(2);
SetFooterC("FAN 1");
SetFooterD("FAN 2");
// tft_set_footer_val3(fan1>0);
// tft_set_footer_val4(fan2>0);
}
/**
* ALIGN <L >R <C>
* --------------------------------------
* | <TITLE <DETAILS SUBDATA> |
* |------------------------------------|
* | |
* | GRAPH |
* | |
* |------------------------------------|
* | <FOOTERA <FOOTERCENTER> FOOTERC> |
* | <STATUSLINE> FOOTERD> |
* --------------------------------------
*/
uint8_t TITLETOPPAD = 4; // main title top padding
// add getter for colors?
// 7 magenta
// 8 cyan
// 4 greenyellow
//
void updateTempA(){
String str = TEMPA;
// Serial.println("footer val1: " + str);
if(DEBUG_BOX) tft.setTextColor(WHITE,DEBUG_HC1);
else tft.setTextColor(getLineColor(7,0),HC1);
tft.setTextDatum(TL_DATUM);
int lpad = 2;
tft.setTextPadding(115);
// drawDatumMarker(2,2);
// tft.setFreeFont(AA_FONT_MED); // Must load the font first
lpad += tft.drawString(str+"`",lpad,TITLETOPPAD,4);
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTempB(){
String str = TEMPB;
// Serial.println("footer val1: " + str);
if(DEBUG_BOX) tft.setTextColor(WHITE,DEBUG_HC1);
else tft.setTextColor(getLineColor(8,0),HC1);
tft.setTextDatum(TL_DATUM);
int lpad = 120;
tft.setTextPadding(115);
// drawDatumMarker(2,2);
// tft.setFreeFont(AA_FONT_MED); // Must load the font first
lpad += tft.drawString(str+"`",lpad,TITLETOPPAD,4);
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTempC(){
String str = TEMPC;
// Serial.println("footer val1: " + str);
if(DEBUG_BOX) tft.setTextColor(WHITE,DEBUG_HC1);
else tft.setTextColor(getLineColor(4,0),HC1);
tft.setTextDatum(TR_DATUM);
int rpad = 5;
tft.setTextPadding(115);
// drawDatumMarker(2,2);
// tft.setFreeFont(AA_FONT_MED); // Must load the font first
rpad += tft.drawString(str+"`",SCREENWIDTH-rpad,TITLETOPPAD,4);
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTitle(){
String str = TITLE;
// Serial.println("footer val1: " + str);
if(DEBUG_BOX) tft.setTextColor(WHITE,DEBUG_HC1);
else tft.setTextColor(getLineColor(4,0),HC1);
tft.setTextDatum(TL_DATUM);
int lpad = 2;
tft.setTextPadding(115);
// drawDatumMarker(2,2);
// tft.setFreeFont(AA_FONT_MED); // Must load the font first
lpad += tft.drawString(str,lpad,TITLETOPPAD,4);
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTimer(){
String str = DETAILS;
if(DEBUG_BOX) tft.setTextColor(HC1_text,DEBUG_HC2);
else tft.setTextColor(HC1_text,HC1);
tft.setTextDatum(BL_DATUM);
int lpad = 2;
tft.setTextPadding(120);
// drawDatumMarker(120,25);
lpad += tft.drawString(str,120,30,4); // 22
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTitleB(){
String str = DETAILS;
if(DEBUG_BOX) tft.setTextColor(HC1_text,DEBUG_HC2);
else tft.setTextColor(HC1_text,HC1);
tft.setTextDatum(BL_DATUM);
int lpad = 2;
tft.setTextPadding(120);
// drawDatumMarker(120,25);
lpad += tft.drawString(str,130,30,4); // 22
// Serial.println(lpad);
tft.setTextPadding(0);
}
void updateTitleC(){
String str = SUBDATA;
if(DEBUG_BOX) tft.setTextColor(HC1_text,DEBUG_HC3);
else tft.setTextColor(HC1_text,HC1);
tft.setTextDatum(BR_DATUM);
int rpad = 4;
tft.setTextPadding(80);
// drawDatumMarker(SCREENWIDTH-rpad,29);
rpad += tft.drawString(str,SCREENWIDTH-rpad,30,4); // 22
// Serial.println(lpad);
tft.setTextPadding(0);
}
// temperature C
// sprite 55fps/67fps varies by font
// gfx 72fps freefont()
// block font 88fps loadFont()
void updateFooterA_C(unsigned int c){
float str = FOOTERA_FLOAT;
#define USESPRITE
#ifdef USESPRITE
spr.setColorDepth(16);
spr.createSprite(115, 35);
spr.fillSprite(HC2);
if(DEBUG_BOX) spr.setTextColor(WHITE,DEBUG_HC1);
else spr.setTextColor(c,HC2);
spr.setTextDatum(TL_DATUM);
int lpad = 5;
spr.setTextPadding(115); // 18pt font
spr.setFreeFont(GFXX18pt);
// spr.loadFont(AA_FONT_LARGE);
lpad = spr.drawFloat((float)str,1,0,GFXFF); // 63
// if(DEBUG_BOX) spr.setTextColor(WHITE,MAROON);
spr.unloadFont();
spr.drawString("`c",lpad+5,2,4); // 22
spr.pushSprite(5, SCREENHEIGHT-35,BLACK);
spr.deleteSprite();
#else
// Serial.println("footer val1: " + str);
if(DEBUG_BOX) tft.setTextColor(WHITE,DEBUG_HC1);
else tft.setTextColor(c,HC2);
tft.setTextDatum(BL_DATUM);
int lpad = 5;
// tft.setTextPadding(90);
tft.setTextPadding(115); // 18pt font
// tft.setFreeFont(GFXX18pt); // Must load the font first
lpad = tft.drawFloat((float)str,1,lpad,SCREENHEIGHT,4); // 63
if(DEBUG_BOX) tft.setTextColor(WHITE,MAROON);
tft.setTextPadding(0);
lpad += tft.drawString("`c",lpad+6,SCREENHEIGHT,4); // 22
// tft.setTextPadding(0);
// Serial.println(lpad);
#endif
}
// user footerb_l
void updateFooterB(){
String str = FOOTERCENTER;
// str = "ABCDEFGHIJKLMNOPQR"; // 19 characters
// str = "Ms: "+(String)(millis())+" RSSI: "+(String)getRSSIasQuality(); // 19 characters
if(DEBUG_BOX) tft.setTextColor(GREY,DEBUG_HC2);
else tft.setTextColor(GREY,HC2);
tft.setTextDatum(BL_DATUM);
tft.setTextPadding(145);
// println_footer("",HC2);
tft.drawString(str,(SCREENWIDTH/3)+10,SCREENHEIGHT-4,2);
tft.setTextPadding(0);
}
void updateFooterB_ERROR(){
bool center = false;
String str = ERRORSTR;
if(DEBUG_BOX) tft.setTextColor(GREY,DEBUG_HC2);
else tft.setTextColor(RED,HC2);
if(center) tft.setTextDatum(BC_DATUM);
else tft.setTextDatum(BL_DATUM);
tft.setTextPadding(150);
int posx = (SCREENWIDTH/2)-35;
if(center)posx = (SCREENWIDTH/2)+23;
tft.drawString(str,posx,SCREENHEIGHT-4,2);
// tft.drawString(str,SCREENWIDTH/2,SCREENHEIGHT-4,2);
tft.setTextPadding(0);
}
// left aligned
// rework all of this, since we can do 2 lines now!!
void updateFooterB_L(){
String str = FOOTERCENTER;
// str = "ABCDEFGHIJKLMNOPQR"; // 19 characters
// str = "Ms: "+(String)(millis())+" RSSI: "+(String)getRSSIasQuality(); // 19 characters
if(DEBUG_BOX) tft.setTextColor(GREY,DEBUG_HC2);
else tft.setTextColor(GREY,HC2);
// text clipping
int maxchars = 0;
String newstr;
if(maxchars > 0) newstr = str.substring(0,maxchars);
else newstr = str;
tft.setTextPadding(150);
tft.setTextDatum(BL_DATUM);
// println_footer("",HC2);
tft.drawString(newstr,(SCREENWIDTH/2)-35,SCREENHEIGHT-4,2);
}
void updatefooterBL1(){
String str = FOOTERCENTERL1;
// str = "ABCDEFGHIJKLMNOPQR"; // 19 characters
// str = "Ms: "+(String)(millis())+" RSSI: "+(String)getRSSIasQuality(); // 19 characters
if(DEBUG_BOX) tft.setTextColor(GREY,DEBUG_HC2);
else tft.setTextColor(GREY,HC2);
// text clipping
int maxchars = 0;
String newstr;
if(maxchars > 0) newstr = str.substring(0,maxchars);
else newstr = str;
tft.setTextDatum(BL_DATUM);
tft.setTextPadding(150);
tft.drawString(str,(SCREENWIDTH/2)-35,SCREENHEIGHT-20,2);
}
void updatefooterBL2(){
}
void UpdateScroll(){
if(!SCROLL) return;
String str = STATUSLINE;
// str = "!\"#$%&'()*+,-./01234";
// str = "/01";
// str = "!\"#$%&'()*+,-./012345678"; // 9:;<=>?@"; // ascii
static int charindex = 0;
int charbuffer = 20;
int chars = charbuffer;
int len = str.length()+charbuffer;
String pad;
for(int i=0;i<chars;i++){
pad += " ";
}
str = pad+str; // prefix spaces so it scrolls in, can remove this after first scroll, or add transitions here
String newstr = str.substring(charindex, charindex+chars < len ? charindex+chars : len );
SetFooterB(newstr);
updateFooterB_L(); // footerB_left
charindex++;
if(charindex>len) charindex = 0;
}
void updateFooterC(bool enable){
String str = FOOTERC;
tft.setTextSize(1);
tft.setTextColor(enable?GREEN:DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(str,SCREENWIDTH-2,SCREENHEIGHT-30,2);
// tft.setTextDatum(BR_DATUM);
// tft.drawString("FAN 2",SCREENWIDTH-2,SCREENHEIGHT,2);
}
void updateFooterD(bool enable){
String str = FOOTERD;
tft.setTextSize(1);
tft.setTextColor(enable?GREEN:DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
// tft.setTextDatum(TR_DATUM);
// tft.drawString("FAN 1",SCREENWIDTH-2,SCREENHEIGHT-30,2);
tft.setTextPadding(0);
tft.setTextDatum(BR_DATUM);
tft.drawString(str,SCREENWIDTH-2,SCREENHEIGHT,2);
}
void updateFPS(){
fps.push((1000/(millis()-fpsmicros)));
fpsmicros = millis();
SetFooterB((String)fps.mean() + " FPS");
}
void updateDev(){
SetFooterB("Dev: " +(String)getTCDev());
}
void drawFooterBorder(unsigned int c = RED){
// Draw border left bottom
tft.drawFastVLine(0,SCREENHEIGHT-FOOTERH,FOOTERH,c);
tft.drawFastVLine(SCREENWIDTH-1,SCREENHEIGHT-FOOTERH,FOOTERH,c);
tft.drawFastHLine(0,SCREENHEIGHT-1,SCREENWIDTH,c);
// tft.drawFastVLine(tft.width()-1,0,tft.height()-1,c);
// tft.drawFastHLine(0,0,tft.width()-1,c);
}
void drawFooterLineBottom(unsigned int c){
tft.drawFastHLine(0,0,SCREENWIDTH,c);
tft.drawFastHLine(0,1,SCREENWIDTH,c);
}
void drawFooterLine(unsigned int c){
tft.drawFastHLine(0,SCREENHEIGHT-FOOTERH,SCREENWIDTH,c);
tft.drawFastHLine(0,SCREENHEIGHT-FOOTERH-1,SCREENWIDTH,c);
}
// @NOTE If Y is off screen is snaps to negative
// fan a
int iconAX = SCREENWIDTH-20;
int iconAY = SCREENHEIGHT-(FOOTERH-2);
// fan b
int iconBX = SCREENWIDTH;
int iconBY = SCREENHEIGHT-(FOOTERH-2);
// heater
int iconCX = SCREENWIDTH-20;
int iconCY = SCREENHEIGHT-(FOOTERH-20);
// wifi
int iconDX = SCREENWIDTH;
int iconDY = SCREENHEIGHT-(FOOTERH-20);
void wifiIcon(bool enabled = true,bool connected = false){
String str = "!";
// tft.setTextSize(1);
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
if(enabled && connected){
tft.setTextColor(ICONACTIVECOLOR,DEBUG_BOX?DEBUG_HC3:HC2);
}
else {
tft.setTextColor(DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
}
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(str,iconDX,iconDY,GFXFF);
if(!connected){
tft.setTextColor(RED);
tft.drawString("!",iconDX-6,iconDY+2,2);
}
// tft.drawString("8",SCREENWIDTH-20,SCREENHEIGHT-(FOOTERH-2),GFXFF);
}
// fonts from custom glyph
// using symbolMono18pt7b test for now, needs cleanup
#define ICON_CHR_WIFI "!"
#define ICON_CHR_WIFI_OVERA "!"
#define ICON_CHR_WIFI_OVERB "*"
#define ICON_CHR_FANA "\""
#define ICON_CHR_FANB "#"
#define ICON_CHR_FANOVERA "$"
#define ICON_CHR_FANOVERB "%"
#define ICON_CHR_HEAT "&"
// NI Wifi mananger or ap is running for config/pairing
void wifiSetupIcon(){
String str = ICON_CHR_WIFI;
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
tft.setTextColor(ICONACTIVECOLOR,DEBUG_BOX?DEBUG_HC3:HC2);
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(str,iconDX,iconDY,GFXFF);
tft.setTextColor(BLUE);
tft.drawString(ICON_CHR_WIFI_OVERB,iconDX-6,iconDY+2,2);
tft.unloadFont();
}
void fanAIcon(bool enabled = false){
String str = ICON_CHR_FANA;
if(enabled){
if(animStateA) str = ICON_CHR_FANB;
animStateA = !animStateA;
tft.setTextColor(ICONACTIVECOLOR,DEBUG_BOX?DEBUG_HC3:HC2);
}
else {
tft.setTextColor(DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
}
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(str,iconAX,iconAY,GFXFF);
tft.unloadFont();
}
void fanBIcon(bool enabled = false){
String str = ICON_CHR_FANA;
if(enabled){
if(animStateB) str = ICON_CHR_FANB;
animStateB = !animStateB;
tft.setTextColor(ICONACTIVECOLOR,DEBUG_BOX?DEBUG_HC3:HC2);
}
else {
tft.setTextColor(DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
}
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(str,iconBX,iconBY,GFXFF); // W,H
}
void iconC(bool enabled = false){
// heater
if(enabled){
tft.setTextColor(REDORANGE,DEBUG_BOX?DEBUG_HC3:HC2);
}
else {
tft.setTextColor(DKGREY,DEBUG_BOX?DEBUG_HC3:HC2);
}
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(ICON_CHR_HEAT,iconCX,iconCY,GFXFF); // W,H
tft.unloadFont();
}
void fanAIcon_ring(unsigned int c){
// String str = animStateB? "\"" : "#";
// animStateB = !animStateB;
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
tft.setTextColor(c);
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(ICON_CHR_FANOVERA,SCREENWIDTH-50-17,SCREENHEIGHT-30,GFXFF);
tft.unloadFont();
}
void fanBIcon_ring(unsigned int c,bool full){
// String str = animStateB? "\"" : "#";
// animStateB = !animStateB;
tft.setFreeFont(AA_FONT_SMALL); // Must load the font first
tft.setTextColor(c);
tft.setTextDatum(TR_DATUM);
tft.setTextPadding(0);
tft.drawString(full ? ICON_CHR_FANOVERA : ICON_CHR_FANOVERB,SCREENWIDTH-50-17-17,SCREENHEIGHT-30,GFXFF);
tft.unloadFont();
}
// Red DANGER burns
// Orange HOT use caution
// Green Above ambient
// Blue, cooldown remove PCB ? NI
void updateFooterLine(){
if(currentTempAvg > hotTemp) drawFooterLine(RED);
else if(currentTempAvg > coolTemp) drawFooterLine(ORANGE);
else if(currentTempAvg > lowTemp) drawFooterLine(GREEN);
else drawFooterLine(BLACK);
}
void updateAccentColor(){
if(currentTempAvg > hotTemp) indAccentSetColor(255,0,0);
else if(currentTempAvg > coolTemp) indAccentSetColor(255,128,0);
else if(currentTempAvg > lowTemp) indAccentSetColor(0,255,0);
else indAccentSetColor(accentColor);
}
void doAlert(int mode = 0);
void updateSSRIcon(){
iconC(getSSRDuty() > 0);
}
// random indication icon test
void testIconsUpdate(){
wifiIcon(random(2)-1,random(2)-1);
fanAIcon(true);
// fanAIcon_ring(DKGRAY);
fanBIcon(random(2)-1);
// fanBIcon_ring(LTBLACK,true);
// fanBIcon_ring(TFT_SILVER,false);
iconC(random(2)-1);
}
void updateIcons(){
if(testIcons){
return testIconsUpdate();
}
// wifiSetupIcon();
wifiIcon(USEWIFI && wifiIsAutoConnect(),wifiIsConnected());
fanAIcon(getFanStatus(1)>0);
// fanAIcon_ring(DKGRAY);
fanBIcon(getFanStatus(2)>0);
// fanBIcon_ring(LTBLACK,true);
// fanBIcon_ring(TFT_SILVER,false);
updateSSRIcon();
}
void dispReflowStats(){
String str = "";
str = "NTC: "+(String)(int)(round(NTC_TEMP/10));
str += " CJ: " + (String)(int)(round(internalTemp));
setFooterBL1(str);
str = "";
str += "P: " + (String)(int)getSSRPower() + "%";
str += " o: " + (String)getTCDev();
str += " E: " + (String)getTCErrorCount();
SetFooterB(str);
}
void updateAll(){
// updateFPS();
// updateDev();
dispReflowStats();