1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Allow to use temporary strings in configTime (#8606)

This commit is contained in:
Max Prokhorov 2022-06-25 00:46:03 +03:00 committed by GitHub
parent 7935bed18f
commit 8decdc380a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -269,10 +269,13 @@ long map(long, long, long, long, long);
void setTZ(const char* tz);
void configTime(int timezone, int daylightOffset_sec, const char* server1,
// configure time using POSIX TZ string
// server pointers *must remain valid* for the duration of the program
void configTime(const char* tz, const char* server1,
const char* server2 = nullptr, const char* server3 = nullptr);
void configTime(const char* tz, const char* server1,
// configures with approximated TZ value. part of the old api, prefer configTime with TZ variable
void configTime(int timezone, int daylightOffset_sec, const char* server1,
const char* server2 = nullptr, const char* server3 = nullptr);
// esp32 api compatibility
@ -290,6 +293,12 @@ bool getLocalTime(struct tm * info, uint32_t ms = 5000);
#include "WCharacter.h"
#include "WString.h"
// configTime wrappers for temporary server{1,2,3} strings
void configTime(int timezone, int daylightOffset_sec, String server1,
String server2 = String(), String server3 = String());
void configTime(const char* tz, String server1,
String server2 = String(), String server3 = String());
#include "HardwareSerial.h"
#include "Esp.h"
#include "Updater.h"

View File

@ -208,6 +208,19 @@ void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, c
sntp_init();
}
void configTime(int timezone_sec, int daylightOffset_sec, String server1, String server2, String server3)
{
static String servers[3];
servers[0] = std::move(server1);
servers[1] = std::move(server2);
servers[2] = std::move(server3);
configTime(timezone_sec, daylightOffset_sec,
servers[0].length() ? servers[0].c_str() : nullptr,
servers[1].length() ? servers[1].c_str() : nullptr,
servers[2].length() ? servers[2].c_str() : nullptr);
}
void setTZ(const char* tz){
char tzram[strlen_P(tz) + 1];
@ -228,6 +241,19 @@ void configTime(const char* tz, const char* server1, const char* server2, const
sntp_init();
}
void configTime(const char* tz, String server1, String server2, String server3)
{
static String servers[3];
servers[0] = std::move(server1);
servers[1] = std::move(server2);
servers[2] = std::move(server3);
configTime(tz,
servers[0].length() ? servers[0].c_str() : nullptr,
servers[1].length() ? servers[1].c_str() : nullptr,
servers[2].length() ? servers[2].c_str() : nullptr);
}
static BoolCB _settimeofday_cb;
void settimeofday_cb (const TrivialCB& cb)