From a8f9be7907fb1ab27a5962ec9eb0ff6570b8d5d8 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Thu, 15 Mar 2018 16:05:07 -0700 Subject: [PATCH 01/41] Add issue template --- docs/issue_template.md | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 docs/issue_template.md diff --git a/docs/issue_template.md b/docs/issue_template.md new file mode 100644 index 0000000..0610992 --- /dev/null +++ b/docs/issue_template.md @@ -0,0 +1,64 @@ +Please use this form only to report code defects or bugs. + +For any question, even questions directly pertaining to this code, post your question on the forums related to the board you are using. + +Arduino: forum.arduino.cc +Teensy: forum.pjrc.com +ESP8266: www.esp8266.com +ESP32: www.esp32.com +Adafruit Feather/Metro/Trinket: forums.adafruit.com +Particle Photon: community.particle.io + +If you are experiencing trouble but not certain of the cause, or need help using this code, ask on the appropriate forum. This is not the place to ask for support or help, even directly related to this code. Only use this form you are certain you have discovered a defect in this code! + +Please verify the problem occurs when using the very latest version, using the newest version of Arduino and any other related software. + + +----------------------------- Remove above ----------------------------- + + + +### Description + +Describe your problem. + + + +### Steps To Reproduce Problem + +Please give detailed instructions needed for anyone to attempt to reproduce the problem. + + + +### Hardware & Software + +Board +Shields / modules used +Arduino IDE version +Teensyduino version (if using Teensy) +Version info & package name (from Tools > Boards > Board Manager) +Operating system & version +Any other software or hardware? + + +### Arduino Sketch + +```cpp +// Change the code below by your sketch (please try to give the smallest code which demonstrates the problem) +#include + +// libraries: give links/details so anyone can compile your code for the same result + +void setup() { +} + +void loop() { +} +``` + + +### Errors or Incorrect Output + +If you see any errors or incorrect output, please show it here. Please use copy & paste to give an exact copy of the message. Details matter, so please show (not merely describe) the actual message or error exactly as it appears. + + From 8ac0830c1e6f3cd627582f0085aa171161f6bbc2 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 27 Jan 2019 17:07:44 -0800 Subject: [PATCH 02/41] Don't define strcpy_P if already defined --- DateStrings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DateStrings.cpp b/DateStrings.cpp index 3eccff3..b82f6bc 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -17,8 +17,10 @@ #define PGM_P const char * #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned char **)(addr)) +#ifndef strcpy_P #define strcpy_P(dest, src) strcpy((dest), (src)) #endif +#endif #include // for strcpy_P or strcpy #include "TimeLib.h" From 50a56f266b6565adb8ecc38a4c20ee634cacfe19 Mon Sep 17 00:00:00 2001 From: "DESKTOP-MK92NDD\\huyat" Date: Mon, 28 Jan 2019 10:47:34 +0700 Subject: [PATCH 03/41] Fix error grammar --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 795d26e..ee44912 100644 --- a/Readme.md +++ b/Readme.md @@ -90,10 +90,10 @@ illustrating how the library can be used with various time sources: if it is running and connected to the Arduino serial port. - `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above - Short (3 character) and long strings are available to print the days of + Short (3 characters) and long strings are available to print the days of the week and names of the months. -- `TimeRTC` uses a DS1307 real time clock to provide time synchronization. +- `TimeRTC` uses a DS1307 real-time clock to provide time synchronization. A basic RTC library named DS1307RTC is included in the download. To run this sketch the DS1307RTC library must be installed. From 81b3192047cd4a7372a7b79d610506e7b3b0b3d5 Mon Sep 17 00:00:00 2001 From: Bollie Date: Thu, 14 Mar 2019 19:58:33 +0100 Subject: [PATCH 04/41] strcpy_P not needed for ESP8266/2.5.0-beta2 sdk --- DateStrings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DateStrings.cpp b/DateStrings.cpp index b82f6bc..87766df 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -17,10 +17,12 @@ #define PGM_P const char * #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned char **)(addr)) +#ifndef ESP8266 #ifndef strcpy_P #define strcpy_P(dest, src) strcpy((dest), (src)) #endif #endif +#endif #include // for strcpy_P or strcpy #include "TimeLib.h" From 2c08bcc7bea1d96cca55fcdfee0e68cda3d83fe0 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 11 May 2019 12:45:31 -0700 Subject: [PATCH 05/41] Fix bad URL in library.properties Use of incorrect case in the Arduino Playground URL resulted in a redirect to the Playground home page instead of the expected Time library page. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 49b1e2a..19fdf3b 100644 --- a/library.properties +++ b/library.properties @@ -5,6 +5,6 @@ maintainer=Paul Stoffregen sentence=Timekeeping functionality for Arduino paragraph=Date and Time functions, with provisions to synchronize to external time sources like GPS and NTP (Internet). This library is often used together with TimeAlarms and DS1307RTC. category=Timing -url=http://playground.arduino.cc/code/time +url=http://playground.arduino.cc/Code/Time/ architectures=* From 28f706760fbc8b16aa5324886aa6cf85b73ae02c Mon Sep 17 00:00:00 2001 From: Daniel Bates Date: Fri, 31 May 2019 09:50:42 +0100 Subject: [PATCH 06/41] Update DateStrings.cpp This now compiles on ESP platform v2.4.2 and v2.5.2 on Arduino IDE 1.8.9 and 1.9.0 beta. I've also uploaded to example to ESP8266 to double check and works fine. --- DateStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 87766df..131d4fe 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -17,7 +17,7 @@ #define PGM_P const char * #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned char **)(addr)) -#ifndef ESP8266 +#ifdef ESP8266 #ifndef strcpy_P #define strcpy_P(dest, src) strcpy((dest), (src)) #endif From d4fafb2c06c41a5ddf18f351bf30c5e22e1e7d2e Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Tue, 11 Jun 2019 06:59:54 -0700 Subject: [PATCH 07/41] Add more explicit comments about Processing to SyncArduinoClock fixes #133 --- .../Processing/SyncArduinoClock/SyncArduinoClock.pde | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde b/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde index 4313be3..62ee57b 100644 --- a/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde +++ b/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde @@ -1,8 +1,17 @@ /** * SyncArduinoClock. * + * SyncArduinoClock is a Processing sketch that responds to Arduino + * requests for time synchronization messages. Run this in the + * Processing environment (not in Arduino) on your PC or Mac. + * + * Download TimeSerial onto Arduino and you should see the time + * message displayed when you run SyncArduinoClock in Processing. + * The Arduino time is set from the time on your computer through the + * Processing sketch. + * * portIndex must be set to the port connected to the Arduino - * + * * The current time is sent in response to request message from Arduino * or by clicking the display window * From 15af8499552fd8505ab801f67a2106eb947508f1 Mon Sep 17 00:00:00 2001 From: venice1200 <43762187+venice1200@users.noreply.github.com> Date: Mon, 1 Jul 2019 17:20:04 +0200 Subject: [PATCH 08/41] Added ESP32 --- DateStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 131d4fe..062b9eb 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -17,7 +17,7 @@ #define PGM_P const char * #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned char **)(addr)) -#ifdef ESP8266 +#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32) #ifndef strcpy_P #define strcpy_P(dest, src) strcpy((dest), (src)) #endif From f11f6fc1de7f08ce8c3ce9946be0836b037a58b2 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 11 Aug 2019 17:11:48 -0700 Subject: [PATCH 09/41] Improve DateStrings, reply on Arduino.h to define PROGMEM, etc --- DateStrings.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 062b9eb..2424678 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -9,22 +9,18 @@ * */ -#if defined(__AVR__) -#include -#else -// for compatiblity with Arduino Due and Teensy 3.0 and maybe others? +#include + +// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr +// But not all platforms define these as they should. If you find a platform needing these +// defined, or if any this becomes unnecessary as platforms improve, please send a pull req. +#if defined(ESP8266) +#undef PROGMEM #define PROGMEM -#define PGM_P const char * -#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#define pgm_read_word(addr) (*(const unsigned char **)(addr)) -#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32) -#ifndef strcpy_P -#define strcpy_P(dest, src) strcpy((dest), (src)) -#endif -#endif #endif -#include // for strcpy_P or strcpy + #include "TimeLib.h" + // the short strings for each day or month must be exactly dt_SHORT_STR_LEN #define dt_SHORT_STR_LEN 3 // the length of short strings @@ -73,7 +69,7 @@ const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat"; char* monthStr(uint8_t month) { - strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month]))); + strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month]))); return buffer; } @@ -87,7 +83,7 @@ char* monthShortStr(uint8_t month) char* dayStr(uint8_t day) { - strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day]))); + strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day]))); return buffer; } From c0436e64c1b6db078deff5371a26edcac91133b7 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Wed, 11 Dec 2019 08:27:28 -0800 Subject: [PATCH 10/41] Bump version to 1.6 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 6603650..1ea5293 100644 --- a/library.json +++ b/library.json @@ -17,7 +17,7 @@ "type": "git", "url": "https://github.com/PaulStoffregen/Time" }, - "version": "1.5", + "version": "1.6", "homepage": "http://playground.arduino.cc/Code/Time", "frameworks": "Arduino", "examples": [ diff --git a/library.properties b/library.properties index 19fdf3b..1693db8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Time -version=1.5 +version=1.6 author=Michael Margolis maintainer=Paul Stoffregen sentence=Timekeeping functionality for Arduino From 0723137212c000288c964ccfd4f0f5eed7911e5e Mon Sep 17 00:00:00 2001 From: pieterbl <30773488+pieterbl@users.noreply.github.com> Date: Mon, 10 Feb 2020 08:21:26 +0100 Subject: [PATCH 11/41] Update Readme.md Update Readme.md - minor text alignment --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index ee44912..4ed4e05 100644 --- a/Readme.md +++ b/Readme.md @@ -148,7 +148,7 @@ Low level functions to convert between system time and individual time elements ```c breakTime(time, &tm); // break time_t into elements stored in tm struct -makeTime(&tm); // return time_t from elements stored in tm struct +makeTime(&tm); // return time_t from elements stored in tm struct ``` The DS1307RTC library included in the download provides an example of how a time provider From d788757ea29a79e4f03968a1cfd04e2d0cf39044 Mon Sep 17 00:00:00 2001 From: pieterbl <30773488+pieterbl@users.noreply.github.com> Date: Mon, 10 Feb 2020 08:26:26 +0100 Subject: [PATCH 12/41] Update Readme.md Update Readme.md - put code-quotes around some types/identifiers --- Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 4ed4e05..db399fd 100644 --- a/Readme.md +++ b/Readme.md @@ -66,8 +66,8 @@ timeNeedsSync // the time had been set but a sync attempt did timeSet // the time is set and is synced ``` -Time and Date values are not valid if the status is timeNotSet. Otherwise, values can be used but -the returned time may have drifted if the status is timeNeedsSync. +Time and Date values are not valid if the status is `timeNotSet`. Otherwise, values can be used but +the returned time may have drifted if the status is `timeNeedsSync`. ```c setSyncProvider(getTimeFunction); // set the external time provider @@ -140,8 +140,8 @@ See the sketches in the examples directory for usage. The default interval for re-syncing the time is 5 minutes but can be changed by calling the `setSyncInterval(interval)` method to set the number of seconds between re-sync attempts. -The Time library defines a structure for holding time elements that is a compact version of the C tm structure. -All the members of the Arduino tm structure are bytes and the year is offset from 1970. +The Time library defines a structure for holding time elements that is a compact version of the C `tm` structure. +All the members of the Arduino `tm` structure are bytes and the year is offset from 1970. Convenience macros provide conversion to and from the Arduino format. Low level functions to convert between system time and individual time elements are provided: From 286d443e01d05c2e233e763426996152956efc87 Mon Sep 17 00:00:00 2001 From: pieterbl <30773488+pieterbl@users.noreply.github.com> Date: Mon, 10 Feb 2020 08:28:16 +0100 Subject: [PATCH 13/41] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index db399fd..52126c7 100644 --- a/Readme.md +++ b/Readme.md @@ -144,7 +144,7 @@ The Time library defines a structure for holding time elements that is a compact All the members of the Arduino `tm` structure are bytes and the year is offset from 1970. Convenience macros provide conversion to and from the Arduino format. -Low level functions to convert between system time and individual time elements are provided: +Low-level functions to convert between system time and individual time elements are provided: ```c breakTime(time, &tm); // break time_t into elements stored in tm struct From 7acd24427ad55e815319ba11a274ff8a6521a1eb Mon Sep 17 00:00:00 2001 From: pieterbl Date: Mon, 10 Feb 2020 19:33:18 +0100 Subject: [PATCH 14/41] Several punctuation fixes, add pointer to DS1307RTC lib. The current (old) description claimded that the DS1307RTC library is part of the download bundle, which is not (no longer?) the case. Instead pointing to following now: https://github.com/PaulStoffregen/DS1307RTC Change-Id: I28b0c71398e56d50de0c786e4dee97d28f408481 --- Readme.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Readme.md b/Readme.md index 52126c7..10a32a0 100644 --- a/Readme.md +++ b/Readme.md @@ -89,15 +89,15 @@ illustrating how the library can be used with various time sources: A companion Processing sketch will automatically provide these messages if it is running and connected to the Arduino serial port. -- `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above +- `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above. Short (3 characters) and long strings are available to print the days of the week and names of the months. - `TimeRTC` uses a DS1307 real-time clock to provide time synchronization. - A basic RTC library named DS1307RTC is included in the download. - To run this sketch the DS1307RTC library must be installed. + The basic [DS1307RTC library][1] must be downloaded and installed, + in order to run this sketch. -- `TimeRTCSet` is similar to the above and adds the ability to set the Real Time Clock +- `TimeRTCSet` is similar to the above and adds the ability to set the Real Time Clock. - `TimeRTCLog` demonstrates how to calculate the difference between times. It is a very simple logger application that monitors events on digital pins @@ -106,11 +106,11 @@ illustrating how the library can be used with various time sources: - `TimeNTP` uses the Arduino Ethernet shield to access time using the internet NTP time service. The NTP protocol uses UDP and the UdpBytewise library is required, see: - http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/ + -- `TimeGPS` gets time from a GPS +- `TimeGPS` gets time from a GPS. This requires the TinyGPS library from Mikal Hart: - http://arduiniana.org/libraries/TinyGPS + ## Differences @@ -126,7 +126,7 @@ Changes in the Time library API: - function added to automatically sync time with external source - `localTime` and `maketime` parameters changed, `localTime` renamed to `breakTime` -## Technical notes: +## Technical Notes Internal system time is based on the standard Unix `time_t`. The value is the number of seconds since Jan 1, 1970. @@ -151,5 +151,7 @@ breakTime(time, &tm); // break time_t into elements stored in tm struct makeTime(&tm); // return time_t from elements stored in tm struct ``` -The DS1307RTC library included in the download provides an example of how a time provider +This [DS1307RTC library][1] provides an example of how a time provider can use the low-level functions to interface with the Time library. + +[1]: From 3d5114d04b37bf53c40c6d6157179c05fc88255f Mon Sep 17 00:00:00 2001 From: pieterbl Date: Tue, 11 Feb 2020 23:09:38 +0100 Subject: [PATCH 15/41] Fixed typos in TimeLib.h and Time.cpp Change-Id: Ia05c370e8f09b75dddf11cf2aa8b5de4c21bd45d --- Time.cpp | 6 +++--- TimeLib.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Time.cpp b/Time.cpp index 8e53e56..0dcb29f 100644 --- a/Time.cpp +++ b/Time.cpp @@ -141,9 +141,9 @@ int year(time_t t) { // the year for the given time /*============================================================================*/ /* functions to convert to and from system time */ -/* These are for interfacing with time serivces and are not normally needed in a sketch */ +/* These are for interfacing with time services and are not normally needed in a sketch */ -// leap year calulator expects year argument as years offset from 1970 +// leap year calculator expects year argument as years offset from 1970 #define LEAP_YEAR(Y) ( ((1970+(Y))>0) && !((1970+(Y))%4) && ( ((1970+(Y))%100) || !((1970+(Y))%400) ) ) static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0 @@ -213,7 +213,7 @@ time_t makeTime(const tmElements_t &tm){ seconds= tm.Year*(SECS_PER_DAY * 365); for (i = 0; i < tm.Year; i++) { if (LEAP_YEAR(i)) { - seconds += SECS_PER_DAY; // add extra days for leap years + seconds += SECS_PER_DAY; // add extra days for leap years } } diff --git a/TimeLib.h b/TimeLib.h index 20e2445..b587046 100644 --- a/TimeLib.h +++ b/TimeLib.h @@ -80,7 +80,7 @@ typedef time_t(*getExternalTime)(); #define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970 #define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight // The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971 -// Always set the correct time before settting alarms +// Always set the correct time before setting alarms #define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day #define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day #define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1 From 416d009dd4dfda4447bff4dc5f8e5ea5cfac8dbf Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sat, 4 Apr 2020 10:27:20 -0700 Subject: [PATCH 16/41] Update readme with include header, fixes #101 --- Readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Readme.md b/Readme.md index 10a32a0..ea29b70 100644 --- a/Readme.md +++ b/Readme.md @@ -14,6 +14,12 @@ for time synchronization. ## Functionality +To use the Time library in an Arduino sketch, include TimeLib.h. + +```c +#include +``` + The functions available in the library include ```c From ebda9bdf134913ee8384e93dd2281994af14d796 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sat, 4 Apr 2020 10:30:25 -0700 Subject: [PATCH 17/41] Update readme with specific info about Arduino Library Manager --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index ea29b70..ba47aeb 100644 --- a/Readme.md +++ b/Readme.md @@ -2,6 +2,8 @@ Time is a library that provides timekeeping functionality for Arduino. +Using the Arduino Library Manager, install "*Time* by *Michael Margolis*". + The code is derived from the Playground DateTime library but is updated to provide an API that is more flexible and easier to use. From d1e76388b1e9c8041a45e05a9ef767d22f799ed1 Mon Sep 17 00:00:00 2001 From: Majenko Technologies Date: Sat, 25 Apr 2020 18:56:33 +0100 Subject: [PATCH 18/41] Added includes to properties file The Arduino library.properties specification gives the `includes` entry: * **includes - (available from Arduino IDE 1.6.10) (optional)** a comma separated list of files to be added to the sketch as #include <...> lines. This property is used with the "Include library" command in the Arduino IDE. If the includes property is missing, all the header files (.h) on the root source folder are included. Adding this will prevent both Time.h and TimeLib.h from being included in the IDE with the include library menu option. --- library.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/library.properties b/library.properties index 1693db8..2c5d58c 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,6 @@ sentence=Timekeeping functionality for Arduino paragraph=Date and Time functions, with provisions to synchronize to external time sources like GPS and NTP (Internet). This library is often used together with TimeAlarms and DS1307RTC. category=Timing url=http://playground.arduino.cc/Code/Time/ +includes=TimeLib.h architectures=* From 410aee4fda01c7ab03aa032c9dc50641633e2d4f Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Tue, 5 May 2020 04:43:12 -0700 Subject: [PATCH 19/41] Add deprecated Time.h warning --- Time.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Time.h b/Time.h index a79b080..6fa02fa 100644 --- a/Time.h +++ b/Time.h @@ -1 +1,2 @@ +#warning "Please include TimeLib.h, not Time.h. Future versions will remove Time.h" #include "TimeLib.h" From 6dccf933e4dcf4f62b815f67341241d72d00ec1e Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:18:30 +0200 Subject: [PATCH 20/41] Update Time.cpp --- Time.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Time.cpp b/Time.cpp index 0dcb29f..cc9369a 100644 --- a/Time.cpp +++ b/Time.cpp @@ -33,7 +33,10 @@ #include #endif -#include "TimeLib.h" +#define TIMELIB_ENABLE_MILLIS +#define usePPS + +#include "microTimeLib.h" static tmElements_t tm; // a cache of time elements static time_t cacheTime; // the time the cache was updated @@ -246,13 +249,28 @@ getExternalTime getTimePtr; // pointer to external sync function time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync #endif +#ifdef usePPS +void SyncToPPS() +{ + sysTime++; + prevMicros = micros(); +} +#endif time_t now() { - // calculate number of seconds passed since last call to now() - while (millis() - prevMillis >= 1000) { - // millis() and prevMillis are both unsigned ints thus the subtraction will always be the absolute value of the difference + uint32_t sysTimeMicros; + return now(sysTimeMicros); +} + +time_t now(uint32_t& sysTimeMicros) { + // calculate number of seconds passed since last call to now() + while ((sysTimeMicros = micros() - prevMicros) >= 1000000) { + while ((sysTimeMicros = micros() - prevMicros) >= 1000000) { + // micros() and prevMicros are both unsigned ints thus the subtraction will + // always result in a positive difference. This is OK since it corrects for + // wrap-around and micros() is monotonic. sysTime++; - prevMillis += 1000; + prevMicros += 1000000; #ifdef TIME_DRIFT_INFO sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift #endif @@ -280,7 +298,9 @@ void setTime(time_t t) { sysTime = (uint32_t)t; nextSyncTime = (uint32_t)t + syncInterval; Status = timeSet; - prevMillis = millis(); // restart counting from now (thanks to Korman for this fix) + #ifndef usePPS + prevMicros = micros(); // restart counting from now (thanks to Korman for this fix) + #endif } void setTime(int hr,int min,int sec,int dy, int mnth, int yr){ From fa4535ea4c1ce4371b2eac2d017a84e7c8024624 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:20:13 +0200 Subject: [PATCH 21/41] Update TimeLib.h --- TimeLib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TimeLib.h b/TimeLib.h index b587046..470f343 100644 --- a/TimeLib.h +++ b/TimeLib.h @@ -21,6 +21,8 @@ typedef unsigned long time_t; #endif +#define usePPS +#define TIMELIB_ENABLE_MILLIS // This ugly hack allows us to define C++ overloaded functions, when included // from within an extern "C", as newlib's sys/stat.h does. Actually it is @@ -118,6 +120,14 @@ int year(); // the full four digit year: (2009, 2010 etc) int year(time_t t); // the year for the given time time_t now(); // return the current time as seconds since Jan 1 1970 + +#ifdef TIMELIB_ENABLE_MILLIS +time_t now(uint32_t& sysTimeMicros); // return the current time as seconds and microseconds since Jan 1 1970 +#endif +#ifdef usePPS +void syncToPPS(); +#endif + void setTime(time_t t); void setTime(int hr,int min,int sec,int day, int month, int yr); void adjustTime(long adjustment); From 58bb5cd40c4c651297da287000bcd46a0a12ec21 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:20:51 +0200 Subject: [PATCH 22/41] Update DateStrings.cpp --- DateStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 2424678..73630dc 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -19,7 +19,7 @@ #define PROGMEM #endif -#include "TimeLib.h" +#include "microTimeLib.h" // the short strings for each day or month must be exactly dt_SHORT_STR_LEN From ae9fb0a6137ff5b2a15f59446b938ee0e9fad3e5 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:22:34 +0200 Subject: [PATCH 23/41] Rename Time.cpp to microTime.cpp --- Time.cpp => microTime.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Time.cpp => microTime.cpp (100%) diff --git a/Time.cpp b/microTime.cpp similarity index 100% rename from Time.cpp rename to microTime.cpp From dd135e9b0a2b8bf154745634ce27f809d276d07d Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:22:50 +0200 Subject: [PATCH 24/41] Rename TimeLib.h to microTimeLib.h --- TimeLib.h => microTimeLib.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TimeLib.h => microTimeLib.h (100%) diff --git a/TimeLib.h b/microTimeLib.h similarity index 100% rename from TimeLib.h rename to microTimeLib.h From 91ee40d0e0aa82958f5df271271e92337ea2f855 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:25:34 +0200 Subject: [PATCH 25/41] Rename microTimeLib.h to microTime.h --- microTimeLib.h => microTime.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename microTimeLib.h => microTime.h (100%) diff --git a/microTimeLib.h b/microTime.h similarity index 100% rename from microTimeLib.h rename to microTime.h From e83c24b4b370a0085c00f4a830e11e03df345fa4 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:29:10 +0200 Subject: [PATCH 26/41] Rename microTime.h to microTimeLib.h --- microTime.h => microTimeLib.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename microTime.h => microTimeLib.h (100%) diff --git a/microTime.h b/microTimeLib.h similarity index 100% rename from microTime.h rename to microTimeLib.h From ca25f95e7e5572874b557cc9d0ea7fe7cd0b51ab Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:29:41 +0200 Subject: [PATCH 27/41] Update and rename Time.h to microTime.h --- Time.h | 2 -- microTime.h | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 Time.h create mode 100644 microTime.h diff --git a/Time.h b/Time.h deleted file mode 100644 index 6fa02fa..0000000 --- a/Time.h +++ /dev/null @@ -1,2 +0,0 @@ -#warning "Please include TimeLib.h, not Time.h. Future versions will remove Time.h" -#include "TimeLib.h" diff --git a/microTime.h b/microTime.h new file mode 100644 index 0000000..e98a0c3 --- /dev/null +++ b/microTime.h @@ -0,0 +1 @@ +#include "microTimeLib.h" From 1f67cdce1fc25e122738f722ac2b0a08adde5a83 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:34:48 +0200 Subject: [PATCH 28/41] Update microTime.cpp --- microTime.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/microTime.cpp b/microTime.cpp index cc9369a..a0d1d9b 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -250,8 +250,7 @@ time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync #endif #ifdef usePPS -void SyncToPPS() -{ +void IRAM_ATTR SyncToPPS() { sysTime++; prevMicros = micros(); } From 348d9f2a3f1ae270dadc0e8b3af8e1161ed54457 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:35:07 +0200 Subject: [PATCH 29/41] Update microTime.h --- microTime.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microTime.h b/microTime.h index e98a0c3..a79b080 100644 --- a/microTime.h +++ b/microTime.h @@ -1 +1 @@ -#include "microTimeLib.h" +#include "TimeLib.h" From ea3966c8c9a59a0d34709472a9c92fb7b64fdd08 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:35:57 +0200 Subject: [PATCH 30/41] Update and rename microTimeLib.h to TimeLib.h --- microTimeLib.h => TimeLib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename microTimeLib.h => TimeLib.h (99%) diff --git a/microTimeLib.h b/TimeLib.h similarity index 99% rename from microTimeLib.h rename to TimeLib.h index 470f343..39b092f 100644 --- a/microTimeLib.h +++ b/TimeLib.h @@ -125,7 +125,7 @@ time_t now(); // return the current time as seconds since Jan 1 197 time_t now(uint32_t& sysTimeMicros); // return the current time as seconds and microseconds since Jan 1 1970 #endif #ifdef usePPS -void syncToPPS(); +void IRAM_ATTR SyncToPPS(); #endif void setTime(time_t t); From 0cb0e1b20b5f2d1f4ee649a13ca1add5bf7e0550 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:39:22 +0200 Subject: [PATCH 31/41] Update DateStrings.cpp --- DateStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 73630dc..2424678 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -19,7 +19,7 @@ #define PROGMEM #endif -#include "microTimeLib.h" +#include "TimeLib.h" // the short strings for each day or month must be exactly dt_SHORT_STR_LEN From e368d02f0909f4388549a698255b1d3f3cf20a88 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:40:26 +0200 Subject: [PATCH 32/41] Update microTime.cpp --- microTime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microTime.cpp b/microTime.cpp index a0d1d9b..4a38ebe 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -36,7 +36,7 @@ #define TIMELIB_ENABLE_MILLIS #define usePPS -#include "microTimeLib.h" +#include "TimeLib.h" static tmElements_t tm; // a cache of time elements static time_t cacheTime; // the time the cache was updated From c1f8d2978562cacfd97fca21e7fc853021967705 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:43:45 +0200 Subject: [PATCH 33/41] Update microTime.cpp --- microTime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microTime.cpp b/microTime.cpp index 4a38ebe..7a5812d 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -238,7 +238,7 @@ time_t makeTime(const tmElements_t &tm){ /* Low level system time functions */ static uint32_t sysTime = 0; -static uint32_t prevMillis = 0; +static uint32_t prevMicros = 0; static uint32_t nextSyncTime = 0; static timeStatus_t Status = timeNotSet; From a9cf9663ccdccb96832b7256f4224e4acfd96b37 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 18:45:17 +0200 Subject: [PATCH 34/41] Update microTime.cpp --- microTime.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/microTime.cpp b/microTime.cpp index 7a5812d..ef68812 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -263,7 +263,6 @@ time_t now() { time_t now(uint32_t& sysTimeMicros) { // calculate number of seconds passed since last call to now() - while ((sysTimeMicros = micros() - prevMicros) >= 1000000) { while ((sysTimeMicros = micros() - prevMicros) >= 1000000) { // micros() and prevMicros are both unsigned ints thus the subtraction will // always result in a positive difference. This is OK since it corrects for From 4f4cd44875c1c54e96ecef0c33f226a7a0df07df Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Mon, 3 May 2021 21:37:56 +0200 Subject: [PATCH 35/41] Update microTime.cpp --- microTime.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/microTime.cpp b/microTime.cpp index ef68812..c240d5f 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -263,17 +263,16 @@ time_t now() { time_t now(uint32_t& sysTimeMicros) { // calculate number of seconds passed since last call to now() - while ((sysTimeMicros = micros() - prevMicros) >= 1000000) { - // micros() and prevMicros are both unsigned ints thus the subtraction will - // always result in a positive difference. This is OK since it corrects for - // wrap-around and micros() is monotonic. - sysTime++; - prevMicros += 1000000; + uint32_t n_secs = (micros() - prevMicros) / 1000000U; + sysTime += n_secs; + prevMicros += n_secs * 1000000U; + #ifdef TIME_DRIFT_INFO - sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift + sysUnsyncedTime++; // this can be compared to the synced time to measure long + // term drift #endif - } - if (nextSyncTime <= sysTime) { + +if (sysTime - nextSyncTime < 2147483648U) { if (getTimePtr != 0) { time_t t = getTimePtr(); if (t != 0) { From 093c27042e50a96584bcffb2240d4b4e9e610e4f Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:18:09 +0200 Subject: [PATCH 36/41] Rename library.json to 0library.json --- library.json => 0library.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library.json => 0library.json (100%) diff --git a/library.json b/0library.json similarity index 100% rename from library.json rename to 0library.json From 5521af56644a4e30fd66d33d2f92d489754da8ad Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:18:28 +0200 Subject: [PATCH 37/41] Rename library.properties to 0library.properties --- library.properties => 0library.properties | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library.properties => 0library.properties (100%) diff --git a/library.properties b/0library.properties similarity index 100% rename from library.properties rename to 0library.properties From 9b87e13010062dacef70b3f2be5c90d7027736ff Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:20:03 +0200 Subject: [PATCH 38/41] Update 0library.properties --- 0library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/0library.properties b/0library.properties index 2c5d58c..5807c98 100644 --- a/0library.properties +++ b/0library.properties @@ -1,7 +1,7 @@ -name=Time +name=microTime version=1.6 author=Michael Margolis -maintainer=Paul Stoffregen +maintainer=cyberman54 sentence=Timekeeping functionality for Arduino paragraph=Date and Time functions, with provisions to synchronize to external time sources like GPS and NTP (Internet). This library is often used together with TimeAlarms and DS1307RTC. category=Timing From d46e1df80acbc731b481626ac550e0eb64ae2691 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:20:11 +0200 Subject: [PATCH 39/41] Rename 0library.properties to library.properties --- 0library.properties => library.properties | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 0library.properties => library.properties (100%) diff --git a/0library.properties b/library.properties similarity index 100% rename from 0library.properties rename to library.properties From 89c07ddc4bb6e45a2354633ee7320d1d3982bd7f Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:21:29 +0200 Subject: [PATCH 40/41] Update and rename 0library.json to library.json --- 0library.json => library.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) rename 0library.json => library.json (73%) diff --git a/0library.json b/library.json similarity index 73% rename from 0library.json rename to library.json index 1ea5293..6510a44 100644 --- a/0library.json +++ b/library.json @@ -7,15 +7,13 @@ "name": "Michael Margolis" }, { - "name": "Paul Stoffregen", - "email": "paul@pjrc.com", - "url": "http://www.pjrc.com", + "name": "cyberman54", "maintainer": true } ], "repository": { "type": "git", - "url": "https://github.com/PaulStoffregen/Time" + "url": "https://github.com/cyberman54/microTime" }, "version": "1.6", "homepage": "http://playground.arduino.cc/Code/Time", From 092106e3510af644bb4ba55c879f00e2b592e876 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sat, 8 May 2021 14:22:12 +0200 Subject: [PATCH 41/41] Update library.json --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 6510a44..014ec33 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "name": "Time", + "name": "microTime", "description": "Time keeping library", "keywords": "Time, date, hour, minute, second, day, week, month, year, RTC", "authors": [