65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#include <Arduino.h>
|
|
#include <TinyGPS++.h>
|
|
#include <SD.h>
|
|
|
|
#include "settings.h"
|
|
#include "random.h"
|
|
// 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"
|
|
#include "gps.h"
|
|
#include "peripheral.h"
|
|
|
|
|
|
void setup() {
|
|
Serial.begin(BAUD_PC);
|
|
Serial.println("[main] Beginning collection sequence.");
|
|
|
|
random_begin();
|
|
|
|
peripheral_register(PIN_SPI_CS_RFM95);
|
|
peripheral_register(PIN_SPI_CS_SD);
|
|
|
|
|
|
gps_begin();
|
|
TinyGPSPlus gps_data = gps_location();
|
|
gps_end();
|
|
|
|
Serial.print("[main] Location: ("); Serial.print(loc.lat()); Serial.print(", "); Serial.print(loc.lng()); Serial.println(")");
|
|
|
|
uint32_t id = random_get();
|
|
|
|
Serial.print("[main] id: ");
|
|
Serial.println(id);
|
|
|
|
// Activate microSD card breakout board on the SPI bus
|
|
peripheral_unsilence(PIN_SPI_CS_SD);
|
|
|
|
store_init();
|
|
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();
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// Activate the RFM95
|
|
peripheral_unsilence(PIN_SPI_CS_RFM95);
|
|
|
|
|
|
|
|
power_off(); // Doesn't return
|
|
}
|
|
|
|
void loop() {
|
|
|
|
}
|