Finish SdFat refactor, but it's untested.

This commit is contained in:
Starbeamrainbowlabs 2019-06-27 15:49:39 +01:00
parent 151b9544f2
commit 18342c55fc
1 changed files with 23 additions and 16 deletions

View File

@ -1,36 +1,43 @@
#include <Arduino.h>
#include <SdFat.h>
// #include <ArduinoFiles.h>
#include "settings.h"
#include "gps.h"
SdFat* card = NULL;
// FUTURE: We might be able to trim it down if we disable long filenames with #define USE_LONG_FILE_NAMES 0
SdFat* card = nullptr;
void store_init() {
card = new SdFat();
card->begin(PIN_SPI_CS_SD);
}
void store_reading(uint32_t id, GPSLocation location) {
SdFat card;
card.begin(PIN_SPI_CS_SD);
// Port the rest of this to SdFat from SD
// 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 = SD.open(SD_FILENAME, FILE_WRITE);
File handle = card->open(SD_FILENAME, O_APPEND | O_CREAT | O_WRONLY);
handle.print(id);
handle.print(F("\t"));
char line[33];
int chars = snprintf(line, 33, "%d\t%06d\t%06d\n",
id,
location.lat, location.lng
);
handle.write(line, chars);
handle.print(location.lat);
handle.print(F("\t"));
handle.print(location.lng);
handle.println();
handle.close();
handle.close(); // Syncs implicitly
}
void store_debug(char* buffer, int size) {
File handle = SD.open(SD_FILENAME_DEBUG, FILE_WRITE);
File handle = card->open(SD_FILENAME_DEBUG, O_APPEND | O_CREAT | O_WRONLY);
handle.write(buffer, size);
handle.println();
handle.write('\n');
handle.close();
}
void store_end() {
card.end();
delete card;
}