X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=user_main.c;h=26150f8bbe640c9552e245be23ba3df7957b2084;hb=377f58b3be561a9e0fffebf54237693ddce2184f;hp=148477131bdbddf4271e62f9a67a6c8c1d2a9a0c;hpb=a6b9bc4387fe370b7a3cddac157b1b9137847f30;p=esp8266-clock.git diff --git a/user_main.c b/user_main.c index 1484771..26150f8 100644 --- a/user_main.c +++ b/user_main.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Jonathan McDowell + * Copyright 2017-2019 Jonathan McDowell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,16 +19,16 @@ #include #include -#include "espmissingincludes.h" - #include "project_config.h" #include "clock.h" #include "max7219.h" +#include "ota.h" #include "spi.h" struct station_config wificfg; static os_timer_t update_timer; +static os_timer_t ntp_timer; static const struct fontchar clocknums[] = { { .width = 5, @@ -106,14 +106,24 @@ void ICACHE_FLASH_ATTR update_func(void *arg) max7219_show(); } +void ICACHE_FLASH_ATTR ntp_func(void *arg) +{ + ntp_get_time(); +} + void ICACHE_FLASH_ATTR wifi_callback(System_Event_t *evt) { switch (evt->event) { case EVENT_STAMODE_CONNECTED: case EVENT_STAMODE_DISCONNECTED: + os_timer_disarm(&ntp_timer); break; case EVENT_STAMODE_GOT_IP: ntp_get_time(); + ota_check(); + os_timer_disarm(&ntp_timer); + os_timer_setfn(&ntp_timer, ntp_func, NULL); + os_timer_arm(&ntp_timer, 3600 * 1000 /* Hourly */, 1); default: break; }