add daylight saving
This commit is contained in:
@@ -13,10 +13,6 @@ void IRAM_ATTR bma_irq( void );
|
||||
|
||||
bma_config_t bma_config[ BMA_CONFIG_NUM ];
|
||||
|
||||
void bma_reload_settings( void );
|
||||
void bma_read_config( void );
|
||||
void bma_save_config( void );
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
void bma_setup( TTGOClass *ttgo );
|
||||
void bma_loop( TTGOClass *ttgo );
|
||||
|
||||
void bma_reload_settings( void );
|
||||
void bma_save_config( void );
|
||||
void bma_read_config( void );
|
||||
bool bma_get_config( int config );
|
||||
void bma_set_config( int config, bool enable );
|
||||
|
||||
|
||||
@@ -107,10 +107,9 @@ void pmu_loop( TTGOClass *ttgo ) {
|
||||
|
||||
uint32_t pmu_get_byttery_percent( TTGOClass *ttgo ) {
|
||||
// discharg coulumb higher then charge coulumb, battery state unknow and set to zero
|
||||
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() )
|
||||
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() ) {
|
||||
ttgo->power->ClearCoulombcounter();
|
||||
|
||||
// printf("Coulumb data: %0.1fmAh %0.1f%% (charge current: %0.1fmA, discharge current: %0.1fmA)\r",ttgo->power->getCoulombData(), (ttgo->power->getCoulombData()/380)*100, ttgo->power->getBattChargeCurrent(), ttgo->power->getBattDischargeCurrent() );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
return( ( ttgo->power->getCoulombData() / PMU_BATTERY_CAP ) * 100 );
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
*
|
||||
* @param ttgo pointer to an TTGOClass
|
||||
*
|
||||
* @return charge in percent
|
||||
* @return charge in percent or -1 if unknown
|
||||
*/
|
||||
uint32_t pmu_get_byttery_percent( TTGOClass *ttgo );
|
||||
|
||||
|
||||
@@ -13,8 +13,10 @@ void timesync_setup( TTGOClass *ttgo ) {
|
||||
timesync_read_config();
|
||||
|
||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
vTaskResume( _timesync_Task );
|
||||
if ( timesync_config.timesync ) {
|
||||
xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
vTaskResume( _timesync_Task );
|
||||
}
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||
|
||||
time_event_handle = xEventGroupCreate();
|
||||
@@ -90,15 +92,16 @@ void timesync_set_timezone( int32_t timezone ) {
|
||||
void timesync_Task( void * pvParameters ) {
|
||||
|
||||
while( true ) {
|
||||
vTaskDelay( 50 );
|
||||
|
||||
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
|
||||
struct tm timeinfo;
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
long gmtOffset_sec = timesync_config.timezone * 3600;
|
||||
|
||||
configTime( gmtOffset_sec, 0, "pool.ntp.org" );
|
||||
int daylightOffset_sec = 0;
|
||||
if ( timesync_config.daylightsave )
|
||||
daylightOffset_sec = 3600;
|
||||
|
||||
configTime( gmtOffset_sec, daylightOffset_sec, "pool.ntp.org" );
|
||||
|
||||
if( !getLocalTime( &timeinfo ) ) {
|
||||
Serial.println( "Failed to obtain time\r\n" );
|
||||
@@ -106,7 +109,6 @@ void timesync_Task( void * pvParameters ) {
|
||||
ttgo->rtc->syncToRtc();
|
||||
xEventGroupClearBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
}
|
||||
|
||||
vTaskSuspend( _timesync_Task );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user