add daylight saving
This commit is contained in:
@@ -15,6 +15,7 @@ lv_obj_t *battery_voltage;
|
||||
lv_obj_t *charge_current;
|
||||
lv_obj_t *discharge_current;
|
||||
lv_obj_t *vbus_voltage;
|
||||
lv_task_t *battery_task;
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
|
||||
@@ -127,7 +128,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( vbus_voltage, "2.4mV");
|
||||
lv_obj_align( vbus_voltage, vbus_voltage_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_task_t * task = lv_task_create(battery_update_task, 1000, LV_TASK_PRIO_LOWEST, NULL );
|
||||
battery_task = lv_task_create(battery_update_task, 1000, LV_TASK_PRIO_LOWEST, NULL );
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +144,12 @@ void battery_update_task( lv_task_t *task ) {
|
||||
char temp[16]="";
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
snprintf( temp, sizeof( temp ), "%0.1fmAh", ttgo->power->getCoulombData() );
|
||||
if ( pmu_get_byttery_percent( ttgo ) >= 0 ) {
|
||||
snprintf( temp, sizeof( temp ), "%0.1fmAh", ttgo->power->getCoulombData() );
|
||||
}
|
||||
else {
|
||||
snprintf( temp, sizeof( temp ), "unknown" );
|
||||
}
|
||||
lv_label_set_text( battery_current_cap, temp );
|
||||
lv_obj_align( battery_current_cap, lv_obj_get_parent( battery_current_cap ), LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ lv_obj_t *time_settings_tile=NULL;
|
||||
lv_style_t time_settings_style;
|
||||
lv_obj_t *utczone_list = NULL;
|
||||
lv_obj_t *wifisync_onoff = NULL;
|
||||
lv_obj_t *daylight_onoff = NULL;
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(time_32px);
|
||||
|
||||
static void exit_time_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void wifisync_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
static void daylight_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
static void utczone_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
|
||||
void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
@@ -59,16 +61,29 @@ void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hre
|
||||
lv_label_set_text( wifisync_label, "sync when connect");
|
||||
lv_obj_align( wifisync_label, wifisync_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *daylight_cont = lv_obj_create( time_settings_tile, NULL );
|
||||
lv_obj_set_size(daylight_cont, hres , 40);
|
||||
lv_obj_add_style( daylight_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( daylight_cont, wifisync_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
daylight_onoff = lv_switch_create( daylight_cont, NULL );
|
||||
lv_switch_off( daylight_onoff, LV_ANIM_ON );
|
||||
lv_obj_align( daylight_onoff, daylight_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
lv_obj_set_event_cb( daylight_onoff, daylight_onoff_event_handler );
|
||||
lv_obj_t *daylight_label = lv_label_create( daylight_cont, NULL);
|
||||
lv_obj_add_style( daylight_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( daylight_label, "daylight saving");
|
||||
lv_obj_align( daylight_label, daylight_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *utczone_cont = lv_obj_create( time_settings_tile, NULL );
|
||||
lv_obj_set_size(utczone_cont, hres , 40);
|
||||
lv_obj_add_style( utczone_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( utczone_cont, wifisync_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
lv_obj_align( utczone_cont, daylight_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
lv_obj_t *utczone_label = lv_label_create( utczone_cont, NULL);
|
||||
lv_obj_add_style( utczone_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( utczone_label, "utc timezone");
|
||||
lv_obj_align( utczone_label, utczone_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
utczone_list = lv_dropdown_create( utczone_cont, NULL);
|
||||
lv_dropdown_set_options( utczone_list, "-12\n-11\n-10\n-9\n-8\n-7\n-6\n-5\n-4\n-3\n-2\n-1\n0\n+1\n+2\n+3\n+4\n+5\n+6\n+7\n+8\n+9\n+10\n+11\n+12\n" );
|
||||
lv_dropdown_set_options( utczone_list, "-12\n-11\n-10\n-9\n-8\n-7\n-6\n-5\n-4\n-3\n-2\n-1\n0\n+1\n+2\n+3\n+4\n+5\n+6\n+7\n+8\n+9\n+10\n+11\n+12" );
|
||||
lv_obj_align(utczone_list, utczone_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0);
|
||||
lv_obj_set_event_cb(utczone_list, utczone_event_handler);
|
||||
|
||||
@@ -77,6 +92,11 @@ void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hre
|
||||
else
|
||||
lv_switch_off( wifisync_onoff, LV_ANIM_OFF );
|
||||
|
||||
if ( timesync_get_daylightsave() )
|
||||
lv_switch_on( daylight_onoff, LV_ANIM_OFF );
|
||||
else
|
||||
lv_switch_off( daylight_onoff, LV_ANIM_OFF );
|
||||
|
||||
lv_dropdown_set_selected( utczone_list, timesync_get_timezone() + 12 );
|
||||
}
|
||||
|
||||
@@ -98,10 +118,20 @@ static void wifisync_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void daylight_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
if( lv_switch_get_state( obj ) ) {
|
||||
timesync_set_daylightsave( true );
|
||||
}
|
||||
else {
|
||||
timesync_set_daylightsave( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void utczone_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
timesync_set_timezone( lv_dropdown_get_selected( obj ) - 12 );
|
||||
printf("timezone: %d\n", lv_dropdown_get_selected( obj ) - 12 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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