-
Notifications
You must be signed in to change notification settings - Fork 0
/
Datalogger.ino
1920 lines (1896 loc) · 56.1 KB
/
Datalogger.ino
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---------------
#include <Arduino.h>
#include <ArduinoJson.h>
#include "SoftwareSerial.h"
#include <avr/pgmspace.h>
#include <RokkitHash.h>
#include <EEPROM.h>
#include <SD.h>
#include <SPI.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <Wire.h>
#include <ds3231.h>
#include <BMP180advanced.h>
#include <math.h>
//macros----------------
#define Version Firmware_Version " B[" __DATE__ "] -" + String(Firmware_class)
#define Version_DX Firmware_Version "-" + String(Firmware_class) + " [" + SAVE_DATA_TYPE + "]\n\nbuild: " __DATE__ \
"\n\ndisplay style: \n\n" + String(DSN[display_style])
#define PIEZO_PIN 7
#define B_RX 11
#define B_TX 12
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define Minute (uint32_t)60000
#define SEC (uint32_t)1000
#define ATAT 30000
#define chipSelect 6
#define MX_Mi_Day 0
#define MX_Mi_Month 1
#define MX_Mi_year 2
#define MX_Mi_Main 3
#define BCVS "[DAT_LOGGER]"
//Settings
#define Firmware_Version "V1.4.7"
#define Debug 0 // 0 off / +1 on
#define display_style 3
#define style_name {"[Debug]","[Simple]","[Simple(2)]","[Modern]"}
#define DELAY_SMTUL (uint32_t)1200 //in sec
#define D_DELAY_LOG 1 //in Minute (log interval)
#define PIEZO_MODE 1 // 0 off / 1 on
#define MAX_MIN_UPDATE_MODE 0 // 0 for in sync with logging time (for better charts) / 1 for in sync with code update (for better data) {[!!!only on main file!!!]}
#define EVENT_LOG_Detail_mode 0 // 0 only Errors / 1 high detail (uses a lot of storage space)
#define noise_filtering_Mode_DEF 0 // noise_filtering_Mode_DEF
#define EEPROM_Saddress 1 // EEPROM starting address
#define EEPROM_SAVING 1 // 0 off / 1 on
#define SAVE_DATA_TYPE String("csv") // csv or txt
#define text_data_separator "\t"
#define Sensor_Active_OFFSET_H 0 // Sensor_Active_OFFSET_H
#define Sensor_Active_OFFSET_T 0 // Sensor_Active_OFFSET_T
#define heater_temp_offset -1.5
#define EEPROM_CLEAR 0 // 0 / 1
//TIME Settings
#define NEW_TIME_SET 0 // 0 / 1
#define NEW_DAY 21
#define NEW_MON 7
#define NEW_YEAR 2023
#define NEW_S 30
#define NEW_M 24
#define NEW_H 13
//noise_filtering
//S1
#define BMP180_SC 180
#define BMP180_LI 10
#define BMP180_HI 10
/*
ULtra:
#define BMP180_SC 180
#define BMP180_LI 10
#define BMP180_HI 10
Normal:
#define BMP180_SC 100
#define BMP180_LI 10
#define BMP180_HI 10
*/
//S2
#define SHT31_SC 120
#define SHT31_LI 8
#define SHT31_HI 8
/*
ULtra:
#define BMP180_SC 120
#define BMP180_LI 10
#define BMP180_HI 10
Normal:
#define BMP180_SC 80
#define BMP180_LI 10
#define BMP180_HI 10
*/
//DATA------------------
//float
float AVT_D;
float AVH_D;
float AVT_D_TEMP;
float AVH_D_TEMP;
float TEMPH;
float TEMPT;
float TEMPH2;
float TEMPT2;
float humidity;
float RAW_humidity;
float temperature;
float RAW_temperature;
float Pressure_hPa;
float RAW_Pressure_hPa;
float DELAY_LOG = D_DELAY_LOG;
float SAF_T;
//int/long/...
uint8_t ERROR_C;
uint8_t year;
uint8_t mon;
uint8_t day;
uint8_t OLD_DAY;
uint8_t OLD_MON;
uint8_t OLD_YEAR;
uint32_t AV_C;
uint32_t day_C;
uint32_t VCH, S_VCH, VCD_LEN;
//bool
bool START = true;
bool START_L_EX = true;
bool BS_SHT31;
bool BS_SD_CARD;
bool BS_BMP_180;
bool SD_EVENT_FILE_EX = true;
bool ignore_ERROR;
bool SD_MAIN_FILE_EX;
bool SHT31_heater;
bool HAM;
bool USB_Debug;
bool noise_filtering_Mode = noise_filtering_Mode_DEF;
//other DT
struct Max_min_REC{
float MAX_T_REC = -100.00;
float MIN_T_REC = 100.00;
float MAX_H_REC = 0;
float MIN_H_REC = 100.00;
float TD_PD;
float HD_PD;
};
char BLS_M = 'N';
char Firmware_class = 's';
Max_min_REC MAX_MIN_RT[4];
struct ts t;
String config_B = "";
const String txt = String("txt");
const String csv = String("csv");
const String DSN[5] = style_name;
const char RAW_DATA[] =
"RSD\n"
"{\n"
"wH8RdS86tS5gKj3E"
"Fp4NzY2jLq6BvXc9"
"tS9MxK6qLp8bHf7D"
"cJ7dGh6fHt2Km5R"
"yP5kXn9bVr2LcQ8J"
"zC2mLp7fTg9DdE5"
"sR3gNk6tVq8yHf4"
"bH9nTc2vZj6Lx7Y"
"mF8tKj2nGc7Dp5S"
"vL7gHd9sT6fRq3N"
"wH8RdS86tS5gKj3E"
"Fp4NzY2jLq6BvXc9"
"tS9MxK6qLp8bHf7D"
"cJ7dGh6fHt2Km5R"
"yP5kXn9bVr2LcQ8J"
"zC2mLp7fTg9DdE5"
"sR3gNk6tVq8yHf4"
"bH9nTc2vZj6Lx7Y"
"mF8tKj2nGc7Dp5S"
"vL7gHd9sT6fRq3N"
"}";
const char DSinfo[] =
"============================\n"
" 24H DATA SUMMARY \n"
"============================";
const char BL_help_tmp[] =
"command table\n"
" help\n"
" EL_Info\n"
" SET_LOG.INTERVAL:\n"
" CONST_SAVE\n"
" RESET_DEF\n"
" SOFT_RESET\n"
" NFM_ON\n"
" NFM_OFF\n"
" ignore_ERROR_ON\n"
" ignore_ERROR_OFF\n"
" Data_stream_on\n"
" Data_stream_off\n"
" Data_stream_DB\n"
" SHT31_heater_ON\n"
" SHT31_heater_OFF";
String ELinfo =
"---------------------------------\n"
"Version: " + String(Version) + "\n\n"
"Settings>>>\n"
"Debug: " + String(Debug) + " (+1 ON / 0 OFF)\n"
"display_style: " + String(DSN[display_style]) + "\n"
"DELAY_SMTUL: " + String(DELAY_SMTUL) + "s\n"
"DELAY_LOG: " + String(DELAY_LOG) + "m\n"
"Sensor_Active_OFFSET_T: " + String(Sensor_Active_OFFSET_T) + "C\n"
"heater_temp_offset: " + String(heater_temp_offset) + "C\n"
"Sensor_Active_OFFSET_H: " + String(Sensor_Active_OFFSET_H) + "RH%\n"
"noise_filtering_Mode: " + String(noise_filtering_Mode) + " (1 ON / 0 OFF)\n"
"SHT31_heater: " + String(SHT31_heater) + " (1 ON / 0 OFF)\n"
"MAX_MIN_UPDATE_MODE: " + String(MAX_MIN_UPDATE_MODE) + " (1 SCU / 0 SL)\n"
"EVENT_LOG_Detail_mode: " + String(EVENT_LOG_Detail_mode) + " (1 HIGH / 0 LOW)\n"
"EEPROM_Saddress: " + String(EEPROM_Saddress) + "\n"
"EEPROM_SAVING: " + String(EEPROM_SAVING) + " (1 ON / 0 OFF)\n"
"SAVE_DATA_TYPE: " + String(SAVE_DATA_TYPE) + "\n"
"---------------------------------";
const String FIX_RAW =
"sd card is not working properly try\nchanging the sd card";
char VCD[] = __DATE__ __TIME__;
//other-----------------
SoftwareSerial bluetooth(B_RX, B_TX);
BMP180advanced bmp180(BMP180_ULTRAHIGHRES);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
Adafruit_SHT31 TH_S = Adafruit_SHT31();
File SD_CARD;
Sd2Card card;
//warning
#if NEW_TIME_SET == 1
#warning "TIME SET IS ON|------------------------------"
#endif
#if EEPROM_CLEAR == 1
#warning "EEPROM_CLEAR IS ON|------------------------------"
#endif
#if Debug >= 1
void DebugVal(String Name, String Val)
{
Serial.print(Name);
Serial.print(F(": "));
Serial.println(Val);
}
#endif
//custom function
bool millisDelay(unsigned long Delay, int TimerS, int Sdelay = 0, bool RESET_CT = false, bool ATA = false)
{
static uint32_t TIME_DELAY[5];
static uint32_t TIME_OVF;
delay(Sdelay);
#if Debug >= 2
DebugVal("ATA: ", String(ATA));
DebugVal("RESET_CT: ", String(RESET_CT));
DebugVal("Sdelay: ", String(Sdelay));
DebugVal("TimerS: ", String(TimerS));
DebugVal("Delay: ", String(Delay));
DebugVal("TIME_OVF: ", String(TIME_OVF));
DebugVal("TIME_DELAY: ", String(TIME_DELAY[TimerS]));
#endif
if (TIME_OVF > millis()) //if OVF
{
TIME_DELAY[TimerS] = (millis() + Delay);
}
TIME_OVF = millis(); //RESET OVF Val
if (TIME_DELAY[TimerS] <= millis()) // TIMER true / RESET
{
TIME_DELAY[TimerS] = (millis() + Delay);
SMART_EX:
return true;
}
else if (RESET_CT) // TIMER RESET
{
TIME_DELAY[TimerS] = (millis() + Delay);
}
if (TIME_DELAY[TimerS] <= (millis() + ATAT) && ATA)
{goto SMART_EX;}
return false;
}
//----------------------
void printMD_bl(String startDate, String endDate, String filename)
{
bluetooth.println(F("scan starts in 10 sec..."));
delay(10000);
bluetooth.println(F("scaning..."));
bool printData = false;
SD_CARD = SD.open(filename);
if (SD_CARD)
{
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_CYAN, ST7735_BLACK);
tft.setCursor(0, 5);
tft.setTextSize(2);
tft.print("Scaning \n" + filename +"\nfile...");
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setTextSize(1);
uint32_t Index_L = 0;
String date = "";
String line = "";
while (SD_CARD.available())
{
Index_L++;
line = SD_CARD.readStringUntil('\n');
line.trim();
startDate.trim();
endDate.trim();
uint8_t FCI = line.indexOf(',');
date = line.substring(FCI + 1, line.indexOf(',', FCI + 1));
if(millisDelay(500, 4))
{
tft.setCursor(0, 60);
tft.println("StartDate: " + startDate);
tft.setCursor(0, 73);
tft.println("EndDate: " + endDate);
tft.setCursor(0, 86);
tft.println("CSD: " + date + " ");
tft.setCursor(0, 99);
tft.println("Datefound: " + String(printData));
tft.setCursor(0, 112);
tft.println("Index_L: " + String(Index_L));
}
if (date.equals(startDate))
{printData = true;}
if (printData)
{
bluetooth.println("/*" + line + "*/");
}
if (date.equals(endDate) || date.equals(""))
{break;}
}
SD_CARD.close(); // close the file
if (!printData)
{
bluetooth.println(F("Error finding the date"));
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(0, 5);
tft.println(F("Error finding the date"));
delay(4000);
ST7735_TAB_Main();
}
}
else
{
bluetooth.println(F("error opening the file"));
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(0, 5);
tft.println(F("error opening the file"));
delay(4000);
ST7735_TAB_Main();
}
ST7735_TAB_Main();
}
//----------------------
void version_control()
{
//CVH
VCD_LEN = strlen(VCD);
VCH = rokkit(VCD, VCD_LEN);
//M_PROC
EEPROM.get((EEPROM_Saddress + sizeof(float)) * 5 + sizeof(bool), S_VCH);
if(S_VCH != VCH)
{
Firmware_class = 'b';
}
EEPROM.put((EEPROM_Saddress + sizeof(float)) * 5 + sizeof(bool), VCH);
#if Debug >= 2
DebugVal("VCD_LEN: ", String(VCD_LEN));
DebugVal("VCD: ", String(VCD));
DebugVal("VCH: ", String(VCH));
DebugVal("S_VCH: ", String(S_VCH));
#endif
}
//----------------------
void ST7735_TAB_ERROR(String ER = "???", String FIX = "N/A", bool RTFTS = true)
{
if (!ignore_ERROR)
{
tft.setTextSize(1);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(0, 5);
tft.print("ERROR: \n" + String(ER) + "\n\nFIX:\n" + String(FIX));
PIEZO(PIEZO_PIN,'E',1000);
delay(5000);
if(RTFTS)
{
tft.fillScreen(ST7735_BLACK);
ST7735_TAB_Main();
}
}
}
//----------------------
void ST7735_TAB_Warning(String ER = "???", int Wdelay = 5000)
{
if (!ignore_ERROR)
{
tft.setTextSize(1);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
tft.setCursor(0, 5);
tft.print("Warning: \n" + String(ER));
PIEZO(PIEZO_PIN,'I',1000);
delay(Wdelay);
tft.fillScreen(ST7735_BLACK);
ST7735_TAB_Main();
}
}
//----------------------
void ST7735_TAB_Boot() {
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(0, 5);
tft.setTextSize(2);
tft.print("Firmware:");
tft.setCursor(0, 27);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setTextSize(1);
tft.print(Version_DX);
delay(5000);
}
//----------------------
#if display_style == 3
uint16_t rainbow(byte value)
{
byte red = 0;
byte green = 0;
byte blue = 0;
byte quadrant = value / 32;
if (quadrant == 0) {
blue = 31;
green = 2 * (value % 32);
red = 0;
}
if (quadrant == 1) {
blue = 31 - (value % 32);
green = 63;
red = 0;
}
if (quadrant == 2) {
blue = 0;
green = 63;
red = value % 32;
}
if (quadrant == 3) {
blue = 0;
green = 63 - 2 * (value % 32);
red = 31;
}
return (red << 11) + (green << 5) + blue;
}
//------------
int ringMeter(float value, int vmin, int vmax, int x, int y, int r, char *units, byte scheme, bool RI = false)
{
x += r;
y += r;
int w = r / 4;
int angle = 150;
int text_colour = 0;
int v = map(value, vmin, vmax, -angle, angle); // Map the value to an angle v
byte seg = 5;
byte inc = 5;
for (int i = -angle; i < angle; i += inc)
{
int colour = 0;
switch (scheme)
{
case 0:
colour = ST7735_RED;
break; // Fixed colour
case 1:
colour = ST7735_GREEN;
break; // Fixed colour
case 2:
colour = ST7735_BLUE;
break; // Fixed colour
case 3:
colour = rainbow(map(i, -angle, angle, 0, 127));
break;
case 4:
colour = rainbow(map(i, -angle, angle, 63, 127));
break;
case 5:
colour = rainbow(map(i, -angle, angle, 61, 0));
break;
case 6:
colour = rainbow(map(i, -angle, angle, 20, 74));
break;
default:
colour = ST7735_BLUE;
break; // Fixed colour
}
float sx = cos((i - 90) * 0.0174532925);
float sy = sin((i - 90) * 0.0174532925);
uint16_t x0 = sx * (r - w) + x;
uint16_t y0 = sy * (r - w) + y;
uint16_t x1 = sx * r + x;
uint16_t y1 = sy * r + y;
float sx2 = cos((i + seg - 90) * 0.0174532925);
float sy2 = sin((i + seg - 90) * 0.0174532925);
int x2 = sx2 * (r - w) + x;
int y2 = sy2 * (r - w) + y;
int x3 = sx2 * r + x;
int y3 = sy2 * r + y;
if (i < v)
{
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
text_colour = colour;
}
else
{
tft.fillTriangle(x0, y0, x1, y1, x2, y2, 0x3186);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, 0x3186);
}
}
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
if (r > 84)
tft.setTextSize(2);
else
tft.setTextSize(1);
if(RI)
{
tft.setCursor(x - 6 - (String(int(value)).length() - 2) * 3, y - 8);
tft.print(String(int(value)));
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
}
else
{
tft.setCursor(x - 6 - (String(value).length() - 2) * 3, y - 8);
tft.print(String(value));
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
}
if (r > 84)
{
tft.setTextSize(2);
tft.setCursor(x, y + 20);
}
else
{
tft.setTextSize(1);
tft.setCursor(x - 7, y + 5);
}
tft.print(units);
}
#endif
//----------------------
void ST7735_TAB_Main()
{ //TODO make new style
tft.fillScreen(ST7735_BLACK);
//style (0)------------------------------------------------
#if display_style == 0
//Time/date
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(0, 5);
tft.print(F("TIME ="));
tft.setCursor(0, 20);
tft.print(F("DATE ="));
//Sys Data
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(0, 35);
tft.print(F("T-AVPRD ="));
tft.setCursor(0, 50);
tft.print(F("H-AVPRD ="));
tft.setCursor(0, 65);
tft.print(F("PROC ="));
//THP data: H = 105 / T = 125 / Pressure_hPa = 145
tft.drawFastHLine(0, 93, tft.width(), ST7735_WHITE);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
tft.setCursor(0, 105);
tft.print(F("HUMIDITY ="));
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(0, 125);
tft.print(F("TEMPERATURE ="));
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.setCursor(0, 145);
tft.print(F("PRESSURE ="));
//style (1)------------------------------------------------
#elif display_style == 1
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(0, 10);
tft.print(F("TIME ="));
tft.setCursor(0, 25);
tft.print(F("DATE ="));
tft.drawFastHLine(0, 50, tft.width(), ST7735_BLUE);
tft.drawFastHLine(0, 102, tft.width(), ST7735_BLUE);
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.setCursor(25, 61);
tft.print(F("TEMPERATURE ="));
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
tft.setCursor(34, 113);
tft.print(F("HUMIDITY ="));
//style (2)------------------------------------------------
#elif display_style == 2
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(0, 2);
tft.print(F("TIME ="));
tft.setCursor(0, 17);
tft.print(F("DATE ="));
tft.drawFastHLine(0, 30, tft.width(), ST7735_WHITE);
tft.drawFastHLine(0, 76, tft.width(), ST7735_WHITE);
tft.drawFastHLine(0, 122, tft.width(), ST7735_WHITE);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(25, 39);
tft.print(F("TEMPERATURE ="));
tft.setTextColor(ST7735_CYAN, ST7735_BLACK);
tft.setCursor(34, 85);
tft.print(F("HUMIDITY ="));
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.setCursor(34, 131);
tft.print(F("PRESSURE ="));
tft.setTextSize(2);
//style (3)------------------------------------------------
#elif display_style == 3
tft.setTextSize(1);
tft.drawFastVLine(61, 0, 160, ST7735_WHITE);
tft.drawFastHLine(61, 29, 128, ST7735_WHITE);
tft.drawFastHLine(61, 62, 128, ST7735_WHITE);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(64, 2);
tft.print(F("TIME"));
tft.setCursor(64, 35);
tft.print(F("DATE"));
tft.setCursor(64, 70);
tft.print(F("AVT: "));
tft.setCursor(64, 85);
tft.print(F("AVH: "));
tft.setCursor(64, 100);
tft.print(F("Tmax: "));
tft.setCursor(64, 115);
tft.print(F("Hmax: "));
tft.setCursor(64, 130);
tft.print(F("Tmin: "));
tft.setCursor(64, 145);
tft.print(F("Hmin: "));
//end of Style
#endif
}
//----------------------
void ST7735_TAB_Main_data(String PROC = "Wait_\\ ")
{
#if Debug >= 2
DebugVal("PROC: ", String(PROC));
#endif
//style (0)------------------------------------------------
#if display_style == 0 //TODO make new style
char buffer[8];
//Time/date
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(40, 5);
sprintf(buffer, "%i:%i:%i ", t.hour, t.min, t.sec);
tft.print(buffer);
tft.setCursor(40, 20);
sprintf(buffer, "%i/%i/%i ", t.mday, t.mon, t.year);
tft.print(buffer);
//Sys Data
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(58, 35);
tft.print(String(AVT_D) + "C ");
tft.setCursor(58, 50);
tft.print(String(AVH_D) + "% ");
tft.setCursor(36, 65);
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.print(String(" ") + PROC + String(" "));
//THP data: H = 105 / T = 125 / Pressure_hPa = 145
tft.setTextSize(1);
tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
tft.setCursor(64, 105);
tft.print(humidity);
tft.print(F("%"));
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(83, 125);
tft.print(temperature);
tft.print(F("C"));
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.setCursor(64, 145);
tft.print(Pressure_hPa);
tft.print(F("hpa "));
//style (1)------------------------------------------------
#elif display_style == 1
char buffer[8];
//Time/date
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(40, 10);
sprintf(buffer, "%i:%i:%i ", t.hour, t.min, t.sec);
tft.print(buffer);
tft.setCursor(40, 25);
sprintf(buffer, "%i/%i/%i ", t.mday, t.mon, t.year);
tft.print(buffer);
//data
tft.setTextSize(2);
tft.setTextColor(ST7735_RED, ST7735_BLACK);
tft.setCursor(29, 78);
tft.print(String(temperature));
tft.drawCircle(90, 80, 2, ST7735_RED);
tft.setCursor(93, 78);
tft.print(F("C"));
tft.setTextColor(ST7735_CYAN, ST7735_BLACK);
tft.setCursor(29, 130);
tft.print(String(humidity) + "%");
//style (2)------------------------------------------------
#elif display_style == 2
char buffer[8];
//Time/date
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
tft.setCursor(40, 2);
sprintf(buffer, "%i:%i:%i ", t.hour, t.min, t.sec);
tft.print(buffer);
tft.setCursor(40, 17);
sprintf(buffer, "%i/%i/%i ", t.mday, t.mon, t.year);
tft.print(buffer);
//data
tft.setTextSize(2);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
tft.setCursor(25, 53);
tft.print(String(temperature) + "C" );
tft.setTextColor(ST7735_MAGENTA, ST7735_BLACK);
tft.setCursor(25, 99);
tft.print(String(humidity) + "% ");
tft.setTextColor(0xFD00, ST7735_BLACK);
tft.setCursor(11, 145);
tft.print(String(Pressure_hPa) + "hpa ");
//style (2)------------------------------------------------
#elif display_style == 3
char buffer[8];
//Time/date
tft.setTextSize(1);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
sprintf(buffer, "%i:%i:%i ", t.hour, t.min, t.sec);
tft.setCursor(64, 17);
tft.print(buffer);
sprintf(buffer, "%i/%i/%i ", t.mday, t.mon, t.year);
tft.setCursor(64, 50);
tft.print(buffer);
//data
//AV
tft.setCursor(88, 70);
tft.print(String(AVT_D) + "C ");
tft.setCursor(88, 85);
tft.print(String(AVH_D) + "% ");
//MAX
tft.setCursor(94, 100);
tft.print(String(round(MAX_MIN_RT[MX_Mi_Day].MAX_T_REC)) + "C ");
tft.setCursor(94, 115);
tft.print(String(round(MAX_MIN_RT[MX_Mi_Day].MAX_H_REC)) + "% ");
//MIN
tft.setCursor(94, 130);
tft.print(String(round(MAX_MIN_RT[MX_Mi_Day].MIN_T_REC)) + "C ");
tft.setCursor(94, 145);
tft.print(String(round(MAX_MIN_RT[MX_Mi_Day].MIN_H_REC)) + "% ");
//data (INV)
// Temperature meter
byte tempScheme = 3;
ringMeter(temperature, -10, 60, 5, 0, tft.width() / 5, " C", tempScheme);
// Humidity meter
byte humiScheme = 6;
ringMeter(humidity, 0, 100, 5, 55, tft.width() / 5, "RH%", humiScheme);
// Pressure meter
byte presScheme = 5;
ringMeter(round(Pressure_hPa), 300, 1100, 5, 110, tft.width() / 5, "hpa", presScheme, true);
//end of Style
#endif
}
//----------------------
void ELinfo_U()
{
ELinfo =
"---------------------------------\n"
"Version: " + String(Version) + "\n\n"
"Settings>>>\n"
"Debug: " + String(Debug) + " (+1 ON / 0 OFF)\n"
"display_style: " + String(DSN[display_style]) + "\n"
"DELAY_SMTUL: " + String(DELAY_SMTUL) + "s\n"
"DELAY_LOG: " + String(DELAY_LOG) + "m\n"
"Sensor_Active_OFFSET_T: " + String(Sensor_Active_OFFSET_T) + "C\n"
"heater_temp_offset: " + String(heater_temp_offset) + "C\n"
"Sensor_Active_OFFSET_H: " + String(Sensor_Active_OFFSET_H) + "RH%\n"
"noise_filtering_Mode: " + String(noise_filtering_Mode) + " (1 ON / 0 OFF)\n"
"SHT31_heater: " + String(SHT31_heater) + " (1 ON / 0 OFF)\n"
"MAX_MIN_UPDATE_MODE: " + String(MAX_MIN_UPDATE_MODE) + " (1 SCU / 0 SL)\n"
"EVENT_LOG_Detail_mode: " + String(EVENT_LOG_Detail_mode) + " (1 HIGH / 0 LOW)\n"
"EEPROM_Saddress: " + String(EEPROM_Saddress) + "\n"
"EEPROM_SAVING: " + String(EEPROM_SAVING) + " (1 ON / 0 OFF)\n"
"SAVE_DATA_TYPE: " + String(SAVE_DATA_TYPE) + "\n"
"---------------------------------";
}
//----------------------
void(* resetFunc) (void) = 0;
//----------------------
void PIEZO(int pin, char mode, long ONTIME)// mode E : ERROR , W : interrupts2 , I : interrupts
{
if (PIEZO_MODE)
{
unsigned long NEWTIME = (millis() + ONTIME);
unsigned long OLDTIME = millis();
delay(10);
if (mode == 'E')
{
while (NEWTIME > millis() && millis() > OLDTIME)
{
tone(pin,2500,40);
delay(100);
tone(pin,2500,40);
delay(400);
}
}
else if (mode == 'W')
{
while (NEWTIME > millis() && millis() > OLDTIME)
{
tone(pin,2000,40);
delay(200);
}
}
else if (mode == 'I')
{
while (NEWTIME > millis() && millis() > OLDTIME)
{
tone(pin,1000,100);
delay(1000);
}
}
}
}
//----------------------
void DAY_LOG()
{
bool print_DAYF_H = SD.exists(F("DAY.txt"));
SD_CARD = SD.open(F("DAY.txt"), FILE_WRITE);
if (!print_DAYF_H){SD_CARD.println(DSinfo);}
DS3231_get(&t);
SD_CARD.print("\n");
SD_CARD.print("#----- DATE: " + String(t.mday) + "/" + String(t.mon) + "/" + String(t.year) + " -----#\n");
SD_CARD.print("temp range: (" + String(MAX_MIN_RT[MX_Mi_Day].MIN_T_REC) + "°C|" + String(MAX_MIN_RT[MX_Mi_Day].MAX_T_REC) + "°C)\n");
SD_CARD.print("humidity range: (" + String(MAX_MIN_RT[MX_Mi_Day].MIN_H_REC) + "RH%|" + String(MAX_MIN_RT[MX_Mi_Day].MAX_H_REC) + "RH%)\n");
SD_CARD.print("AV temp: " + String(AVT_D) + "°C (based on " + String(AV_C) + " data points)\n");
SD_CARD.print("AV humidity: " + String(AVH_D) + "RH% (based on " + String(AV_C) + " data points)\n");
SD_CARD.print("Temp difference from previous day: " + String(MAX_MIN_RT[MX_Mi_Day].TD_PD) + "°C\n");
SD_CARD.print("Humidity difference from previous day: " + String(MAX_MIN_RT[MX_Mi_Day].HD_PD) + "RH%\n");
SD_CARD.close();
}
//----------------------
void Bluetooth_PRINT()
{
if (BLS_M == 'N')
{
DS3231_get(&t);
bluetooth.print("\n");
bluetooth.print("#----- DATE & TIME: " + String(t.mday) + "/" + String(t.mon) + "/" + String(t.year) + " | "
+ String(t.hour) + ":" + String(t.min) + ":" + String(t.sec) + " -----#\n");
bluetooth.print("temp: " + String(temperature) + "°C\n");
bluetooth.print("humidity: " + String(humidity) + "RH%\n");
bluetooth.print("temp range: (" + String(MAX_MIN_RT[MX_Mi_Day].MIN_T_REC) + "°C|" + String(MAX_MIN_RT[MX_Mi_Day].MAX_T_REC) + "°C)\n");
bluetooth.print("humidity range: (" + String(MAX_MIN_RT[MX_Mi_Day].MIN_H_REC) + "RH%|" + String(MAX_MIN_RT[MX_Mi_Day].MAX_H_REC) + "RH%)\n");
bluetooth.print("AV temp: " + String(AVT_D) + "°C (based on " + String(AV_C) + " data points)\n");
bluetooth.print("AV humidity: " + String(AVH_D) + "RH% (based on " + String(AV_C) + " data points)\n");
bluetooth.print("Temp difference from previous day: " + String(MAX_MIN_RT[MX_Mi_Day].TD_PD) + "°C\n");
bluetooth.print("Humidity difference from previous day: " + String(MAX_MIN_RT[MX_Mi_Day].HD_PD) + "RH%\n");
}
else if (BLS_M == 'S')
{
bluetooth.print(F("/*")); //for suport of serial studio
bluetooth.print(t.hour);
bluetooth.print(F(":"));
bluetooth.print(t.min);
bluetooth.print(F(":"));
bluetooth.print(t.sec);
bluetooth.print(F(","));
bluetooth.print(t.mday);
bluetooth.print(F("/"));
bluetooth.print(t.mon);
bluetooth.print(F("/"));
bluetooth.print(t.year);
bluetooth.print(F(","));
bluetooth.print(Pressure_hPa);
#if Debug >= 1
bluetooth.print(F(","));
bluetooth.print(RAW_Pressure_hPa);
#endif
bluetooth.print(F(","));
bluetooth.print(temperature);
#if Debug >= 1
bluetooth.print(F(","));
bluetooth.print(RAW_temperature);
#endif
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Month].MAX_T_REC);
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Month].MIN_T_REC);
bluetooth.print(F(","));
bluetooth.print(humidity);
#if Debug >= 1
bluetooth.print(F(","));
bluetooth.print(RAW_humidity);
#endif
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Month].MAX_H_REC);
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Month].MIN_H_REC);
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Main].TD_PD);
bluetooth.print(F(","));
bluetooth.print(MAX_MIN_RT[MX_Mi_Main].HD_PD);
bluetooth.print(F(","));
bluetooth.print(BS_SHT31);
bluetooth.print(F(","));
bluetooth.print(HAM);
bluetooth.print(F(","));
bluetooth.print(BS_BMP_180);
bluetooth.print(F(","));
bluetooth.print(ERROR_C);
bluetooth.println(F("*/")); //for suport of serial studio
}
}
//----------------------
void ELOG(String ELOG_INPUT, bool DATA_HEADER, bool OVER_WRITE = false, bool HM = false)
{
#if Debug >= 3
DebugVal("ELOG_INPUT: ", String(ELOG_INPUT));
DebugVal("DATA_HEADER: ", String(DATA_HEADER));
DebugVal("OVER_WRITE: ", String(OVER_WRITE));
DebugVal("HM: ", String(HM));
#endif
SD_CARD = SD.open(F("Event.log"), FILE_WRITE);
if (!HM)
{
if (SD_EVENT_FILE_EX == true or OVER_WRITE == true)
{
if (DATA_HEADER)
{
SD_CARD.print(F("|"));
SD_CARD.print(t.hour);
SD_CARD.print(F(":"));
SD_CARD.print(t.min);
SD_CARD.print(F("."));
SD_CARD.print(t.sec);
SD_CARD.print(F("|"));
SD_CARD.print(t.mday);
SD_CARD.print(F("/"));
SD_CARD.print(t.mon);
SD_CARD.print(F("/"));
SD_CARD.print(t.year);
SD_CARD.print(F("|"));
SD_CARD.print(F("DATA: "));
}
SD_CARD.println(ELOG_INPUT);
SD_CARD.close();
}
}
else
{
DS3231_get(&t);
SD_CARD.print(F("\n"));
SD_CARD.print(F("|"));
SD_CARD.print(t.hour);
SD_CARD.print(F(":"));
SD_CARD.print(t.min);
SD_CARD.print(F("."));
SD_CARD.print(t.sec);
SD_CARD.print(F("|"));
SD_CARD.print(t.mday);
SD_CARD.print(F("/"));
SD_CARD.print(t.mon);
SD_CARD.print(F("/"));
SD_CARD.print(t.year);
SD_CARD.print(F("|"));
SD_CARD.print(F("WARNING: "));
SD_CARD.println(ELOG_INPUT);
SD_CARD.print(F("\n"));
SD_CARD.close();
}
}
//----------------------
void RAW_TEST()
{
if (BS_SD_CARD)
{
if (SD.exists(F("R_A_W_T")))
{SD.remove(F("R_A_W_T"));}
//RAW
SD_CARD = SD.open(F("R_A_W_T"), FILE_WRITE);
SD_CARD.print(RAW_DATA);