mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
Merge branch 'sntp_servers_flash' into integration
This commit is contained in:
@@ -18,7 +18,7 @@ namespace sntp {
|
|||||||
/// \see https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
|
/// \see https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
|
||||||
class SNTPComponent : public time::RealTimeClock {
|
class SNTPComponent : public time::RealTimeClock {
|
||||||
public:
|
public:
|
||||||
SNTPComponent(std::array<const char *, SNTP_SERVER_COUNT> servers) : servers_(servers) {}
|
SNTPComponent(const std::array<const char *, SNTP_SERVER_COUNT> &servers) : servers_(servers) {}
|
||||||
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|||||||
@@ -43,17 +43,12 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
servers = config[CONF_SERVERS]
|
servers = config[CONF_SERVERS]
|
||||||
server_count = len(servers)
|
|
||||||
|
|
||||||
# Define server count at compile time
|
# Define server count at compile time
|
||||||
cg.add_define("SNTP_SERVER_COUNT", server_count)
|
cg.add_define("SNTP_SERVER_COUNT", len(servers))
|
||||||
|
|
||||||
# Pass string literals to constructor - stored in flash/rodata by compiler
|
# Pass string literals to constructor - stored in flash/rodata by compiler
|
||||||
# On ESP8266, LWIP doesn't support PROGMEM pointers, so strings are in rodata (RAM)
|
var = cg.new_Pvariable(config[CONF_ID], servers)
|
||||||
# but we still avoid the ~24 byte std::string overhead per server
|
|
||||||
var = cg.new_Pvariable(
|
|
||||||
config[CONF_ID], cg.ArrayInitializer(*[cg.safe_exp(s) for s in servers])
|
|
||||||
)
|
|
||||||
|
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
await time_.register_time(var, config)
|
await time_.register_time(var, config)
|
||||||
|
|||||||
Reference in New Issue
Block a user