forked from PaulStoffregen/Time
Fixes for esp-idf
This commit is contained in:
35
CMakeLists.txt
Normal file
35
CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
set(headers
|
||||||
|
Time.h
|
||||||
|
TimeLib.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(sources
|
||||||
|
DateStrings.cpp
|
||||||
|
Time.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(dependencies
|
||||||
|
esp_timer
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
INCLUDE_DIRS
|
||||||
|
.
|
||||||
|
SRCS
|
||||||
|
${headers}
|
||||||
|
${sources}
|
||||||
|
REQUIRES
|
||||||
|
${dependencies}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_TARGET}
|
||||||
|
PUBLIC
|
||||||
|
-DUSE_FACADE=true
|
||||||
|
PRIVATE
|
||||||
|
-fstack-reuse=all
|
||||||
|
-fstack-protector-all
|
||||||
|
-Wno-unused-function
|
||||||
|
-Wno-deprecated-declarations
|
||||||
|
-Wno-missing-field-initializers
|
||||||
|
-Wno-parentheses
|
||||||
|
)
|
112
DateStrings.cpp
112
DateStrings.cpp
@@ -9,15 +9,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
//#include <Arduino.h>
|
||||||
|
|
||||||
// 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
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "TimeLib.h"
|
#include "TimeLib.h"
|
||||||
|
|
||||||
@@ -25,73 +17,73 @@
|
|||||||
// the short strings for each day or month must be exactly dt_SHORT_STR_LEN
|
// 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
|
#define dt_SHORT_STR_LEN 3 // the length of short strings
|
||||||
|
|
||||||
static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null
|
//static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null
|
||||||
|
|
||||||
const char monthStr0[] PROGMEM = "";
|
const char monthStr0[] = "";
|
||||||
const char monthStr1[] PROGMEM = "January";
|
const char monthStr1[] = "January";
|
||||||
const char monthStr2[] PROGMEM = "February";
|
const char monthStr2[] = "February";
|
||||||
const char monthStr3[] PROGMEM = "March";
|
const char monthStr3[] = "March";
|
||||||
const char monthStr4[] PROGMEM = "April";
|
const char monthStr4[] = "April";
|
||||||
const char monthStr5[] PROGMEM = "May";
|
const char monthStr5[] = "May";
|
||||||
const char monthStr6[] PROGMEM = "June";
|
const char monthStr6[] = "June";
|
||||||
const char monthStr7[] PROGMEM = "July";
|
const char monthStr7[] = "July";
|
||||||
const char monthStr8[] PROGMEM = "August";
|
const char monthStr8[] = "August";
|
||||||
const char monthStr9[] PROGMEM = "September";
|
const char monthStr9[] = "September";
|
||||||
const char monthStr10[] PROGMEM = "October";
|
const char monthStr10[] = "October";
|
||||||
const char monthStr11[] PROGMEM = "November";
|
const char monthStr11[] = "November";
|
||||||
const char monthStr12[] PROGMEM = "December";
|
const char monthStr12[] = "December";
|
||||||
|
|
||||||
const PROGMEM char * const PROGMEM monthNames_P[] =
|
const char * const monthNames_P[] =
|
||||||
{
|
{
|
||||||
monthStr0,monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
|
monthStr0,monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6,
|
||||||
monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
|
monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12
|
||||||
};
|
};
|
||||||
|
|
||||||
const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec";
|
const char monthShortNames_P[] = "ErrJanFebMarAprMayJunJulAugSepOctNovDec";
|
||||||
|
|
||||||
const char dayStr0[] PROGMEM = "Err";
|
const char dayStr0[] = "Err";
|
||||||
const char dayStr1[] PROGMEM = "Sunday";
|
const char dayStr1[] = "Sunday";
|
||||||
const char dayStr2[] PROGMEM = "Monday";
|
const char dayStr2[] = "Monday";
|
||||||
const char dayStr3[] PROGMEM = "Tuesday";
|
const char dayStr3[] = "Tuesday";
|
||||||
const char dayStr4[] PROGMEM = "Wednesday";
|
const char dayStr4[] = "Wednesday";
|
||||||
const char dayStr5[] PROGMEM = "Thursday";
|
const char dayStr5[] = "Thursday";
|
||||||
const char dayStr6[] PROGMEM = "Friday";
|
const char dayStr6[] = "Friday";
|
||||||
const char dayStr7[] PROGMEM = "Saturday";
|
const char dayStr7[] = "Saturday";
|
||||||
|
|
||||||
const PROGMEM char * const PROGMEM dayNames_P[] =
|
const char * const dayNames_P[] =
|
||||||
{
|
{
|
||||||
dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7
|
dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7
|
||||||
};
|
};
|
||||||
|
|
||||||
const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat";
|
const char dayShortNames_P[] = "ErrSunMonTueWedThuFriSat";
|
||||||
|
|
||||||
/* functions to return date strings */
|
/* functions to return date strings */
|
||||||
|
|
||||||
char* monthStr(uint8_t month)
|
//char* monthStr(uint8_t month)
|
||||||
{
|
//{
|
||||||
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month])));
|
// strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(monthNames_P[month])));
|
||||||
return buffer;
|
// return buffer;
|
||||||
}
|
//}
|
||||||
|
|
||||||
char* monthShortStr(uint8_t month)
|
//char* monthShortStr(uint8_t month)
|
||||||
{
|
//{
|
||||||
for (int i=0; i < dt_SHORT_STR_LEN; i++)
|
// for (int i=0; i < dt_SHORT_STR_LEN; i++)
|
||||||
buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)]));
|
// buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)]));
|
||||||
buffer[dt_SHORT_STR_LEN] = 0;
|
// buffer[dt_SHORT_STR_LEN] = 0;
|
||||||
return buffer;
|
// return buffer;
|
||||||
}
|
//}
|
||||||
|
|
||||||
char* dayStr(uint8_t day)
|
//char* dayStr(uint8_t day)
|
||||||
{
|
//{
|
||||||
strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day])));
|
// strcpy_P(buffer, (PGM_P)pgm_read_ptr(&(dayNames_P[day])));
|
||||||
return buffer;
|
// return buffer;
|
||||||
}
|
//}
|
||||||
|
|
||||||
char* dayShortStr(uint8_t day)
|
//char* dayShortStr(uint8_t day)
|
||||||
{
|
//{
|
||||||
uint8_t index = day*dt_SHORT_STR_LEN;
|
// uint8_t index = day*dt_SHORT_STR_LEN;
|
||||||
for (int i=0; i < dt_SHORT_STR_LEN; i++)
|
// for (int i=0; i < dt_SHORT_STR_LEN; i++)
|
||||||
buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i]));
|
// buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i]));
|
||||||
buffer[dt_SHORT_STR_LEN] = 0;
|
// buffer[dt_SHORT_STR_LEN] = 0;
|
||||||
return buffer;
|
// return buffer;
|
||||||
}
|
//}
|
||||||
|
19
Time.cpp
19
Time.cpp
@@ -27,18 +27,27 @@
|
|||||||
1.4 5 Sep 2014 - compatibility with Arduino 1.5.7
|
1.4 5 Sep 2014 - compatibility with Arduino 1.5.7
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if ARDUINO >= 100
|
//#if ARDUINO >= 100
|
||||||
#include <Arduino.h>
|
//#include <Arduino.h>
|
||||||
#else
|
//#else
|
||||||
#include <WProgram.h>
|
//#include <WProgram.h>
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
#include "TimeLib.h"
|
#include "TimeLib.h"
|
||||||
|
|
||||||
|
#include <esp_timer.h>
|
||||||
|
|
||||||
static tmElements_t tm; // a cache of time elements
|
static tmElements_t tm; // a cache of time elements
|
||||||
static time_t cacheTime; // the time the cache was updated
|
static time_t cacheTime; // the time the cache was updated
|
||||||
static uint32_t syncInterval = 300; // time sync will be attempted after this many seconds
|
static uint32_t syncInterval = 300; // time sync will be attempted after this many seconds
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
unsigned long millis()
|
||||||
|
{
|
||||||
|
return esp_timer_get_time() / 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void refreshCache(time_t t) {
|
void refreshCache(time_t t) {
|
||||||
if (t != cacheTime) {
|
if (t != cacheTime) {
|
||||||
breakTime(t, tm);
|
breakTime(t, tm);
|
||||||
|
@@ -124,10 +124,10 @@ void adjustTime(long adjustment);
|
|||||||
|
|
||||||
/* date strings */
|
/* date strings */
|
||||||
#define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null)
|
#define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null)
|
||||||
char* monthStr(uint8_t month);
|
//char* monthStr(uint8_t month);
|
||||||
char* dayStr(uint8_t day);
|
//char* dayStr(uint8_t day);
|
||||||
char* monthShortStr(uint8_t month);
|
//char* monthShortStr(uint8_t month);
|
||||||
char* dayShortStr(uint8_t day);
|
//char* dayShortStr(uint8_t day);
|
||||||
|
|
||||||
/* time sync functions */
|
/* time sync functions */
|
||||||
timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized
|
timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized
|
||||||
|
Reference in New Issue
Block a user