2019-06-12 19:18:37 +00:00
# include <Arduino.h>
2019-06-13 13:13:03 +00:00
# include <TinyGPS++.h>
2019-06-20 12:56:08 +00:00
# include <SD.h>
2019-06-12 19:18:37 +00:00
# include "settings.h"
2019-06-13 13:33:08 +00:00
# include "random.h"
2019-06-13 13:47:40 +00:00
// BAD PRACTICE: For some extremely strange reason, the Arduino IDE doesn't pick up random.cpp like it does our other source files - so we've got to explicitly include it here. If we had control over the build process (which we don't), we've use a Makefile here that handled this better.
# include "random.cpp"
2019-06-12 19:18:37 +00:00
# include "gps.h"
2019-06-24 12:52:33 +00:00
# include "peripheral.h"
2019-06-12 19:18:37 +00:00
2019-06-13 13:33:08 +00:00
2019-06-12 19:18:37 +00:00
void setup ( ) {
Serial . begin ( BAUD_PC ) ;
2019-06-13 14:10:12 +00:00
Serial . println ( " [main] Beginning collection sequence. " ) ;
2019-06-12 19:18:37 +00:00
2019-06-13 13:33:08 +00:00
random_begin ( ) ;
2019-06-24 12:52:33 +00:00
peripheral_register ( PIN_SPI_CS_RFM95 ) ;
peripheral_register ( PIN_SPI_CS_SD ) ;
2019-06-13 13:33:08 +00:00
2019-06-12 19:18:37 +00:00
gps_begin ( ) ;
2019-06-20 12:56:08 +00:00
TinyGPSPlus gps_data = gps_location ( ) ;
2019-06-13 13:13:03 +00:00
gps_end ( ) ;
2019-06-13 14:10:12 +00:00
Serial . print ( " [main] Location: ( " ) ; Serial . print ( loc . lat ( ) ) ; Serial . print ( " , " ) ; Serial . print ( loc . lng ( ) ) ; Serial . println ( " ) " ) ;
2019-06-12 19:18:37 +00:00
2019-06-13 13:33:08 +00:00
uint32_t id = random_get ( ) ;
2019-06-12 19:18:37 +00:00
2019-06-13 13:33:08 +00:00
Serial . print ( " [main] id: " ) ;
Serial . println ( id ) ;
2019-06-12 19:18:37 +00:00
2019-06-24 12:52:33 +00:00
// Activate microSD card breakout board on the SPI bus
peripheral_unsilence ( PIN_SPI_CS_SD ) ;
store_init ( ) ;
2019-06-20 12:56:08 +00:00
store_reading ( id , gps_data . location ) ;
char debug_message [ 64 ] ;
int chars = snprintf ( debug_message , 64 , " %d-%d-%d %d:%d:%d | %f %f " ,
gps_data . date . year ( ) ,
gps_data . date . month ( ) ,
gps_data . date . day ( ) ,
gps_data . time . hour ( ) ,
gps_data . time . minute ( ) ,
gps_data . time . second ( ) ,
gps_data . location . lat ( ) ,
gps_data . location . lng ( ) ,
) ;
store_debug ( debug_message , chars ) ;
store_close ( ) ;
2019-06-24 12:52:33 +00:00
// ------------------------------------------------------------------------
// Activate the RFM95
peripheral_unsilence ( PIN_SPI_CS_RFM95 ) ;
2019-06-20 12:56:08 +00:00
power_off ( ) ; // Doesn't return
2019-06-12 19:18:37 +00:00
}
void loop ( ) {
}