|
|
|
|
@@ -25,6 +25,7 @@
|
|
|
|
|
#include "weather.h"
|
|
|
|
|
#include "weather_fetch.h"
|
|
|
|
|
#include "weather_forecast.h"
|
|
|
|
|
#include "images/resolve_owm_icon.h"
|
|
|
|
|
|
|
|
|
|
#include "gui/mainbar/mainbar.h"
|
|
|
|
|
#include "gui/mainbar/main_tile/main_tile.h"
|
|
|
|
|
@@ -36,6 +37,9 @@ TaskHandle_t _weather_forecast_sync_Task;
|
|
|
|
|
void weather_forecast_sync_Task( void * pvParameters );
|
|
|
|
|
|
|
|
|
|
lv_obj_t *weather_widget_tile = NULL;
|
|
|
|
|
lv_obj_t *weather_forecast_location_label = NULL;
|
|
|
|
|
lv_obj_t *weather_forecast_icon_imgbtn[ WEATHER_MAX_FORECAST ];
|
|
|
|
|
lv_obj_t *weather_forecast_temperature_label[ WEATHER_MAX_FORECAST ];
|
|
|
|
|
lv_style_t weather_widget_style;
|
|
|
|
|
|
|
|
|
|
weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
|
|
|
|
@@ -43,6 +47,7 @@ weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
|
|
|
|
LV_IMG_DECLARE(exit_32px);
|
|
|
|
|
LV_IMG_DECLARE(setup_32px);
|
|
|
|
|
LV_IMG_DECLARE(refresh_32px);
|
|
|
|
|
LV_IMG_DECLARE(owm_01d_64px);
|
|
|
|
|
|
|
|
|
|
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
|
|
|
static void setup_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
|
|
|
@@ -76,14 +81,39 @@ void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hr
|
|
|
|
|
lv_obj_align(reload_btn, tile, LV_ALIGN_IN_TOP_RIGHT, -10 , STATUSBAR_HEIGHT + 10 );
|
|
|
|
|
lv_obj_set_event_cb( reload_btn, refresh_weather_widget_event_cb );
|
|
|
|
|
|
|
|
|
|
weather_forecast_location_label = lv_label_create( tile , NULL);
|
|
|
|
|
lv_label_set_text( weather_forecast_location_label, "n/a");
|
|
|
|
|
lv_obj_reset_style_list( weather_forecast_location_label, LV_OBJ_PART_MAIN );
|
|
|
|
|
lv_obj_align( weather_forecast_location_label, tile, LV_ALIGN_IN_TOP_LEFT, 15, STATUSBAR_HEIGHT + 15 );
|
|
|
|
|
|
|
|
|
|
lv_obj_t * weater_forecast_cont = lv_obj_create( tile, NULL );
|
|
|
|
|
lv_obj_set_size( weater_forecast_cont, hres , 80 );
|
|
|
|
|
lv_obj_add_style( weater_forecast_cont, LV_OBJ_PART_MAIN, style );
|
|
|
|
|
lv_obj_align( weater_forecast_cont, tile, LV_ALIGN_CENTER, 0, 0 );
|
|
|
|
|
|
|
|
|
|
for ( int i = 0 ; i < WEATHER_MAX_FORECAST / 4 ; i++ ) {
|
|
|
|
|
weather_forecast_icon_imgbtn[ i ] = lv_imgbtn_create( weater_forecast_cont, NULL);
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_RELEASED, &owm_01d_64px);
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_PRESSED, &owm_01d_64px);
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_RELEASED, &owm_01d_64px);
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_PRESSED, &owm_01d_64px);
|
|
|
|
|
lv_obj_add_style( weather_forecast_icon_imgbtn[ i ], LV_IMGBTN_PART_MAIN, style);
|
|
|
|
|
lv_obj_align( weather_forecast_icon_imgbtn[ i ], weater_forecast_cont, LV_ALIGN_IN_TOP_LEFT, i*60, 0 );
|
|
|
|
|
|
|
|
|
|
weather_forecast_temperature_label[ i ] = lv_label_create( weater_forecast_cont , NULL);
|
|
|
|
|
lv_label_set_text( weather_forecast_temperature_label[ i ], "n/a");
|
|
|
|
|
lv_obj_reset_style_list( weather_forecast_temperature_label[ i ], LV_OBJ_PART_MAIN );
|
|
|
|
|
lv_obj_align( weather_forecast_temperature_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// regster callback for wifi sync
|
|
|
|
|
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
|
|
|
xEventGroupSetBits( weather_forecast_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
|
|
|
|
xEventGroupSetBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST );
|
|
|
|
|
vTaskResume( _weather_forecast_sync_Task );
|
|
|
|
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
|
|
|
|
|
|
|
|
|
weather_forecast_event_handle = xEventGroupCreate();
|
|
|
|
|
xEventGroupClearBits( weather_forecast_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
|
|
|
|
xEventGroupClearBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST );
|
|
|
|
|
|
|
|
|
|
xTaskCreate(
|
|
|
|
|
weather_forecast_sync_Task, /* Function to implement the task */
|
|
|
|
|
@@ -118,7 +148,7 @@ static void refresh_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void weather_forecast_sync_request( void ) {
|
|
|
|
|
xEventGroupSetBits( weather_forecast_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
|
|
|
|
xEventGroupSetBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST );
|
|
|
|
|
vTaskResume( _weather_forecast_sync_Task );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -126,20 +156,26 @@ void weather_forecast_sync_Task( void * pvParameters ) {
|
|
|
|
|
weather_config_t *weather_config = weather_get_config();
|
|
|
|
|
|
|
|
|
|
while( true ) {
|
|
|
|
|
vTaskDelay( 250 );
|
|
|
|
|
if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) {
|
|
|
|
|
vTaskDelay( 500 );
|
|
|
|
|
if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_FORECAST_SYNC_REQUEST ) {
|
|
|
|
|
if ( weather_config->autosync ) {
|
|
|
|
|
weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] );
|
|
|
|
|
if ( !weather_forecast[ 0 ].valide )
|
|
|
|
|
weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] );
|
|
|
|
|
if ( weather_forecast[ 0 ].valide ) {
|
|
|
|
|
Serial.printf("weather forecast fetch ok\r\n");
|
|
|
|
|
for( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) {
|
|
|
|
|
Serial.printf("Temp %02d: %s\r\n", i, weather_forecast[ i ].temp );
|
|
|
|
|
for( int i = 0 ; i < WEATHER_MAX_FORECAST / 4 ; i++ ) {
|
|
|
|
|
lv_label_set_text( weather_forecast_location_label, weather_forecast[ i * 4 ].name );
|
|
|
|
|
lv_label_set_text( weather_forecast_temperature_label[ i ], weather_forecast[ i * 4 ].temp );
|
|
|
|
|
lv_obj_align( weather_forecast_temperature_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_RELEASED, resolve_owm_icon( weather_forecast[ i * 4 ].icon ) );
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_PRESSED, resolve_owm_icon( weather_forecast[ i * 4 ].icon ) );
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_RELEASED, resolve_owm_icon( weather_forecast[ i * 4 ].icon ) );
|
|
|
|
|
lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_PRESSED, resolve_owm_icon( weather_forecast[ i * 4 ].icon ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
xEventGroupClearBits( weather_forecast_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
|
|
|
|
xEventGroupClearBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST );
|
|
|
|
|
}
|
|
|
|
|
vTaskSuspend( _weather_forecast_sync_Task );
|
|
|
|
|
}
|
|
|
|
|
|