-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdcard.h
51 lines (48 loc) · 1.04 KB
/
sdcard.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
#include <SD.h>
#include <SPI.h>
File telemetryFile;
File logFile;
void SDsetup()
{
if (!SD.begin(BUILTIN_SDCARD)) {
//failed
Serial.println("failure");
SD_works = false;
return;
}
SD_works = true ;
}
void failedWrite (){
// Runs when writing to Sd card fails
SD_works = false;
Serial.println("failure write");
}
void saveTelemetryInSdCard( String telemetryString )
{
// if the file opened okay, write to it:
if ( !SD_works ){
return;
}
telemetryFile = SD.open("telemetry.csv", FILE_WRITE);
if (telemetryFile) {
telemetryFile.println(telemetryString);
telemetryFile.close();
Serial.println("success");
} else {
// Failed to write to file
failedWrite();
}
}
void log( String logdata ){
if ( !SD_works ){
return;
}
logFile = SD.open("logs.txt", FILE_WRITE);
if (logFile) {
logFile.println(logdata);
logFile.close();
} else {
// Failed to write to file
failedWrite();
}
}