mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
import getLocalTime() from esp32/Arduino (#8413)
* import getLocalTime() from esp32/Arduino follows #8407
This commit is contained in:
parent
f26201e6a9
commit
a05a71fa9d
@ -279,6 +279,8 @@ inline void configTzTime(const char* tz, const char* server1,
|
|||||||
configTime(tz, server1, server2, server3);
|
configTime(tz, server1, server2, server3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getLocalTime(struct tm * info, uint32_t ms = 5000);
|
||||||
|
|
||||||
// Everything we expect to be implicitly loaded for the sketch
|
// Everything we expect to be implicitly loaded for the sketch
|
||||||
#include <pgmspace.h>
|
#include <pgmspace.h>
|
||||||
|
|
||||||
|
@ -20,6 +20,28 @@
|
|||||||
* synchronisation of the two through timeshift64
|
* synchronisation of the two through timeshift64
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-time.c
|
||||||
|
|
||||||
|
bool getLocalTime(struct tm * info, uint32_t ms)
|
||||||
|
{
|
||||||
|
uint32_t start = millis();
|
||||||
|
time_t now;
|
||||||
|
while((millis()-start) <= ms) {
|
||||||
|
time(&now);
|
||||||
|
localtime_r(&now, info);
|
||||||
|
if(info->tm_year > (2016 - 1900)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CORE_MOCK)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <../include/time.h> // See issue #6714
|
#include <../include/time.h> // See issue #6714
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -33,7 +55,6 @@ extern "C" {
|
|||||||
#include <coredecls.h>
|
#include <coredecls.h>
|
||||||
#include <Schedule.h>
|
#include <Schedule.h>
|
||||||
|
|
||||||
#include <Arduino.h> // configTime()
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
@ -257,4 +278,6 @@ int settimeofday(const struct timeval* tv, const struct timezone* tz)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
}; // extern "C"
|
||||||
|
|
||||||
|
#endif // !defined(CORE_MOCK)
|
||||||
|
@ -19,29 +19,6 @@ long timezone = 2;
|
|||||||
byte daysavetime = 1;
|
byte daysavetime = 1;
|
||||||
|
|
||||||
|
|
||||||
bool getLocalTime(struct tm * info, uint32_t ms) {
|
|
||||||
uint32_t count = ms / 10;
|
|
||||||
time_t now;
|
|
||||||
|
|
||||||
time(&now);
|
|
||||||
localtime_r(&now, info);
|
|
||||||
|
|
||||||
if (info->tm_year > (2016 - 1900)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (count--) {
|
|
||||||
delay(10);
|
|
||||||
time(&now);
|
|
||||||
localtime_r(&now, info);
|
|
||||||
if (info->tm_year > (2016 - 1900)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void listDir(const char * dirname) {
|
void listDir(const char * dirname) {
|
||||||
Serial.printf("Listing directory: %s\n", dirname);
|
Serial.printf("Listing directory: %s\n", dirname);
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ CORE_CPP_FILES := \
|
|||||||
HardwareSerial.cpp \
|
HardwareSerial.cpp \
|
||||||
crc32.cpp \
|
crc32.cpp \
|
||||||
Updater.cpp \
|
Updater.cpp \
|
||||||
|
time.cpp \
|
||||||
) \
|
) \
|
||||||
$(addprefix $(abspath $(LIBRARIES_PATH)/ESP8266SdFat/src)/, \
|
$(addprefix $(abspath $(LIBRARIES_PATH)/ESP8266SdFat/src)/, \
|
||||||
FatLib/FatFile.cpp \
|
FatLib/FatFile.cpp \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user