#include <TinyGPS++.h>
#include <softSerial.h>
// Display stuff
#include <Wire.h>
#include <HT_SH1107Wire.h>
/*
This is a modified version of the sample code provided with the TinyGPS++ library that
demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object. It requires the use of
SoftwareSerial, and assumes that a 9600 baud serial GPS device is connected to
CubeCell Plus pins RX2(rx) and TX2(tx). It has been extended to display a subset of
data on the CubeCell Plus display.
*/
static const uint32_t GPSBaud = 9600;
float gpsLatitude = 0.0;
float gpsLongitude = 0.0;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
softSerial ss(UART_TX2 /*TX pin*/, UART_RX2 /*RX pin*/);
// Teh display object
SH1107Wire display(0x3C, 500000, SDA, SCL ,GEOMETRY_128_64, GPIO10); // addr, freq, sda, scl, resolution, rst
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
static void printFloat(float val, bool valid, int len, int prec)
{
if (!valid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i 0)
sz[len-1] = ' ';
Serial.print(sz);
smartDelay(0);
}
static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
if (!d.isValid())
{
Serial.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
Serial.print(sz);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 45, sz);
}
if (!t.isValid())
{
Serial.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
Serial.print(sz);
display.setFont(ArialMT_Plain_10);
display.drawString(64, 45, sz);
}
printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}
static void printStr(const char *str, int len)
{
int slen = strlen(str);
for (int i=0; i 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}
|