Bugfix: Squash sd card writing issue

This commit is contained in:
Starbeamrainbowlabs 2019-07-11 13:17:01 +01:00
parent f80571e444
commit d0d303bc4b
2 changed files with 10 additions and 6 deletions

View file

@ -69,10 +69,10 @@
#define PIN_SPI_CS_SD 3
// The filename on the microSD card to store data in.
#define SD_FILENAME F("DATA.TSV")
#define SD_FILENAME "DATA.TSV"
// Whether to write debug information to the filename below. This could compromise privacy, so it should be commented out for production.
// #define SD_DEBUG_ENABLED
// The filename on the microSD card to store debug information in
#define SD_FILENAME_DEBUG F("DEBUG.LOG")
#define SD_FILENAME_DEBUG "DEBUG.LOG"

View file

@ -11,14 +11,18 @@
void store_reading(uint32_t id, GPSLocation location) {
SdFat card;
if(!card.begin(PIN_SPI_CS_SD)) {
Serial.println(F("Error: MicroSD card init failed"));
while(true) delay(100);
if(!card.begin(PIN_SPI_CS_SD, SD_SCK_MHZ(50))) {
card.initErrorHalt();
}
// Open the file to write the data to. If it doesn't exist it will be created.
// Unlike elsewhere, FILE_WRITE opens the file with the cursor starting at the end, so it's basically actually equivalent to FILE_APPEND that we use in other environments. Confusing, I know.
File handle = card.open(SD_FILENAME, O_APPEND | O_CREAT | O_WRONLY);
SdFile handle;
if(!handle.open(SD_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
Serial.println(F("Failed to open file"));
while(true) delay(1);
}
uint8_t places = 6;
handle.printField(id, '\t');
handle.printField(location.lat, '\t', places);