Created
April 5, 2016 23:46
-
-
Save joshuajnoble/d6b98554828525959dcd64bbe5b198a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_GPS.h> | |
#include "parsegps.h" | |
#include "tzmaths.h" | |
#include "timezones.h" | |
#include "tz_coords.h" | |
Adafruit_GPS GPS(&Serial2); | |
int get_timezone(long lat, long lon) { | |
int tz; | |
init_get_timezone(lat, lon); | |
while ( (tz = continue_get_timezone(10)) == -1 ) | |
; | |
return tz; | |
} | |
void setup() { | |
// let's get a serial connection | |
while (!Serial) | |
{ | |
Serial.begin(115200); | |
} | |
delay(100); | |
// GPS for the adafruit ultimate GPS | |
GPS.begin(9600); | |
} | |
void loop() { | |
if (GPS.newNMEAreceived()) { | |
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false | |
return; // we can fail to parse a sentence in which case we should just wait for another | |
} | |
// if millis() or timer wraps around, we'll just reset it | |
if (GPS.fix) { | |
long lat = GPS.lat; | |
long lon = GPS.lon; | |
int tz = get_timezone(lat, lon); | |
// minitz has a very particular time/date format it wants | |
int timetz = GPS.seconds + GPS.minute * 100 + GPS.hour * 10000; | |
int date = (GPS.year-2000) + GPS.month * 100 + GPS.day * 10000; | |
// get the time, pass it in as pointers | |
int using_dst = apply_timezone(&timetz, &date, tz); | |
// let's output the correct time! | |
Serial.print(timetz / 10000); | |
Serial.print(":"); | |
Serial.print((timetz / 100) % 100); | |
Serial.print(":"); | |
Serial.print(timetz % 100); | |
Serial.print(" "); | |
Serial.print(using_dst ? "*" : ""); | |
Serial.print(" "); | |
Serial.print(date / 10000); | |
Serial.print("/"); | |
Serial.print((date / 100) % 100); | |
Serial.print("/"); | |
Serial.println(date % 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment