2019-06-13 13:13:03 +00:00
# include <Arduino.h>
2019-06-26 17:08:42 +00:00
# include <SdFat.h>
2019-06-13 13:13:03 +00:00
# include "settings.h"
2019-06-26 14:46:07 +00:00
# include "gps.h"
2019-06-20 12:56:08 +00:00
2019-06-26 17:08:42 +00:00
SdFat * card = NULL ;
2019-06-13 13:13:03 +00:00
2019-06-26 14:46:07 +00:00
void store_reading ( uint32_t id , GPSLocation location ) {
2019-06-26 17:08:42 +00:00
SdFat card ;
2019-06-26 18:34:29 +00:00
card . begin ( PIN_SPI_CS_SD ) ;
// Port the rest of this to SdFat from SD
2019-06-13 13:13:03 +00:00
// 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 ) ;
handle . print ( id ) ;
2019-06-26 14:46:07 +00:00
handle . print ( F ( " \t " ) ) ;
2019-06-13 13:13:03 +00:00
2019-06-26 14:46:07 +00:00
handle . print ( location . lat ) ;
handle . print ( F ( " \t " ) ) ;
2019-06-13 13:13:03 +00:00
2019-06-26 14:46:07 +00:00
handle . print ( location . lng ) ;
2019-06-13 13:13:03 +00:00
handle . println ( ) ;
handle . close ( ) ;
}
2019-06-20 12:56:08 +00:00
void store_debug ( char * buffer , int size ) {
File handle = SD . open ( SD_FILENAME_DEBUG , FILE_WRITE ) ;
2019-06-26 14:46:07 +00:00
handle . write ( buffer , size ) ;
handle . println ( ) ;
handle . close ( ) ;
2019-06-20 12:56:08 +00:00
}