Start working on a debug program to test battery life, but it's not finished yet

This commit is contained in:
Starbeamrainbowlabs 2019-06-20 13:56:08 +01:00
parent 79adeef737
commit a4f8ad6138
7 changed files with 52 additions and 5 deletions

View file

@ -11,7 +11,7 @@ void gps_begin() {
serial_gps.begin(BAUD_GPS);
}
TinyGPSLocation gps_location() {
void gps_fetch() {
Serial.print("[gps] Getting location: ");
uint32_t ms_last_update = millis();
// We WILL discover our location - if it's the last thing we do!
@ -41,10 +41,14 @@ TinyGPSLocation gps_location() {
// Hooray!
Serial.println("ok");
return gps.location;
return;
}
}
TinyGPSPlus gps_info() {
return gps;
}
void gps_end() {
Serial.println(F("[warning] Putting the GPS device to sleep isn't implemented yet."));
}

View file

@ -12,11 +12,17 @@
void gps_begin();
/**
* Fetches the current location from the GPS device.
* Fetches new data from the GPS module.
* May take a moment, as the GPS device needs time to acquire a satellite fix.
*/
void gps_fetch();
/**
* Fetches the latest information from the GPS device.
* Call gps_fetch() first.
* @return TinyGPSLocation The current location.
*/
TinyGPSLocation gps_location();
TinyGPSLocation gps_info();
/**
* Ends the connection to the GPS device and puts it to sleep in order to save

View file

@ -1,5 +1,6 @@
#include <Arduino.h>
#include <TinyGPS++.h>
#include <SD.h>
#include "settings.h"
#include "random.h"
@ -16,7 +17,7 @@ void setup() {
gps_begin();
TinyGPSLocation loc = gps_location();
TinyGPSPlus gps_data = gps_location();
gps_end();
Serial.print("[main] Location: ("); Serial.print(loc.lat()); Serial.print(", "); Serial.print(loc.lng()); Serial.println(")");
@ -26,6 +27,23 @@ void setup() {
Serial.print("[main] id: ");
Serial.println(id);
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();
power_off(); // Doesn't return
}
void loop() {

View file

@ -12,8 +12,14 @@ void power_gps_standby() {
}
void power_off() {
Serial.println(F("[power] Beginning shutdown sequence"));
Serial.println(F("[power] Switching GPS module to standby"));
power_gps_standby();
Serial.println(F("[power] Signalling TPL5111"));
pinMode(PIN_TPL_DONE, OUTPUT);
digitalWrite(PIN_TPL_DONE, HIGH);
// Wait until we're turned off
while(true) delay(100);
}

View file

@ -34,4 +34,8 @@
// The chip select pin that activates the connection to the microSD card over SPI.
#define PIN_SD_SPI_CHIP_SELECT 3
// The filename on the microSD card to store data in.
#define SD_FILENAME "data.tsv"
// The filename on the microSD card to store debug information in
#define SD_FILENAME_DEBUG "debug.log"

View file

@ -4,6 +4,8 @@
#include "settings.h"
File _debug_handle;
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)) {
@ -29,6 +31,11 @@ void store_reading(uint32_t id, TinyGPSLocation location) {
handle.close();
}
void store_debug(char* buffer, int size) {
File handle = SD.open(SD_FILENAME_DEBUG, FILE_WRITE);
}
void store_close() {
SD.end();
}

View file

@ -9,4 +9,6 @@ void store_init();
void store_reading(uint32_t id, TinyGPSLocation location);
void store_debug(char* buffer, int size);
void store_close();