diff --git a/src/config.h b/src/config.h index bb6feb9..20697f9 100644 --- a/src/config.h +++ b/src/config.h @@ -31,6 +31,6 @@ /* * firmeware version string */ - #define __FIRMWARE__ "2020072708" + #define __FIRMWARE__ "2020072804" #endif // _CONFIG_H diff --git a/src/gui/mainbar/setup_tile/update/update.cpp b/src/gui/mainbar/setup_tile/update/update.cpp index a013d7c..b8d99ba 100644 --- a/src/gui/mainbar/setup_tile/update/update.cpp +++ b/src/gui/mainbar/setup_tile/update/update.cpp @@ -26,6 +26,8 @@ #include #include "update.h" +#include "update_check_version.h" + #include "gui/mainbar/mainbar.h" #include "gui/statusbar.h" #include "hardware/display.h" @@ -97,7 +99,12 @@ void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_c lv_obj_add_style( update_status_label, LV_OBJ_PART_MAIN, style ); lv_label_set_text( update_status_label, "" ); lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 ); - + + // regster callback + WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { + update_check_version(); + }, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP ); + update_event_handle = xEventGroupCreate(); xEventGroupClearBits( update_event_handle, UPDATE_REQUEST ); @@ -131,9 +138,26 @@ static void update_event_handler(lv_obj_t * obj, lv_event_t event) { } } +void update_check_version( void ) { + if ( xEventGroupGetBits( update_event_handle ) & UPDATE_GET_VERSION_REQUEST ) { + return; + } + else { + xEventGroupSetBits( update_event_handle, UPDATE_GET_VERSION_REQUEST ); + vTaskResume( _update_Task ); + } +} + void update_Task( void * pvParameters ) { while( true ) { vTaskDelay( 500 ); + if ( xEventGroupGetBits( update_event_handle) & UPDATE_GET_VERSION_REQUEST ) { + if ( update_check_new_version() > atol( __FIRMWARE__ ) ) { + lv_label_set_text( update_status_label, "new version available" ); + lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 ); + } + xEventGroupClearBits( update_event_handle, UPDATE_GET_VERSION_REQUEST ); + } if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) { if( WiFi.status() == WL_CONNECTED ) { diff --git a/src/gui/mainbar/setup_tile/update/update.h b/src/gui/mainbar/setup_tile/update/update.h index 61eaff5..6558b13 100644 --- a/src/gui/mainbar/setup_tile/update/update.h +++ b/src/gui/mainbar/setup_tile/update/update.h @@ -24,11 +24,13 @@ #include - #define UPDATE_REQUEST _BV(0) + #define UPDATE_REQUEST _BV(0) + #define UPDATE_GET_VERSION_REQUEST _BV(1) #define FIRMWARE_LOCATION "https://github.com/sharandac/My-TTGO-Watch/blob/master/ttgo-t-watch2020_v1.ino.bin" void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ); + void update_check_version( void ); void update_update_firmware( void ); #endif // _UPDATE_H \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/update/update_check_version.cpp b/src/gui/mainbar/setup_tile/update/update_check_version.cpp new file mode 100644 index 0000000..f9f528d --- /dev/null +++ b/src/gui/mainbar/setup_tile/update/update_check_version.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** + * July 28 00:23:05 2020 + * Copyright 2020 Dirk Brosswick + * Email: dirk.brosswick@googlemail.com + ****************************************************************************/ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#include "config.h" +#include +#include +#include "ArduinoJson.h" +#include "HTTPClient.h" + +#include "update_check_version.h" + +uint64_t update_check_new_version( void ) { + + WiFiClient check_version_client; + uint64_t retval = -1; + + if ( !check_version_client.connect( FIRMWARE_HOST, FIRMWARE_HOST_PORT ) ) { + Serial.printf("connection failed\r\n"); + return( -1 ); + } + + check_version_client.printf( "GET /ttgo-t-watch2020_v1.version.json 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", FIRMWARE_HOST ); + + uint64_t startMillis = millis(); + while ( check_version_client.available() == 0 ) { + if ( millis() - startMillis > 5000 ) { + Serial.printf("connection timeout\r\n"); + check_version_client.stop(); + return( retval ); + } + } + + char *json = (char *)ps_malloc( 100 ); + if ( json == NULL ) { + Serial.printf("memory alloc failed\r\n"); + 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(200); + + DeserializationError error = deserializeJson( doc, json); + if (error) { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(error.c_str()); + doc.clear(); + free( json ); + return( retval ); + } + + retval = atoll( doc["version"] ); + + doc.clear(); + free( json ); + return( retval ); +} \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/update/update_check_version.h b/src/gui/mainbar/setup_tile/update/update_check_version.h new file mode 100644 index 0000000..0f4d154 --- /dev/null +++ b/src/gui/mainbar/setup_tile/update/update_check_version.h @@ -0,0 +1,32 @@ +/**************************************************************************** + * July 28 00:23:05 2020 + * Copyright 2020 Dirk Brosswick + * Email: dirk.brosswick@googlemail.com + ****************************************************************************/ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#ifndef _UPDATE_CHECK_VERSION_H + #define _UPDATE_CHECK_VERSION_H + + #include + + #define FIRMWARE_HOST "www.neo-guerillaz.de" + #define FIRMWARE_HOST_PORT 80 + + uint64_t update_check_new_version(); + +#endif // _UPDATE_CHECK_VERSION_H \ No newline at end of file diff --git a/src/gui/widget/weather/weather.h b/src/gui/widget/weather/weather.h index ce92789..ec82b03 100644 --- a/src/gui/widget/weather/weather.h +++ b/src/gui/widget/weather/weather.h @@ -37,6 +37,7 @@ typedef struct { bool valide = false; + time_t timestamp = 0; char temp[8] = ""; char pressure[8] = ""; char humidity[8] = ""; diff --git a/src/gui/widget/weather/weather_fetch.cpp b/src/gui/widget/weather/weather_fetch.cpp index e7f8ce1..d5d52be 100644 --- a/src/gui/widget/weather/weather_fetch.cpp +++ b/src/gui/widget/weather/weather_fetch.cpp @@ -185,7 +185,7 @@ uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forca retval = doc["cod"].as(); if ( retval != 200 ) { - Serial.printf("get weather failed, returncode: %d\r\n", retval ); + Serial.printf("get weather forecast failed, returncode: %d\r\n", retval ); doc.clear(); free( json ); return( retval ); @@ -193,6 +193,7 @@ uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forca weather_forecast[0].valide = true; for ( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) { + weather_forecast[ i ].timestamp = doc["list"][i]["dt"].as(); snprintf( weather_forecast[ i ].temp, sizeof( weather_forecast[ i ].temp ),"%0.1f°C", doc["list"][i]["main"]["temp"].as() - 273.15 ); snprintf( weather_forecast[ i ].humidity, sizeof( weather_forecast[ i ].humidity ),"%f%%", doc["list"][i]["main"]["humidity"].as() ); snprintf( weather_forecast[ i ].pressure, sizeof( weather_forecast[ i ].pressure ),"%fpha", doc["list"][i]["main"]["pressure"].as() ); diff --git a/src/gui/widget/weather/weather_forecast.cpp b/src/gui/widget/weather/weather_forecast.cpp index ad784a3..e4b7d40 100644 --- a/src/gui/widget/weather/weather_forecast.cpp +++ b/src/gui/widget/weather/weather_forecast.cpp @@ -41,6 +41,7 @@ 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_update_label = NULL; +lv_obj_t *weather_forecast_time_label[ WEATHER_MAX_FORECAST ]; 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; @@ -87,7 +88,7 @@ void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hr 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_align( weather_forecast_location_label, tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 ); weather_forecast_update_label = lv_label_create( tile , NULL); lv_label_set_text( weather_forecast_update_label, ""); @@ -95,7 +96,7 @@ void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hr lv_obj_align( weather_forecast_update_label, weather_forecast_location_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0 ); lv_obj_t * weater_forecast_cont = lv_obj_create( tile, NULL ); - lv_obj_set_size( weater_forecast_cont, hres , 80 ); + lv_obj_set_size( weater_forecast_cont, hres , 96 ); lv_obj_add_style( weater_forecast_cont, LV_OBJ_PART_MAIN, style ); lv_obj_align( weater_forecast_cont, tile, LV_ALIGN_CENTER, 0, 10 ); @@ -106,12 +107,17 @@ void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hr 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 ); + lv_obj_align( weather_forecast_icon_imgbtn[ i ], weater_forecast_cont, LV_ALIGN_IN_LEFT_MID, i*58, 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); + + weather_forecast_time_label[ i ] = lv_label_create( weater_forecast_cont , NULL); + lv_label_set_text( weather_forecast_time_label[ i ], "n/a"); + lv_obj_reset_style_list( weather_forecast_time_label[ i ], LV_OBJ_PART_MAIN ); + lv_obj_align( weather_forecast_time_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_TOP_MID, 0, 0); } // regster callback for wifi sync @@ -177,23 +183,31 @@ void weather_forecast_sync_Task( void * pvParameters ) { if ( weather_config->autosync ) { retval = weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] ); if ( retval == 200 ) { - 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 ) ); + time_t now; + struct tm info; + char buf[64]; - time_t now; - struct tm info; - char buf[64]; - time( &now ); - localtime_r( &now, &info ); - strftime( buf, sizeof(buf), "updated: %d.%b %H:%M", &info ); - lv_label_set_text( weather_forecast_update_label, buf ); + lv_label_set_text( weather_forecast_location_label, weather_forecast[ 0 ].name ); + + for( int i = 0 ; i < WEATHER_MAX_FORECAST / 4 ; i++ ) { + lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_RELEASED, resolve_owm_icon( weather_forecast[ i * 2 ].icon ) ); + lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_PRESSED, resolve_owm_icon( weather_forecast[ i * 2 ].icon ) ); + lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_RELEASED, resolve_owm_icon( weather_forecast[ i * 2 ].icon ) ); + lv_imgbtn_set_src( weather_forecast_icon_imgbtn[ i ], LV_BTN_STATE_CHECKED_PRESSED, resolve_owm_icon( weather_forecast[ i * 2 ].icon ) ); + + lv_label_set_text( weather_forecast_temperature_label[ i ], weather_forecast[ i * 2 ].temp ); + lv_obj_align( weather_forecast_temperature_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + + localtime_r( &weather_forecast[ i * 2 ].timestamp, &info ); + strftime( buf, sizeof(buf), "%H:%M", &info ); + lv_label_set_text( weather_forecast_time_label[ i ], buf ); + lv_obj_align( weather_forecast_time_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_TOP_MID, 0, 0); } + + time( &now ); + localtime_r( &now, &info ); + strftime( buf, sizeof(buf), "updated: %d.%b %H:%M", &info ); + lv_label_set_text( weather_forecast_update_label, buf ); } else { char buf[64]; diff --git a/src/gui/widget/weather/weather_forecast.h b/src/gui/widget/weather/weather_forecast.h index 71fff04..52c9bd2 100644 --- a/src/gui/widget/weather/weather_forecast.h +++ b/src/gui/widget/weather/weather_forecast.h @@ -3,7 +3,7 @@ #include - #define WEATHER_FORECAST_SYNC_REQUEST _BV(0) + #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 ); diff --git a/ttgo-t-watch2020_v1.ino.bin b/ttgo-t-watch2020_v1.ino.bin index ec1df93..8ff015f 100644 Binary files a/ttgo-t-watch2020_v1.ino.bin and b/ttgo-t-watch2020_v1.ino.bin differ diff --git a/ttgo-t-watch2020_v1.version.json b/ttgo-t-watch2020_v1.version.json new file mode 100644 index 0000000..43d8bb3 --- /dev/null +++ b/ttgo-t-watch2020_v1.version.json @@ -0,0 +1 @@ +{"version":"2020072804"} diff --git a/ttgo-t-watch2020_v1.version.txt b/ttgo-t-watch2020_v1.version.txt deleted file mode 100644 index b1b9194..0000000 --- a/ttgo-t-watch2020_v1.version.txt +++ /dev/null @@ -1 +0,0 @@ -2020072708