From 706830dc11580d01a7d25f9b27b2086a9008c82a Mon Sep 17 00:00:00 2001 From: Cody Gray Date: Sun, 5 Jan 2020 18:46:01 -0800 Subject: [PATCH] Enable building for platforms other than Arduino. --- src/TinyGPS++.cpp | 35 +++++++++++++++++++++++++++++++++++ src/TinyGPS++.h | 16 +++++++++++----- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/TinyGPS++.cpp b/src/TinyGPS++.cpp index e1ec777..188a658 100644 --- a/src/TinyGPS++.cpp +++ b/src/TinyGPS++.cpp @@ -27,6 +27,41 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#ifndef ARDUINO +// Enable use of this library on non-Arduino targets by defining symbols that are +// normally provided by the Arduino standard headers (Arduino.h/WProgram.h). + +typedef uint8_t byte; + + +#define _USE_MATH_DEFINES +#include + +#define PI (M_PI) +#define HALF_PI (M_PI / 2.0) +#define TWO_PI (M_PI * 2.0) +#define DEG_TO_RAD (M_PI / 180.0) +#define RAD_TO_DEG (180.0 / M_PI) + +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + + +#include + +unsigned long millis() +{ + // Standards-compliant replacement for Arduino-specific millis() function: + // uses C++11's std::chrono::steady_clock, which is roughly equivalent + // to clock_gettime(CLOCK_MONOTONIC, ...) in POSIX C. + using namespace std::chrono; + const auto now = time_point_cast(system_clock::now()); + const auto ms = now.time_since_epoch().count(); + return static_cast(ms); +} +#endif // !ARDUINO + #define _GPRMCterm "GPRMC" #define _GPGGAterm "GPGGA" #define _GNRMCterm "GNRMC" diff --git a/src/TinyGPS++.h b/src/TinyGPS++.h index 60485cb..6b81b76 100644 --- a/src/TinyGPS++.h +++ b/src/TinyGPS++.h @@ -24,12 +24,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #ifndef __TinyGPSPlus_h #define __TinyGPSPlus_h -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" +#if defined (ARDUINO) +#if ARDUINO >= 100 + #include "Arduino.h" #else -#include "WProgram.h" -#endif -#include + #include "WProgram.h" +#endif // ARDUINO >= 100 +#else + #include + #include + + unsigned long millis(); +#endif // ARDUINO #define _GPS_VERSION "1.0.2" // software version of this library #define _GPS_MPH_PER_KNOT 1.15077945