-
Notifications
You must be signed in to change notification settings - Fork 0
/
SD_functions.ino
82 lines (69 loc) · 1.93 KB
/
SD_functions.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
void initialise_SD() {
if (!SD.begin(4)) {
Serial.println("SD error");
while (1 == 1) { //if there is something wrong, just keep blinking
blink_wildly(1000);
}
return;
}
else {
Serial.println("SD ok");
delay(300);
SD_ok = true;
//write startup line to logfile
SDcard = SD.open("specylog.csv", O_CREAT | O_WRITE);
SDcard.print(getDateRTC());
SDcard.print(";");
SDcard.print(getTimeRTC());
SDcard.print(";temp=;");
SDcard.print(sts_get_temp(0));
SDcard.print(";Version 0.1;");
SDcard.print("save_every_s=;");
SDcard.println(spec_every_sec);
SDcard.close();
}
}
String set_dir_and_file() {
getDateRTC().toCharArray(current_path, 8);
//creates the current working directory
if (SD.mkdir(current_path)) {
Serial.print(current_path);
Serial.println(" DIR ok");
delay(500);
}
else {
Serial.print(current_path);
Serial.println(" DIR error");
while (1 == 1) { //if there is something wrong, just keep blinking
blink_wildly(1000);
}
}
//sets the current_file name inside the directory
String current_file = getDateRTC() + "/" + getTimeRTC() + ".csv";
current_file.toCharArray(current_file_name, 18); //current_file_name is a global variable
//Serial.println(current_file);
return current_file;
}
void save_to_sd() {
SDcard = SD.open(current_file_name, O_CREAT | O_WRITE);
SDcard.print(getDateRTC());
SDcard.print(";");
SDcard.print(getTimeRTC());
SDcard.print(";");
SDcard.print("ms_since_start=;");
SDcard.print(millis());
SDcard.print(";temp=;");
SDcard.print(sts_get_temp(0));
SDcard.print(";IT=;");
SDcard.print(int_time);
SDcard.print(";spec num=;");
SDcard.print(cycle_number);
SDcard.print(";");
for (int i = 0; i < 1024; i += 2) {
SDcard.print(word(spectrum[i + 1], spectrum[i]));
SDcard.print(";");
}
SDcard.println(";");
SDcard.close();
Serial.println("spec saved");
}