forked from dastcvi/StratoCore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StratoSD.cpp
57 lines (43 loc) · 1.16 KB
/
StratoSD.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
/*
* StratoSD.cpp
* Author: Alex St. Clair
* Created: June 2019
*
* This file implements functions for use running the SD card
* Updated 4/2024 for Teensy 4.1 using SD.h instead of SDFat.h
*/
#include "StratoSD.h"
#include "StratoGroundPort.h"
#include <SD.h>
//#include <SdFatConfig.h>
// globals for internal use
bool sd_state = false;
File file;
//SdFatSdio SD;
bool StartSD()
{
if (SD.begin(BUILTIN_SDCARD)) {
sd_state = true;
} else {
sd_state = false;
}
return sd_state;
}
bool FileWrite(const char * filename, const char * buffer, int buffer_size)
{
int bytes_written = 0;
if (NULL == filename || NULL == buffer || 0 == buffer_size) return false;
if (!sd_state) {
return false;
}
file = SD.open(filename, FILE_WRITE);
debug_serial->print("Filename: "); debug_serial->println(filename);
if (!file) {
debug_serial->println("File not ok");
return false;
}
bytes_written = file.write(buffer, buffer_size);
file.close();
debug_serial->print("File write ok, bytes: "); debug_serial->println(bytes_written);
return (bytes_written == buffer_size);
}