some fixes and firmware stabilization

This commit is contained in:
sharandac
2020-08-06 17:31:40 +02:00
parent 7876f35e39
commit 4f22ef3c24
26 changed files with 1646 additions and 967 deletions

View File

@@ -15,6 +15,7 @@ framework = arduino
board_build.f_flash = 80000000L board_build.f_flash = 80000000L
monitor_speed = 115200 monitor_speed = 115200
build_flags = build_flags =
; -DCORE_DEBUG_LEVEL=3
-DBOARD_HAS_PSRAM -DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-issue
src_filter = src_filter =
@@ -23,4 +24,4 @@ lib_deps =
TTGO TWatch Library@>=1.2.0 TTGO TWatch Library@>=1.2.0
ESP Async WebServer@>=1.2.0 ESP Async WebServer@>=1.2.0
AsyncTCP@>=1.1.1 AsyncTCP@>=1.1.1
ArduinoJson@>=6.15.2 ArduinoJson@>=6.15.2

View File

@@ -29,6 +29,7 @@
#include "gui/mainbar/app_tile/app_tile.h" #include "gui/mainbar/app_tile/app_tile.h"
#include "gui/mainbar/main_tile/main_tile.h" #include "gui/mainbar/main_tile/main_tile.h"
#include "gui/mainbar/mainbar.h" #include "gui/mainbar/mainbar.h"
#include "gui/statusbar.h"
uint32_t example_app_main_tile_num; uint32_t example_app_main_tile_num;
uint32_t example_app_setup_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 ) { static void enter_example_app_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( 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 #ifdef EXAMPLE_WIDGET
example_app_hide_widget_icon_info( true ); example_app_hide_widget_icon_info( true );
#endif #endif

View File

@@ -28,6 +28,7 @@
#include "gui/mainbar/app_tile/app_tile.h" #include "gui/mainbar/app_tile/app_tile.h"
#include "gui/mainbar/main_tile/main_tile.h" #include "gui/mainbar/main_tile/main_tile.h"
#include "gui/mainbar/mainbar.h" #include "gui/mainbar/mainbar.h"
#include "gui/statusbar.h"
lv_obj_t *example_app_main_tile = NULL; lv_obj_t *example_app_main_tile = NULL;
lv_style_t example_app_main_style; 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_label_set_text( app_label, "myapp");
lv_obj_reset_style_list( app_label, LV_OBJ_PART_MAIN ); 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_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 // create an task that runs every secound
_example_app_task = lv_task_create( example_app_task, 1000, LV_TASK_PRIO_MID, NULL ); _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 ) { static void enter_example_app_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( 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; break;
} }
} }

View File

@@ -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_t *exit_cont = lv_obj_create( example_app_setup_tile, NULL );
lv_obj_set_size( exit_cont, LV_HOR_RES_MAX , 40); 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_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_obj_t *exit_btn = lv_imgbtn_create( exit_cont, NULL);
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px); 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 ) { static void exit_example_app_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( 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; break;
} }
} }

View File

@@ -132,16 +132,19 @@ void weather_app_setup( void ) {
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) { static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
switch( 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; break;
} }
} }
void weather_jump_to_forecast( void ) { void weather_jump_to_forecast( void ) {
statusbar_hide( true );
mainbar_jump_to_tilenumber( weather_app_tile_num, LV_ANIM_ON ); mainbar_jump_to_tilenumber( weather_app_tile_num, LV_ANIM_ON );
} }
void weather_jump_to_setup( void ) { void weather_jump_to_setup( void ) {
statusbar_hide( true );
mainbar_jump_to_tilenumber( weather_app_setup_tile_num, LV_ANIM_ON ); 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 ) { void weather_widget_sync_Task( void * pvParameters ) {
log_i("start weather widget task"); log_i("start weather widget task");
vTaskDelay( 250 );
if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) { if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) {
uint32_t retval = weather_fetch_today( &weather_config, &weather_today ); uint32_t retval = weather_fetch_today( &weather_config, &weather_today );
if ( retval == 200 ) { if ( retval == 200 ) {

View File

@@ -20,8 +20,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "config.h" #include "config.h"
#include <Arduino.h>
#include <WiFi.h>
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "HTTPClient.h" #include "HTTPClient.h"
@@ -31,82 +29,46 @@
#include "hardware/powermgm.h" #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 */ /* Utility function to convert numbers to directions */
static void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree); 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 ) { int weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) {
char url[512]="";
WiFiClient today_client; int httpcode = -1;
uint32_t retval = -1;
if ( !today_client.connect( OWM_HOST, OWM_PORT ) ) { 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);
log_e("connection failed");
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 ); 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; SpiRamJsonDocument doc( today_client.getSize() * 2 );
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++;
}
}
today_client.stop(); DeserializationError error = deserializeJson( doc, today_client.getStream() );
if ( data_begin == false ) {
free( json );
return( retval );
}
today_client.stop();
DynamicJsonDocument doc(20000);
DeserializationError error = deserializeJson( doc, json);
if (error) { if (error) {
log_e("weather today deserializeJson() failed: %s", error.c_str() ); log_e("weather today deserializeJson() failed: %s", error.c_str() );
doc.clear(); doc.clear();
free( json ); today_client.end();
return( retval ); return( -1 );
} }
retval = doc["cod"].as<int>(); today_client.end();
if ( retval != 200 ) {
log_e("get weather failed, returncode: %d", retval );
doc.clear();
free( json );
return( retval );
}
weather_today->valide = true; weather_today->valide = true;
snprintf( weather_today->temp, sizeof( weather_today->temp ),"%0.1f°C", doc["main"]["temp"].as<float>() - 273.15 ); 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 ); weather_wind_to_string( weather_today, speed, directionDegree );
doc.clear(); doc.clear();
free( json ); return( httpcode );
return( retval );
} }
uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) { int weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) {
char url[512]="";
WiFiClient forecast_client; int httpcode = -1;
uint32_t retval = -1;
if ( !forecast_client.connect( OWM_HOST, OWM_PORT ) ) { 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);
log_e("connection failed");
return( retval );
}
forecast_client.printf( "GET /data/2.5/forecast?cnt=%d&lat=%s&lon=%s&appid=%s HTTP/1.1\r\n" HTTPClient forecast_client;
"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 );
uint64_t startMillis = millis(); forecast_client.useHTTP10( true );
while ( forecast_client.available() == 0 ) { forecast_client.begin( url );
if ( millis() - startMillis > 5000 ) { httpcode = forecast_client.GET();
log_e("connection timeout");
forecast_client.stop();
return( retval );
}
}
char *json = (char *)ps_malloc( WEATHER_FORECAST_BUFFER_SIZE ); if ( httpcode != 200 ) {
if ( json == NULL ) { log_e("HTTPClient error %d", httpcode );
log_e("memory alloc failed"); forecast_client.end();
forecast_client.stop(); return( -1 );
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 );
} }
DynamicJsonDocument doc(20000); SpiRamJsonDocument doc( forecast_client.getSize() * 2 );
DeserializationError error = deserializeJson( doc, json );
DeserializationError error = deserializeJson( doc, forecast_client.getStream() );
if (error) { if (error) {
log_e("weather forecast deserializeJson() failed: %s", error.c_str() ); log_e("weather forecast deserializeJson() failed: %s", error.c_str() );
doc.clear(); doc.clear();
free( json ); forecast_client.end();
return( retval ); return( -1 );
} }
retval = doc["cod"].as<int>(); forecast_client.end();
if ( retval != 200 ) {
log_e("get weather forecast failed, returncode: %d", retval );
doc.clear();
free( json );
return( retval );
}
weather_forecast[0].valide = true; weather_forecast[0].valide = true;
for ( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) { 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(); doc.clear();
free( json ); return( httpcode );
return( 200 );
} }
void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree ) void weather_wind_to_string( weather_forcast_t* container, int speed, int directionDegree )

View File

@@ -28,7 +28,7 @@
#define WEATHER_TODAY_BUFFER_SIZE 10000 #define WEATHER_TODAY_BUFFER_SIZE 10000
#define WEATHER_FORECAST_BUFFER_SIZE 40000 #define WEATHER_FORECAST_BUFFER_SIZE 40000
uint32_t weather_fetch_today( weather_config_t * weather_config, weather_forcast_t * weather_today ); int 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_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast );
#endif // _WEATHER_FETCH_H #endif // _WEATHER_FETCH_H

View File

@@ -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_RELEASED, &refresh_32px);
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_PRESSED, &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_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 ); lv_obj_set_event_cb( reload_btn, refresh_weather_widget_event_cb );
weather_forecast_location_label = lv_label_create( weather_forecast_tile , NULL); weather_forecast_location_label = lv_label_create( weather_forecast_tile , NULL);
lv_label_set_text( weather_forecast_location_label, "n/a"); 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_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); weather_forecast_update_label = lv_label_create( weather_forecast_tile , NULL);
lv_label_set_text( weather_forecast_update_label, ""); 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_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_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_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++ ) { for ( int i = 0 ; i < WEATHER_MAX_FORECAST / 4 ; i++ ) {
weather_forecast_icon_imgbtn[ i ] = lv_imgbtn_create( weater_forecast_cont, NULL); 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"); log_i("start weather forecast task");
vTaskDelay( 250 );
if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_FORECAST_SYNC_REQUEST ) { if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_FORECAST_SYNC_REQUEST ) {
if ( weather_config->autosync ) { if ( weather_config->autosync ) {
retval = weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] ); retval = weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] );

View File

@@ -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_RELEASED, &exit_32px);
lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &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_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_set_event_cb( exit_btn, exit_weather_widget_setup_event_cb );
lv_obj_t *exit_label = lv_label_create( weather_setup_tile, NULL); 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_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_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_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_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_obj_add_style( weather_apikey_label, LV_OBJ_PART_MAIN, &weather_setup_style );
lv_label_set_text( weather_apikey_label, "appid"); lv_label_set_text( weather_apikey_label, "appid");

View File

@@ -31,6 +31,6 @@
/* /*
* firmeware version string * firmeware version string
*/ */
#define __FIRMWARE__ "2020080405" #define __FIRMWARE__ "2020080603"
#endif // _CONFIG_H #endif // _CONFIG_H

View File

@@ -28,6 +28,7 @@
#include "note_tile/note_tile.h" #include "note_tile/note_tile.h"
#include "app_tile/app_tile.h" #include "app_tile/app_tile.h"
#include "gui/keyboard.h" #include "gui/keyboard.h"
#include "gui/statusbar.h"
#include "setup_tile/battery_settings/battery_settings.h" #include "setup_tile/battery_settings/battery_settings.h"
#include "setup_tile/wlan_settings/wlan_settings.h" #include "setup_tile/wlan_settings/wlan_settings.h"
@@ -160,6 +161,7 @@ lv_obj_t *mainbar_get_tile_obj( uint32_t tile_number ) {
} }
void mainbar_jump_to_maintile( lv_anim_enable_t anim ) { void mainbar_jump_to_maintile( lv_anim_enable_t anim ) {
statusbar_hide( false );
if ( tile_entrys != 0 ) { if ( tile_entrys != 0 ) {
lv_tileview_set_tile_act( mainbar, 0, 0, anim ); lv_tileview_set_tile_act( mainbar, 0, 0, anim );
} }

View File

@@ -189,7 +189,7 @@ void update_check_version( void ) {
xEventGroupSetBits( update_event_handle, UPDATE_GET_VERSION_REQUEST ); xEventGroupSetBits( update_event_handle, UPDATE_GET_VERSION_REQUEST );
xTaskCreate( update_Task, /* Function to implement the task */ xTaskCreate( update_Task, /* Function to implement the task */
"update Task", /* Name of the task */ "update Task", /* Name of the task */
2000, /* Stack size in words */ 5000, /* Stack size in words */
NULL, /* Task input parameter */ NULL, /* Task input parameter */
1, /* Priority of the task */ 1, /* Priority of the task */
&_update_Task ); /* Task handle. */ &_update_Task ); /* Task handle. */

View File

@@ -20,81 +20,53 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include "config.h" #include "config.h"
#include <Arduino.h>
#include <WiFi.h>
#include "ArduinoJson.h" #include "ArduinoJson.h"
#include "HTTPClient.h" #include "HTTPClient.h"
#include "update_check_version.h" #include "update_check_version.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>;
uint64_t update_check_new_version( void ) { uint64_t update_check_new_version( void ) {
char url[512]="";
WiFiClient check_version_client; int httpcode = -1;
uint64_t retval = -1; uint64_t version = -1;
if ( !check_version_client.connect( FIRMWARE_HOST, FIRMWARE_HOST_PORT ) ) { snprintf( url, sizeof( url ), "http://%s/%s", FIRMWARE_HOST, FIRMWARE_VERSION_FILE );
log_e("connection failed");
HTTPClient check_update_client;
check_update_client.useHTTP10( true );
check_update_client.setUserAgent( "ESP32-" __FIRMWARE__ );
check_update_client.begin( url );
httpcode = check_update_client.GET();
if ( httpcode != 200 ) {
log_e("HTTPClient error %d", httpcode );
check_update_client.end();
return( -1 ); return( -1 );
}
check_version_client.printf( "GET /" FIRMWARE_VERSION_FILE " HTTP/1.1\r\n"
"Host: " FIRMWARE_HOST "\r\n"
"Connection: close\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"User-Agent: ESP32-" __FIRMWARE__ "\r\n"
"Accept: text/html,application/json\r\n\r\n" );
uint64_t startMillis = millis();
while ( check_version_client.available() == 0 ) {
if ( millis() - startMillis > 5000 ) {
log_e("connection timeout");
check_version_client.stop();
return( retval );
}
}
char *json = (char *)ps_malloc( 200 );
if ( json == NULL ) {
log_e("memory alloc failed");
check_version_client.stop();
return( retval );
} }
char *ptr = json;
bool data_begin = false; SpiRamJsonDocument doc( check_update_client.getSize() * 2 );
while( check_version_client.available() ) {
if ( data_begin ) {
ptr[ check_version_client.readBytes( ptr, 100 - 1 ) ] = '\0';
}
else if ( check_version_client.read() == '{' ) {
data_begin = true;
*ptr = '{';
ptr++;
}
}
check_version_client.stop(); DeserializationError error = deserializeJson( doc, check_update_client.getStream() );
if ( data_begin == false ) {
free( json );
return( retval );
}
check_version_client.stop();
DynamicJsonDocument doc( 400 );
DeserializationError error = deserializeJson( doc, json);
if (error) { if (error) {
log_e("update version deserializeJson() failed: ", error.c_str() ); log_e("update check deserializeJson() failed: %s", error.c_str() );
doc.clear(); doc.clear();
free( json ); check_update_client.end();
return( retval ); return( -1 );
} }
retval = atoll( doc["version"] ); check_update_client.end();
version = atoll( doc["version"] );
doc.clear(); doc.clear();
free( json ); return( version );
return( retval );
} }

View File

@@ -24,9 +24,11 @@
#include <TTGO.h> #include <TTGO.h>
#define FIRMWARE_HOST "www.neo-guerillaz.de" #define FIRMWARE_HOST "www.neo-guerillaz.de"
#define FIRMWARE_HOST_PORT 80 #define FIRMWARE_HOST_PORT 80
#define FIRMWARE_VERSION_FILE "ttgo-t-watch2020_v1.version.json" #define FIRMWARE_VERSION_FILE "ttgo-t-watch2020_v1.version.json"
#define UPDATE_JSON_BUFFER_SIZE 200
uint64_t update_check_new_version(); uint64_t update_check_new_version();

File diff suppressed because it is too large Load Diff

View File

@@ -34,7 +34,6 @@
#include "statusbar.h" #include "statusbar.h"
#include "hardware/motor.h"
#include "hardware/powermgm.h" #include "hardware/powermgm.h"
#include "hardware/wifictl.h" #include "hardware/wifictl.h"
@@ -193,7 +192,6 @@ void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event ) {
break; break;
default: break; default: break;
} }
motor_vibe( 1 );
} }
} }
@@ -207,7 +205,6 @@ void statusbar_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event ) {
case( LV_BTN_STATE_PRESSED ): break; case( LV_BTN_STATE_PRESSED ): break;
default: break; default: break;
} }
motor_vibe( 1 );
} }
} }
@@ -362,3 +359,7 @@ void statusbar_update_battery( int32_t percent, bool charging, bool plug ) {
} }
statusbar_refresh(); statusbar_refresh();
} }
void statusbar_hide( bool hide ) {
lv_obj_set_hidden( statusbar, hide );
}

View File

@@ -83,6 +83,7 @@
void statusbar_update_battery( int32_t percent, bool charging, bool plug ); void statusbar_update_battery( int32_t percent, bool charging, bool plug );
void statusbar_wifi_set_state( bool state, const char *wifiname ); void statusbar_wifi_set_state( bool state, const char *wifiname );
void statusbar_bluetooth_set_state( bool state ); void statusbar_bluetooth_set_state( bool state );
void statusbar_hide( bool hide );
#endif // _STATUSBAR_H #endif // _STATUSBAR_H

View File

@@ -32,6 +32,7 @@ EventGroupHandle_t bma_event_handle = NULL;
bma_config_t bma_config[ BMA_CONFIG_NUM ]; bma_config_t bma_config[ BMA_CONFIG_NUM ];
__NOINIT_ATTR uint32_t stepcounter_valid; __NOINIT_ATTR uint32_t stepcounter_valid;
__NOINIT_ATTR uint32_t stepcounter_before_reset;
__NOINIT_ATTR uint32_t stepcounter; __NOINIT_ATTR uint32_t stepcounter;
void IRAM_ATTR bma_irq( void ); void IRAM_ATTR bma_irq( void );
@@ -49,10 +50,13 @@ void bma_setup( TTGOClass *ttgo ) {
if ( stepcounter_valid != 0xa5a5a5a5 ) { if ( stepcounter_valid != 0xa5a5a5a5 ) {
stepcounter = 0; stepcounter = 0;
stepcounter_before_reset = 0;
stepcounter_valid = 0xa5a5a5a5; stepcounter_valid = 0xa5a5a5a5;
log_e("stepcounter not valid. reset"); log_i("stepcounter not valid. reset");
} }
stepcounter = stepcounter + stepcounter_before_reset;
bma_read_config(); bma_read_config();
ttgo->bma->begin(); ttgo->bma->begin();
@@ -68,6 +72,8 @@ void bma_setup( TTGOClass *ttgo ) {
void bma_standby( void ) { void bma_standby( void ) {
TTGOClass *ttgo = TTGOClass::getWatch(); TTGOClass *ttgo = TTGOClass::getWatch();
log_i("standby");
if ( bma_get_config( BMA_STEPCOUNTER ) ) if ( bma_get_config( BMA_STEPCOUNTER ) )
ttgo->bma->enableStepCountInterrupt( false ); ttgo->bma->enableStepCountInterrupt( false );
@@ -76,11 +82,13 @@ void bma_standby( void ) {
void bma_wakeup( void ) { void bma_wakeup( void ) {
TTGOClass *ttgo = TTGOClass::getWatch(); TTGOClass *ttgo = TTGOClass::getWatch();
log_i("wakeup");
if ( bma_get_config( BMA_STEPCOUNTER ) ) if ( bma_get_config( BMA_STEPCOUNTER ) )
ttgo->bma->enableStepCountInterrupt( true ); ttgo->bma->enableStepCountInterrupt( true );
stepcounter =+ ttgo->bma->getCounter(); stepcounter_before_reset = ttgo->bma->getCounter();
statusbar_update_stepcounter( stepcounter ); statusbar_update_stepcounter( stepcounter + ttgo->bma->getCounter() );
} }
/* /*
@@ -126,8 +134,8 @@ void bma_loop( TTGOClass *ttgo ) {
} }
if ( !powermgm_get_event( POWERMGM_STANDBY ) && xEventGroupGetBitsFromISR( bma_event_handle ) & BMA_EVENT_INT ) { if ( !powermgm_get_event( POWERMGM_STANDBY ) && xEventGroupGetBitsFromISR( bma_event_handle ) & BMA_EVENT_INT ) {
stepcounter =+ ttgo->bma->getCounter(); stepcounter_before_reset = ttgo->bma->getCounter();
statusbar_update_stepcounter( stepcounter ); statusbar_update_stepcounter( stepcounter + ttgo->bma->getCounter() );
xEventGroupClearBitsFromISR( bma_event_handle, BMA_EVENT_INT ); xEventGroupClearBitsFromISR( bma_event_handle, BMA_EVENT_INT );
} }
} }

View File

@@ -69,7 +69,7 @@ void display_loop( TTGOClass *ttgo ) {
void display_standby( void ) { void display_standby( void ) {
TTGOClass *ttgo = TTGOClass::getWatch(); TTGOClass *ttgo = TTGOClass::getWatch();
log_i("standby");
ttgo->bl->adjust( 0 ); ttgo->bl->adjust( 0 );
ttgo->displaySleep(); ttgo->displaySleep();
ttgo->closeBL(); ttgo->closeBL();

View File

@@ -74,7 +74,12 @@ void pmu_standby( void ) {
TTGOClass *ttgo = TTGOClass::getWatch(); TTGOClass *ttgo = TTGOClass::getWatch();
ttgo->power->clearTimerStatus(); ttgo->power->clearTimerStatus();
ttgo->power->setTimer( 60 ); if ( ttgo->power->isChargeing() ) {
ttgo->power->setTimer( 10 );
}
else {
ttgo->power->setTimer( 60 );
}
if ( pmu_get_experimental_power_save() ) { if ( pmu_get_experimental_power_save() ) {
ttgo->power->setDCDC3Voltage( 2700 ); ttgo->power->setDCDC3Voltage( 2700 );
@@ -213,11 +218,11 @@ void pmu_loop( TTGOClass *ttgo ) {
} }
int32_t pmu_get_battery_percent( TTGOClass *ttgo ) { int32_t pmu_get_battery_percent( TTGOClass *ttgo ) {
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() || ttgo->power->getBattVoltage() < 3200 ) {
ttgo->power->ClearCoulombcounter();
}
if ( pmu_get_calculated_percent() ) { if ( pmu_get_calculated_percent() ) {
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() || ttgo->power->getBattVoltage() < 3200 ) {
ttgo->power->ClearCoulombcounter();
return( -1 );
}
return( ( ttgo->power->getCoulombData() / PMU_BATTERY_CAP ) * 100 ); return( ( ttgo->power->getCoulombData() / PMU_BATTERY_CAP ) * 100 );
} }
else { else {

View File

@@ -24,7 +24,10 @@
#include <soc/rtc.h> #include <soc/rtc.h>
#include <WiFi.h> #include <WiFi.h>
#include <esp_wifi.h> #include <esp_wifi.h>
#include <esp_bt.h>
#include <esp_bt_main.h>
#include <time.h> #include <time.h>
#include "driver/adc.h"
#include "pmu.h" #include "pmu.h"
#include "bma.h" #include "bma.h"
@@ -73,6 +76,8 @@ void powermgm_loop( TTGOClass *ttgo ) {
if ( powermgm_get_event( POWERMGM_STANDBY ) ) { if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
powermgm_clear_event( POWERMGM_STANDBY ); powermgm_clear_event( POWERMGM_STANDBY );
log_i("go wakeup");
pmu_wakeup(); pmu_wakeup();
bma_wakeup(); bma_wakeup();
display_wakeup(); display_wakeup();
@@ -82,10 +87,8 @@ void powermgm_loop( TTGOClass *ttgo ) {
lv_disp_trig_activity(NULL); lv_disp_trig_activity(NULL);
wifictl_wakeup(); wifictl_wakeup();
log_i("go wakeup");
} }
else { else {
log_i("go standby");
display_standby(); display_standby();
mainbar_jump_to_maintile( LV_ANIM_OFF ); mainbar_jump_to_maintile( LV_ANIM_OFF );
@@ -99,11 +102,17 @@ void powermgm_loop( TTGOClass *ttgo ) {
powermgm_set_event( POWERMGM_STANDBY ); powermgm_set_event( POWERMGM_STANDBY );
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP ); powermgm_clear_event( POWERMGM_SILENCE_WAKEUP );
setCpuFrequencyMhz( 10 ); adc_power_off();
log_i("go standby");
setCpuFrequencyMhz( 80 );
gpio_wakeup_enable ( (gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL ); gpio_wakeup_enable ( (gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL );
gpio_wakeup_enable ( (gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL ); gpio_wakeup_enable ( (gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL );
esp_sleep_enable_gpio_wakeup (); esp_sleep_enable_gpio_wakeup ();
esp_light_sleep_start(); esp_light_sleep_start();
// from here, the consumption is round about 2.5mA
// total standby time is 152h (6days) without use?
} }
// clear event // clear event
powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP | POWERMGM_STANDBY_REQUEST | POWERMGM_SILENCE_WAKEUP_REQUEST ); powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP | POWERMGM_STANDBY_REQUEST | POWERMGM_SILENCE_WAKEUP_REQUEST );

View File

@@ -26,6 +26,7 @@
#include "gui/sound/snd_start.h" #include "gui/sound/snd_start.h"
#include "gui/sound/snd_signal.h" #include "gui/sound/snd_signal.h"
EventGroupHandle_t sound_event_handle = NULL;
TaskHandle_t _sound_Task; TaskHandle_t _sound_Task;
void sound_Task( void * pvParameters ); void sound_Task( void * pvParameters );
@@ -63,6 +64,8 @@ void sound_setup( void ) {
while (true); while (true);
} }
sound_event_handle = xEventGroupCreate();
xTaskCreate( sound_Task, /* Function to implement the task */ xTaskCreate( sound_Task, /* Function to implement the task */
"sound Task", /* Name of the task */ "sound Task", /* Name of the task */
2000, /* Stack size in words */ 2000, /* Stack size in words */

View File

@@ -24,6 +24,10 @@
#include <TTGO.h> #include <TTGO.h>
#define SOUND_EVENT_PLAYING _BV(0)
#define SOUND_EVENT_STARTUP _BV(1)
#define SOUND_EVENT_NOTIFICATION _BV(2)
#define I2S_PORT I2S_NUM_0 #define I2S_PORT I2S_NUM_0
void sound_setup( void ); void sound_setup( void );

View File

@@ -313,12 +313,14 @@ void wifictl_off( void ) {
} }
void wifictl_standby( void ) { void wifictl_standby( void ) {
log_i("standby");
if ( powermgm_get_event( POWERMGM_WIFI_ACTIVE ) ) wifictl_off(); if ( powermgm_get_event( POWERMGM_WIFI_ACTIVE ) ) wifictl_off();
while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN ) ) { yield(); } while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN ) ) { yield(); }
} }
void wifictl_wakeup( void ) { void wifictl_wakeup( void ) {
if ( wifictl_config.autoon ) { if ( wifictl_config.autoon ) {
log_i("wakeup");
wifictl_on(); wifictl_on();
} }
} }

Binary file not shown.

View File

@@ -1 +1 @@
{"version":"2020080405","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"} {"version":"2020080603","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}