2019-06-13 13:13:03 +00:00
# include <Arduino.h>
# include <SD.h>
2019-06-13 13:33:08 +00:00
# include <TinyGPS++.h>
2019-06-13 13:13:03 +00:00
# include "settings.h"
void store_init ( ) {
// NOTE: If this doesn't work, then we need to use pinMode() & specify the data pin here instead.
if ( ! SD . begin ( PIN_SD_SPI_CHIP_SELECT ) ) {
Serial . println ( F ( " Error: Failed to initialise connection to microSD card " ) ) ;
while ( true ) { delay ( 1 ) ; } // Pseudo-halt, but uses delay() to ensure we keep passing back control to allow easy re-programming
}
}
void store_reading ( uint32_t id , TinyGPSLocation location ) {
// 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 ) ;
handle . print ( " \t " ) ;
2019-06-13 13:33:08 +00:00
handle . print ( location . lat ( ) ) ;
2019-06-13 13:13:03 +00:00
handle . print ( " \t " ) ;
2019-06-13 13:33:08 +00:00
handle . print ( location . lng ( ) ) ;
2019-06-13 13:13:03 +00:00
handle . println ( ) ;
handle . close ( ) ;
}
void store_close ( ) {
SD . end ( ) ;
}