some fixes and firmware stabilization
This commit is contained in:
@@ -15,6 +15,7 @@ framework = arduino
|
||||
board_build.f_flash = 80000000L
|
||||
monitor_speed = 115200
|
||||
build_flags =
|
||||
; -DCORE_DEBUG_LEVEL=3
|
||||
-DBOARD_HAS_PSRAM
|
||||
-mfix-esp32-psram-cache-issue
|
||||
src_filter =
|
||||
|
||||
@@ -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 ) {
|
||||
int weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) {
|
||||
char url[512]="";
|
||||
int httpcode = -1;
|
||||
|
||||
WiFiClient today_client;
|
||||
uint32_t retval = -1;
|
||||
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);
|
||||
|
||||
if ( !today_client.connect( OWM_HOST, OWM_PORT ) ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
SpiRamJsonDocument doc( today_client.getSize() * 2 );
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
int weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) {
|
||||
char url[512]="";
|
||||
int httpcode = -1;
|
||||
|
||||
WiFiClient forecast_client;
|
||||
uint32_t retval = -1;
|
||||
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);
|
||||
|
||||
if ( !forecast_client.connect( OWM_HOST, OWM_PORT ) ) {
|
||||
log_e("connection failed");
|
||||
return( retval );
|
||||
HTTPClient forecast_client;
|
||||
|
||||
forecast_client.useHTTP10( true );
|
||||
forecast_client.begin( url );
|
||||
httpcode = forecast_client.GET();
|
||||
|
||||
if ( httpcode != 200 ) {
|
||||
log_e("HTTPClient error %d", httpcode );
|
||||
forecast_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
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 );
|
||||
SpiRamJsonDocument doc( forecast_client.getSize() * 2 );
|
||||
|
||||
uint64_t startMillis = millis();
|
||||
while ( forecast_client.available() == 0 ) {
|
||||
if ( millis() - startMillis > 5000 ) {
|
||||
log_e("connection timeout");
|
||||
forecast_client.stop();
|
||||
return( retval );
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
DynamicJsonDocument doc(20000);
|
||||
DeserializationError error = deserializeJson( doc, json );
|
||||
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");
|
||||
|
||||
@@ -31,6 +31,6 @@
|
||||
/*
|
||||
* firmeware version string
|
||||
*/
|
||||
#define __FIRMWARE__ "2020080405"
|
||||
#define __FIRMWARE__ "2020080603"
|
||||
|
||||
#endif // _CONFIG_H
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "note_tile/note_tile.h"
|
||||
#include "app_tile/app_tile.h"
|
||||
#include "gui/keyboard.h"
|
||||
#include "gui/statusbar.h"
|
||||
|
||||
#include "setup_tile/battery_settings/battery_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 ) {
|
||||
statusbar_hide( false );
|
||||
if ( tile_entrys != 0 ) {
|
||||
lv_tileview_set_tile_act( mainbar, 0, 0, anim );
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ void update_check_version( void ) {
|
||||
xEventGroupSetBits( update_event_handle, UPDATE_GET_VERSION_REQUEST );
|
||||
xTaskCreate( update_Task, /* Function to implement the task */
|
||||
"update Task", /* Name of the task */
|
||||
2000, /* Stack size in words */
|
||||
5000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_update_Task ); /* Task handle. */
|
||||
|
||||
@@ -20,81 +20,53 @@
|
||||
* 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"
|
||||
|
||||
#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 ) {
|
||||
char url[512]="";
|
||||
int httpcode = -1;
|
||||
uint64_t version = -1;
|
||||
|
||||
WiFiClient check_version_client;
|
||||
uint64_t retval = -1;
|
||||
snprintf( url, sizeof( url ), "http://%s/%s", FIRMWARE_HOST, FIRMWARE_VERSION_FILE );
|
||||
|
||||
if ( !check_version_client.connect( FIRMWARE_HOST, FIRMWARE_HOST_PORT ) ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
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" );
|
||||
SpiRamJsonDocument doc( check_update_client.getSize() * 2 );
|
||||
|
||||
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;
|
||||
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();
|
||||
|
||||
if ( data_begin == false ) {
|
||||
free( json );
|
||||
return( retval );
|
||||
}
|
||||
check_version_client.stop();
|
||||
|
||||
DynamicJsonDocument doc( 400 );
|
||||
|
||||
DeserializationError error = deserializeJson( doc, json);
|
||||
DeserializationError error = deserializeJson( doc, check_update_client.getStream() );
|
||||
if (error) {
|
||||
log_e("update version deserializeJson() failed: ", error.c_str() );
|
||||
log_e("update check deserializeJson() failed: %s", error.c_str() );
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
check_update_client.end();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
retval = atoll( doc["version"] );
|
||||
check_update_client.end();
|
||||
|
||||
version = atoll( doc["version"] );
|
||||
|
||||
doc.clear();
|
||||
free( json );
|
||||
return( retval );
|
||||
return( version );
|
||||
}
|
||||
@@ -28,6 +28,8 @@
|
||||
#define FIRMWARE_HOST_PORT 80
|
||||
#define FIRMWARE_VERSION_FILE "ttgo-t-watch2020_v1.version.json"
|
||||
|
||||
#define UPDATE_JSON_BUFFER_SIZE 200
|
||||
|
||||
uint64_t update_check_new_version();
|
||||
|
||||
#endif // _UPDATE_CHECK_VERSION_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,7 +34,6 @@
|
||||
|
||||
#include "statusbar.h"
|
||||
|
||||
#include "hardware/motor.h"
|
||||
#include "hardware/powermgm.h"
|
||||
#include "hardware/wifictl.h"
|
||||
|
||||
@@ -193,7 +192,6 @@ void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event ) {
|
||||
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;
|
||||
default: break;
|
||||
}
|
||||
motor_vibe( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,3 +359,7 @@ void statusbar_update_battery( int32_t percent, bool charging, bool plug ) {
|
||||
}
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
void statusbar_hide( bool hide ) {
|
||||
lv_obj_set_hidden( statusbar, hide );
|
||||
}
|
||||
@@ -83,6 +83,7 @@
|
||||
void statusbar_update_battery( int32_t percent, bool charging, bool plug );
|
||||
void statusbar_wifi_set_state( bool state, const char *wifiname );
|
||||
void statusbar_bluetooth_set_state( bool state );
|
||||
void statusbar_hide( bool hide );
|
||||
|
||||
#endif // _STATUSBAR_H
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ EventGroupHandle_t bma_event_handle = NULL;
|
||||
bma_config_t bma_config[ BMA_CONFIG_NUM ];
|
||||
|
||||
__NOINIT_ATTR uint32_t stepcounter_valid;
|
||||
__NOINIT_ATTR uint32_t stepcounter_before_reset;
|
||||
__NOINIT_ATTR uint32_t stepcounter;
|
||||
|
||||
void IRAM_ATTR bma_irq( void );
|
||||
@@ -49,10 +50,13 @@ void bma_setup( TTGOClass *ttgo ) {
|
||||
|
||||
if ( stepcounter_valid != 0xa5a5a5a5 ) {
|
||||
stepcounter = 0;
|
||||
stepcounter_before_reset = 0;
|
||||
stepcounter_valid = 0xa5a5a5a5;
|
||||
log_e("stepcounter not valid. reset");
|
||||
log_i("stepcounter not valid. reset");
|
||||
}
|
||||
|
||||
stepcounter = stepcounter + stepcounter_before_reset;
|
||||
|
||||
bma_read_config();
|
||||
|
||||
ttgo->bma->begin();
|
||||
@@ -68,6 +72,8 @@ void bma_setup( TTGOClass *ttgo ) {
|
||||
void bma_standby( void ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
log_i("standby");
|
||||
|
||||
if ( bma_get_config( BMA_STEPCOUNTER ) )
|
||||
ttgo->bma->enableStepCountInterrupt( false );
|
||||
|
||||
@@ -76,11 +82,13 @@ void bma_standby( void ) {
|
||||
void bma_wakeup( void ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
log_i("wakeup");
|
||||
|
||||
if ( bma_get_config( BMA_STEPCOUNTER ) )
|
||||
ttgo->bma->enableStepCountInterrupt( true );
|
||||
|
||||
stepcounter =+ ttgo->bma->getCounter();
|
||||
statusbar_update_stepcounter( stepcounter );
|
||||
stepcounter_before_reset = ttgo->bma->getCounter();
|
||||
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 ) {
|
||||
stepcounter =+ ttgo->bma->getCounter();
|
||||
statusbar_update_stepcounter( stepcounter );
|
||||
stepcounter_before_reset = ttgo->bma->getCounter();
|
||||
statusbar_update_stepcounter( stepcounter + ttgo->bma->getCounter() );
|
||||
xEventGroupClearBitsFromISR( bma_event_handle, BMA_EVENT_INT );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ void display_loop( TTGOClass *ttgo ) {
|
||||
|
||||
void display_standby( void ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
log_i("standby");
|
||||
ttgo->bl->adjust( 0 );
|
||||
ttgo->displaySleep();
|
||||
ttgo->closeBL();
|
||||
|
||||
@@ -74,7 +74,12 @@ void pmu_standby( void ) {
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
ttgo->power->clearTimerStatus();
|
||||
if ( ttgo->power->isChargeing() ) {
|
||||
ttgo->power->setTimer( 10 );
|
||||
}
|
||||
else {
|
||||
ttgo->power->setTimer( 60 );
|
||||
}
|
||||
|
||||
if ( pmu_get_experimental_power_save() ) {
|
||||
ttgo->power->setDCDC3Voltage( 2700 );
|
||||
@@ -213,11 +218,11 @@ void pmu_loop( TTGOClass *ttgo ) {
|
||||
}
|
||||
|
||||
int32_t pmu_get_battery_percent( TTGOClass *ttgo ) {
|
||||
if ( pmu_get_calculated_percent() ) {
|
||||
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() || ttgo->power->getBattVoltage() < 3200 ) {
|
||||
ttgo->power->ClearCoulombcounter();
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if ( pmu_get_calculated_percent() ) {
|
||||
return( ( ttgo->power->getCoulombData() / PMU_BATTERY_CAP ) * 100 );
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -24,7 +24,10 @@
|
||||
#include <soc/rtc.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_bt.h>
|
||||
#include <esp_bt_main.h>
|
||||
#include <time.h>
|
||||
#include "driver/adc.h"
|
||||
|
||||
#include "pmu.h"
|
||||
#include "bma.h"
|
||||
@@ -73,6 +76,8 @@ void powermgm_loop( TTGOClass *ttgo ) {
|
||||
if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
|
||||
powermgm_clear_event( POWERMGM_STANDBY );
|
||||
|
||||
log_i("go wakeup");
|
||||
|
||||
pmu_wakeup();
|
||||
bma_wakeup();
|
||||
display_wakeup();
|
||||
@@ -82,10 +87,8 @@ void powermgm_loop( TTGOClass *ttgo ) {
|
||||
lv_disp_trig_activity(NULL);
|
||||
|
||||
wifictl_wakeup();
|
||||
log_i("go wakeup");
|
||||
}
|
||||
else {
|
||||
log_i("go standby");
|
||||
display_standby();
|
||||
mainbar_jump_to_maintile( LV_ANIM_OFF );
|
||||
|
||||
@@ -99,11 +102,17 @@ void powermgm_loop( TTGOClass *ttgo ) {
|
||||
powermgm_set_event( POWERMGM_STANDBY );
|
||||
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)BMA423_INT1, GPIO_INTR_HIGH_LEVEL );
|
||||
esp_sleep_enable_gpio_wakeup ();
|
||||
esp_light_sleep_start();
|
||||
// from here, the consumption is round about 2.5mA
|
||||
// total standby time is 152h (6days) without use?
|
||||
}
|
||||
// clear event
|
||||
powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP | POWERMGM_STANDBY_REQUEST | POWERMGM_SILENCE_WAKEUP_REQUEST );
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "gui/sound/snd_start.h"
|
||||
#include "gui/sound/snd_signal.h"
|
||||
|
||||
EventGroupHandle_t sound_event_handle = NULL;
|
||||
TaskHandle_t _sound_Task;
|
||||
void sound_Task( void * pvParameters );
|
||||
|
||||
@@ -63,6 +64,8 @@ void sound_setup( void ) {
|
||||
while (true);
|
||||
}
|
||||
|
||||
sound_event_handle = xEventGroupCreate();
|
||||
|
||||
xTaskCreate( sound_Task, /* Function to implement the task */
|
||||
"sound Task", /* Name of the task */
|
||||
2000, /* Stack size in words */
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
|
||||
#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
|
||||
|
||||
void sound_setup( void );
|
||||
|
||||
@@ -313,12 +313,14 @@ void wifictl_off( void ) {
|
||||
}
|
||||
|
||||
void wifictl_standby( void ) {
|
||||
log_i("standby");
|
||||
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(); }
|
||||
}
|
||||
|
||||
void wifictl_wakeup( void ) {
|
||||
if ( wifictl_config.autoon ) {
|
||||
log_i("wakeup");
|
||||
wifictl_on();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user