some fixes and firmware stabilization
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "gui/mainbar/app_tile/app_tile.h"
|
||||
#include "gui/mainbar/main_tile/main_tile.h"
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
|
||||
uint32_t example_app_main_tile_num;
|
||||
uint32_t example_app_setup_tile_num;
|
||||
@@ -123,7 +124,8 @@ uint32_t example_app_get_app_setup_tile_num( void ) {
|
||||
*/
|
||||
static void enter_example_app_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): example_app_hide_app_icon_info( true );
|
||||
case( LV_EVENT_CLICKED ): statusbar_hide( true );
|
||||
example_app_hide_app_icon_info( true );
|
||||
#ifdef EXAMPLE_WIDGET
|
||||
example_app_hide_widget_icon_info( true );
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "gui/mainbar/app_tile/app_tile.h"
|
||||
#include "gui/mainbar/main_tile/main_tile.h"
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
|
||||
lv_obj_t *example_app_main_tile = NULL;
|
||||
lv_style_t example_app_main_style;
|
||||
@@ -73,7 +74,7 @@ void example_app_main_setup( uint32_t tile_num ) {
|
||||
lv_label_set_text( app_label, "myapp");
|
||||
lv_obj_reset_style_list( app_label, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( app_label, LV_OBJ_PART_MAIN, &example_app_main_style );
|
||||
lv_obj_align( app_label, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_align( app_label, example_app_main_tile, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
// create an task that runs every secound
|
||||
_example_app_task = lv_task_create( example_app_task, 1000, LV_TASK_PRIO_MID, NULL );
|
||||
@@ -81,7 +82,8 @@ void example_app_main_setup( uint32_t tile_num ) {
|
||||
|
||||
static void enter_example_app_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( example_app_get_app_setup_tile_num(), LV_ANIM_OFF );
|
||||
case( LV_EVENT_CLICKED ): statusbar_hide( true );
|
||||
mainbar_jump_to_tilenumber( example_app_get_app_setup_tile_num(), LV_ANIM_ON );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ void example_app_setup_setup( uint32_t tile_num ) {
|
||||
lv_obj_t *exit_cont = lv_obj_create( example_app_setup_tile, NULL );
|
||||
lv_obj_set_size( exit_cont, LV_HOR_RES_MAX , 40);
|
||||
lv_obj_add_style( exit_cont, LV_OBJ_PART_MAIN, &example_app_setup_style );
|
||||
lv_obj_align( exit_cont, example_app_setup_tile, LV_ALIGN_IN_TOP_MID, 0, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_align( exit_cont, example_app_setup_tile, LV_ALIGN_IN_TOP_MID, 0, 10 );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( exit_cont, NULL);
|
||||
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px);
|
||||
@@ -94,7 +94,7 @@ static void example_app_foobar_switch_event_cb( lv_obj_t * obj, lv_event_t event
|
||||
|
||||
static void exit_example_app_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( example_app_get_app_main_tile_num(), LV_ANIM_OFF );
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( example_app_get_app_main_tile_num(), LV_ANIM_ON );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,16 +132,19 @@ void weather_app_setup( void ) {
|
||||
|
||||
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( weather_app_tile_num, LV_ANIM_OFF );
|
||||
case( LV_EVENT_CLICKED ): statusbar_hide( true );
|
||||
mainbar_jump_to_tilenumber( weather_app_tile_num, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void weather_jump_to_forecast( void ) {
|
||||
statusbar_hide( true );
|
||||
mainbar_jump_to_tilenumber( weather_app_tile_num, LV_ANIM_ON );
|
||||
}
|
||||
|
||||
void weather_jump_to_setup( void ) {
|
||||
statusbar_hide( true );
|
||||
mainbar_jump_to_tilenumber( weather_app_setup_tile_num, LV_ANIM_ON );
|
||||
}
|
||||
|
||||
@@ -168,6 +171,8 @@ weather_config_t *weather_get_config( void ) {
|
||||
void weather_widget_sync_Task( void * pvParameters ) {
|
||||
log_i("start weather widget task");
|
||||
|
||||
vTaskDelay( 250 );
|
||||
|
||||
if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) {
|
||||
uint32_t retval = weather_fetch_today( &weather_config, &weather_today );
|
||||
if ( retval == 200 ) {
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include "ArduinoJson.h"
|
||||
#include "HTTPClient.h"
|
||||
|
||||
@@ -31,82 +29,46 @@
|
||||
|
||||
#include "hardware/powermgm.h"
|
||||
|
||||
// arduinoJson allocator for external PSRAM
|
||||
// see: https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/
|
||||
struct SpiRamAllocator {
|
||||
void* allocate( size_t size ) { return ps_calloc( size, 1 ); }
|
||||
void deallocate( void* pointer ) { free( pointer ); }
|
||||
};
|
||||
using SpiRamJsonDocument = BasicJsonDocument<SpiRamAllocator>;
|
||||
|
||||
/* Utility function to convert numbers to directions */
|
||||
static void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree);
|
||||
|
||||
uint32_t weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) {
|
||||
|
||||
WiFiClient today_client;
|
||||
uint32_t retval = -1;
|
||||
int weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) {
|
||||
char url[512]="";
|
||||
int httpcode = -1;
|
||||
|
||||
if ( !today_client.connect( OWM_HOST, OWM_PORT ) ) {
|
||||
log_e("connection failed");
|
||||
snprintf( url, sizeof( url ), "http://%s/data/2.5/weather?lat=%s&lon=%s&appid=%s", OWM_HOST, weather_config->lat, weather_config->lon, weather_config->apikey);
|
||||
|
||||
HTTPClient today_client;
|
||||
|
||||
today_client.useHTTP10( true );
|
||||
today_client.begin( url );
|
||||
httpcode = today_client.GET();
|
||||
|
||||
if ( httpcode != 200 ) {
|
||||
log_e("HTTPClient error %d", httpcode );
|
||||
today_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
today_client.printf( "GET /data/2.5/weather?lat=%s&lon=%s&appid=%s HTTP/1.1\r\n"
|
||||
"Host: %s\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"User-Agent: ESP32\r\n"
|
||||
"Accept: text/html,application/json\r\n\r\n", weather_config->lat, weather_config->lon, weather_config->apikey, OWM_HOST );
|
||||
|
||||
uint64_t startMillis = millis();
|
||||
while ( today_client.available() == 0 ) {
|
||||
if ( millis() - startMillis > 5000 ) {
|
||||
log_e("connection timeout");
|
||||
today_client.stop();
|
||||
return( retval );
|
||||
}
|
||||
}
|
||||
|
||||
char *json = (char *)ps_malloc( WEATHER_TODAY_BUFFER_SIZE );
|
||||
if ( json == NULL ) {
|
||||
log_e("memory alloc failed");
|
||||
today_client.stop();
|
||||
return( retval );
|
||||
}
|
||||
char *ptr = json;
|
||||
|
||||
bool data_begin = false;
|
||||
while( today_client.available() ) {
|
||||
if ( data_begin ) {
|
||||
ptr[ today_client.readBytes( ptr, WEATHER_TODAY_BUFFER_SIZE - 1 ) ] = '\0';
|
||||
}
|
||||
else if ( today_client.read() == '{' ) {
|
||||
data_begin = true;
|
||||
*ptr = '{';
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
SpiRamJsonDocument doc( today_client.getSize() * 2 );
|
||||
|
||||
today_client.stop();
|
||||
|
||||
if ( data_begin == false ) {
|
||||
free( json );
|
||||
return( retval );
|
||||
}
|
||||
today_client.stop();
|
||||
|
||||
DynamicJsonDocument doc(20000);
|
||||
|
||||
DeserializationError error = deserializeJson( doc, json);
|
||||
DeserializationError error = deserializeJson( doc, today_client.getStream() );
|
||||
if (error) {
|
||||
log_e("weather today deserializeJson() failed: %s", error.c_str() );
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
today_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
retval = doc["cod"].as<int>();
|
||||
|
||||
if ( retval != 200 ) {
|
||||
log_e("get weather failed, returncode: %d", retval );
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
}
|
||||
today_client.end();
|
||||
|
||||
weather_today->valide = true;
|
||||
snprintf( weather_today->temp, sizeof( weather_today->temp ),"%0.1f°C", doc["main"]["temp"].as<float>() - 273.15 );
|
||||
@@ -120,81 +82,38 @@ uint32_t weather_fetch_today( weather_config_t *weather_config, weather_forcast_
|
||||
weather_wind_to_string( weather_today, speed, directionDegree );
|
||||
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
return( httpcode );
|
||||
}
|
||||
|
||||
uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) {
|
||||
|
||||
WiFiClient forecast_client;
|
||||
uint32_t retval = -1;
|
||||
int weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) {
|
||||
char url[512]="";
|
||||
int httpcode = -1;
|
||||
|
||||
if ( !forecast_client.connect( OWM_HOST, OWM_PORT ) ) {
|
||||
log_e("connection failed");
|
||||
return( retval );
|
||||
}
|
||||
snprintf( url, sizeof( url ), "http://%s/data/2.5/forecast?cnt=%d&lat=%s&lon=%s&appid=%s", OWM_HOST, WEATHER_MAX_FORECAST, weather_config->lat, weather_config->lon, weather_config->apikey);
|
||||
|
||||
forecast_client.printf( "GET /data/2.5/forecast?cnt=%d&lat=%s&lon=%s&appid=%s HTTP/1.1\r\n"
|
||||
"Host: %s\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"User-Agent: ESP32\r\n"
|
||||
"Accept: text/html,application/json\r\n\r\n", WEATHER_MAX_FORECAST, weather_config->lat, weather_config->lon, weather_config->apikey, OWM_HOST );
|
||||
HTTPClient forecast_client;
|
||||
|
||||
uint64_t startMillis = millis();
|
||||
while ( forecast_client.available() == 0 ) {
|
||||
if ( millis() - startMillis > 5000 ) {
|
||||
log_e("connection timeout");
|
||||
forecast_client.stop();
|
||||
return( retval );
|
||||
}
|
||||
}
|
||||
forecast_client.useHTTP10( true );
|
||||
forecast_client.begin( url );
|
||||
httpcode = forecast_client.GET();
|
||||
|
||||
char *json = (char *)ps_malloc( WEATHER_FORECAST_BUFFER_SIZE );
|
||||
if ( json == NULL ) {
|
||||
log_e("memory alloc failed");
|
||||
forecast_client.stop();
|
||||
return( retval );
|
||||
}
|
||||
char *ptr = json;
|
||||
|
||||
bool data_begin = false;
|
||||
while( forecast_client.available() ) {
|
||||
if ( data_begin ) {
|
||||
ptr[ forecast_client.readBytes( ptr, WEATHER_FORECAST_BUFFER_SIZE - 1 ) ] = '\0';
|
||||
}
|
||||
else if ( forecast_client.read() == '{' ) {
|
||||
data_begin = true;
|
||||
*ptr = '{';
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
forecast_client.stop();
|
||||
|
||||
if ( data_begin == false ) {
|
||||
free( json );
|
||||
return( retval );
|
||||
if ( httpcode != 200 ) {
|
||||
log_e("HTTPClient error %d", httpcode );
|
||||
forecast_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
DynamicJsonDocument doc(20000);
|
||||
DeserializationError error = deserializeJson( doc, json );
|
||||
SpiRamJsonDocument doc( forecast_client.getSize() * 2 );
|
||||
|
||||
DeserializationError error = deserializeJson( doc, forecast_client.getStream() );
|
||||
if (error) {
|
||||
log_e("weather forecast deserializeJson() failed: %s", error.c_str() );
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
forecast_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
retval = doc["cod"].as<int>();
|
||||
|
||||
if ( retval != 200 ) {
|
||||
log_e("get weather forecast failed, returncode: %d", retval );
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
}
|
||||
forecast_client.end();
|
||||
|
||||
weather_forecast[0].valide = true;
|
||||
for ( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) {
|
||||
@@ -211,8 +130,7 @@ uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forca
|
||||
}
|
||||
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( 200 );
|
||||
return( httpcode );
|
||||
}
|
||||
|
||||
void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree )
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define WEATHER_TODAY_BUFFER_SIZE 10000
|
||||
#define WEATHER_FORECAST_BUFFER_SIZE 40000
|
||||
|
||||
uint32_t weather_fetch_today( weather_config_t * weather_config, weather_forcast_t * weather_today );
|
||||
uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast );
|
||||
int weather_fetch_today( weather_config_t * weather_config, weather_forcast_t * weather_today );
|
||||
int weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast );
|
||||
|
||||
#endif // _WEATHER_FETCH_H
|
||||
@@ -88,13 +88,13 @@ void weather_forecast_tile_setup( uint32_t tile_num ) {
|
||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_RELEASED, &refresh_32px);
|
||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_PRESSED, &refresh_32px);
|
||||
lv_obj_add_style(reload_btn, LV_IMGBTN_PART_MAIN, &weather_forecast_style );
|
||||
lv_obj_align(reload_btn, weather_forecast_tile, LV_ALIGN_IN_TOP_RIGHT, -10 , STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_align(reload_btn, weather_forecast_tile, LV_ALIGN_IN_TOP_RIGHT, -10 , 10 );
|
||||
lv_obj_set_event_cb( reload_btn, refresh_weather_widget_event_cb );
|
||||
|
||||
weather_forecast_location_label = lv_label_create( weather_forecast_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, weather_forecast_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_align( weather_forecast_location_label, weather_forecast_tile, LV_ALIGN_IN_TOP_LEFT, 10, 10 );
|
||||
|
||||
weather_forecast_update_label = lv_label_create( weather_forecast_tile , NULL);
|
||||
lv_label_set_text( weather_forecast_update_label, "");
|
||||
@@ -104,7 +104,7 @@ void weather_forecast_tile_setup( uint32_t tile_num ) {
|
||||
lv_obj_t * weater_forecast_cont = lv_obj_create( weather_forecast_tile, NULL );
|
||||
lv_obj_set_size( weater_forecast_cont, LV_HOR_RES_MAX , 96 );
|
||||
lv_obj_add_style( weater_forecast_cont, LV_OBJ_PART_MAIN, &weather_forecast_style );
|
||||
lv_obj_align( weater_forecast_cont, weather_forecast_tile, LV_ALIGN_CENTER, 0, 10 );
|
||||
lv_obj_align( weater_forecast_cont, weather_forecast_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);
|
||||
@@ -184,6 +184,8 @@ void weather_forecast_sync_Task( void * pvParameters ) {
|
||||
|
||||
log_i("start weather forecast task");
|
||||
|
||||
vTaskDelay( 250 );
|
||||
|
||||
if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_FORECAST_SYNC_REQUEST ) {
|
||||
if ( weather_config->autosync ) {
|
||||
retval = weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] );
|
||||
|
||||
@@ -67,7 +67,7 @@ void weather_setup_tile_setup( uint32_t tile_num ) {
|
||||
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_RELEASED, &exit_32px);
|
||||
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &exit_32px);
|
||||
lv_obj_add_style( exit_btn, LV_IMGBTN_PART_MAIN, &weather_setup_style );
|
||||
lv_obj_align( exit_btn, weather_setup_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_align( exit_btn, weather_setup_tile, LV_ALIGN_IN_TOP_LEFT, 10, 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_weather_widget_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( weather_setup_tile, NULL);
|
||||
@@ -78,7 +78,7 @@ void weather_setup_tile_setup( uint32_t tile_num ) {
|
||||
lv_obj_t *weather_apikey_cont = lv_obj_create( weather_setup_tile, NULL );
|
||||
lv_obj_set_size(weather_apikey_cont, LV_HOR_RES_MAX , 40);
|
||||
lv_obj_add_style( weather_apikey_cont, LV_OBJ_PART_MAIN, &weather_setup_style );
|
||||
lv_obj_align( weather_apikey_cont, weather_setup_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
lv_obj_align( weather_apikey_cont, weather_setup_tile, LV_ALIGN_IN_TOP_MID, 0, 49 );
|
||||
lv_obj_t *weather_apikey_label = lv_label_create( weather_apikey_cont, NULL);
|
||||
lv_obj_add_style( weather_apikey_label, LV_OBJ_PART_MAIN, &weather_setup_style );
|
||||
lv_label_set_text( weather_apikey_label, "appid");
|
||||
|
||||
Reference in New Issue
Block a user