try to fix time sync

This commit is contained in:
sharandac
2020-07-27 18:42:57 +02:00
parent 9458e11983
commit c71f2bf479
6 changed files with 26 additions and 7 deletions

View File

@@ -31,6 +31,6 @@
/*
* firmeware version string
*/
#define __FIRMWARE__ "2020072706"
#define __FIRMWARE__ "2020072707"
#endif // _CONFIG_H

View File

@@ -24,6 +24,7 @@
#include <soc/rtc.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <time.h>
#include "pmu.h"
#include "bma.h"
@@ -82,7 +83,7 @@ void powermgm_loop( TTGOClass *ttgo ) {
display_go_silence_wakeup( ttgo );
powermgm_set_event( POWERMGM_SILENCE_WAKEUP );
}
ttgo->rtc->syncToSystem();
timesyncToSystem();
ttgo->startLvglTick();
mainbar_jump_to_maintile( LV_ANIM_OFF );
lv_disp_trig_activity(NULL);
@@ -95,7 +96,7 @@ void powermgm_loop( TTGOClass *ttgo ) {
else {
Serial.printf("go to standby\r\n");
display_go_sleep( ttgo );
ttgo->rtc->syncToRtc();
timesyncToRTC();
if ( powermgm_get_event( POWERMGM_WIFI_ACTIVE ) ) wifictl_off();
while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN ) ) { yield(); }
ttgo->stopLvglTick();

View File

@@ -19,9 +19,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "time.h"
#include <WiFi.h>
#include "config.h"
#include "timesync.h"
#include <WiFi.h>
EventGroupHandle_t time_event_handle = NULL;
TaskHandle_t _timesync_Task;
@@ -30,7 +31,12 @@ void timesync_Task( void * pvParameters );
timesync_config_t timesync_config;
void timesync_setup( TTGOClass *ttgo ) {
/*
char buff[16]="";
snprintf( buff, sizeof(buff),"UTC%d", timesync_config.timezone);
setenv("TZ", buff, 1);
tzset();
*/
timesync_read_config();
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
@@ -115,13 +121,22 @@ void timesync_set_timezone( int32_t timezone ) {
timesync_save_config();
}
void timesyncToSystem( void ) {
TTGOClass *ttgo = TTGOClass::getWatch();
ttgo->rtc->syncToSystem();
}
void timesyncToRTC( void ) {
TTGOClass *ttgo = TTGOClass::getWatch();
ttgo->rtc->syncToRtc();
}
void timesync_Task( void * pvParameters ) {
while( true ) {
vTaskDelay( 500 );
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
struct tm info;
TTGOClass *ttgo = TTGOClass::getWatch();
long gmtOffset_sec = timesync_config.timezone * 3600;
int daylightOffset_sec = 0;

View File

@@ -85,4 +85,7 @@
*/
void timesync_set_timezone( int32_t timezone );
void timesyncToSystem( void );
void timesyncToRTC( void );
#endif // _TIME_SYNC_H

Binary file not shown.

View File

@@ -1 +1 @@
2020072706
2020072707