first functional weather widget release
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 64 KiB |
@@ -31,6 +31,6 @@
|
||||
/*
|
||||
* firmeware version string
|
||||
*/
|
||||
#define __FIRMWARE__ "2020072308"
|
||||
#define __FIRMWARE__ "2020072403"
|
||||
|
||||
#endif // _CONFIG_H
|
||||
|
||||
@@ -125,7 +125,7 @@ static void update_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
|
||||
void update_Task( void * pvParameters ) {
|
||||
while( true ) {
|
||||
vTaskDelay( 250 );
|
||||
vTaskDelay( 500 );
|
||||
if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) {
|
||||
if( WiFi.status() == WL_CONNECTED ) {
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ weather_config_t *weather_get_config( void ) {
|
||||
void weather_widget_sync_Task( void * pvParameters ) {
|
||||
|
||||
while( true ) {
|
||||
vTaskDelay( 250 );
|
||||
vTaskDelay( 500 );
|
||||
if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) {
|
||||
if ( weather_config.autosync ) {
|
||||
weather_fetch_today( &weather_config, &weather_today );
|
||||
|
||||
@@ -162,9 +162,9 @@ void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t
|
||||
|
||||
weather_forecast[0].valide = true;
|
||||
for ( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) {
|
||||
snprintf( weather_forecast[ i ].temp, sizeof( weather_forecast[ i ].temp ),"%0.1f", doc["list"][i]["main"]["temp"].as<float>() - 273.15 );
|
||||
snprintf( weather_forecast[ i ].humidity, sizeof( weather_forecast[ i ].humidity ),"%f", doc["list"][i]["main"]["humidity"].as<float>() );
|
||||
snprintf( weather_forecast[ i ].pressure, sizeof( weather_forecast[ i ].pressure ),"%f", doc["list"][i]["main"]["pressure"].as<float>() );
|
||||
snprintf( weather_forecast[ i ].temp, sizeof( weather_forecast[ i ].temp ),"%0.1f°C", doc["list"][i]["main"]["temp"].as<float>() - 273.15 );
|
||||
snprintf( weather_forecast[ i ].humidity, sizeof( weather_forecast[ i ].humidity ),"%f%%", doc["list"][i]["main"]["humidity"].as<float>() );
|
||||
snprintf( weather_forecast[ i ].pressure, sizeof( weather_forecast[ i ].pressure ),"%fpha", doc["list"][i]["main"]["pressure"].as<float>() );
|
||||
strcpy( weather_forecast[ i ].icon, doc["list"][i]["weather"][0]["icon"] );
|
||||
strcpy( weather_forecast[ i ].name, doc["city"]["name"] );
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
#define WEATHER_WIDGET_SYNC_REQUEST _BV(0)
|
||||
#define WEATHER_MAX_FORECAST 18
|
||||
#define WEATHER_FORECAST_SYNC_REQUEST _BV(0)
|
||||
#define WEATHER_MAX_FORECAST 16
|
||||
|
||||
void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
void weather_forecast_sync_request( void );
|
||||
|
||||
@@ -113,7 +113,7 @@ void timesync_set_timezone( int32_t timezone ) {
|
||||
void timesync_Task( void * pvParameters ) {
|
||||
|
||||
while( true ) {
|
||||
vTaskDelay( 250 );
|
||||
vTaskDelay( 500 );
|
||||
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
|
||||
struct tm info;
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
@@ -247,7 +247,7 @@ void wifictl_Task( void * pvParameters ) {
|
||||
return;
|
||||
|
||||
while( true ) {
|
||||
vTaskDelay( 50 );
|
||||
vTaskDelay( 500 );
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
statusbar_wifi_set_state( true, "activate" );
|
||||
WiFi.mode( WIFI_STA );
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
2020072308
|
||||
2020072403
|
||||
|
||||
Reference in New Issue
Block a user