diff --git a/src/config.h b/src/config.h index bb883e9..ba55abe 100644 --- a/src/config.h +++ b/src/config.h @@ -31,6 +31,6 @@ /* * firmeware version string */ - #define __FIRMWARE__ "2020072408" + #define __FIRMWARE__ "2020072703" #endif // _CONFIG_H diff --git a/src/gui/mainbar/setup_tile/update/update.cpp b/src/gui/mainbar/setup_tile/update/update.cpp index e0e4264..19b43af 100644 --- a/src/gui/mainbar/setup_tile/update/update.cpp +++ b/src/gui/mainbar/setup_tile/update/update.cpp @@ -118,8 +118,13 @@ static void exit_update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { static void update_event_handler(lv_obj_t * obj, lv_event_t event) { if(event == LV_EVENT_CLICKED) { - xEventGroupSetBits( update_event_handle, UPDATE_REQUEST ); - vTaskResume( _update_Task ); + if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) { + return; + } + else { + xEventGroupSetBits( update_event_handle, UPDATE_REQUEST ); + vTaskResume( _update_Task ); + } } } @@ -133,7 +138,6 @@ void update_Task( void * pvParameters ) { display_set_timeout( DISPLAY_MAX_TIMEOUT ); WiFiClient client; - client.setTimeout( 10 ); lv_label_set_text( update_status_label, "start update ..." ); lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 ); @@ -164,6 +168,7 @@ void update_Task( void * pvParameters ) { } xEventGroupClearBits( update_event_handle, UPDATE_REQUEST ); } + lv_disp_trig_activity(NULL); vTaskSuspend( _update_Task ); } } \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp index 2a44583..a77e599 100644 --- a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp +++ b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp @@ -224,7 +224,6 @@ static void wifi_onoff_event_handler(lv_obj_t * obj, lv_event_t event) { void wifi_settings_enter_pass_event_cb( lv_obj_t * obj, lv_event_t event ) { if(event == LV_EVENT_CLICKED) { -// strcpy( ssid, lv_list_get_btn_text(obj) ); lv_label_set_text( wlan_password_name_label, lv_list_get_btn_text(obj) ); lv_textarea_set_text( wlan_password_pass_textfield, ""); mainbar_jump_to_tilenumber( WLAN_PASSWORD_TILE, LV_ANIM_ON ); diff --git a/src/gui/widget/weather/weather.cpp b/src/gui/widget/weather/weather.cpp index 73e3d65..f5f4efe 100644 --- a/src/gui/widget/weather/weather.cpp +++ b/src/gui/widget/weather/weather.cpp @@ -91,7 +91,7 @@ void weather_widget_setup( void ) { xTaskCreate( weather_widget_sync_Task, /* Function to implement the task */ "weather sync Task", /* Name of the task */ - 2000, /* Stack size in words */ + 5000, /* Stack size in words */ NULL, /* Task input parameter */ 1, /* Priority of the task */ &_weather_widget_sync_Task ); /* Task handle. */ @@ -114,8 +114,13 @@ void weather_jump_to_setup( void ) { } void weather_widget_sync_request( void ) { - xEventGroupSetBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST ); - vTaskResume( _weather_widget_sync_Task ); + if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) { + return; + } + else { + xEventGroupSetBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST ); + vTaskResume( _weather_widget_sync_Task ); + } } weather_config_t *weather_get_config( void ) { @@ -123,20 +128,22 @@ weather_config_t *weather_get_config( void ) { } void weather_widget_sync_Task( void * pvParameters ) { + uint32_t retval = -1; while( true ) { vTaskDelay( 500 ); if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) { if ( weather_config.autosync ) { - weather_fetch_today( &weather_config, &weather_today ); - if ( weather_today.valide ) { + uint32_t retval = weather_fetch_today( &weather_config, &weather_today ); + if ( retval == 200 ) { lv_label_set_text( weather_widget_temperature_label, weather_today.temp ); lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_RELEASED, resolve_owm_icon( weather_today.icon ) ); lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_PRESSED, resolve_owm_icon( weather_today.icon ) ); lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_RELEASED, resolve_owm_icon( weather_today.icon ) ); lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_PRESSED, resolve_owm_icon( weather_today.icon ) ); lv_obj_align( weather_widget_temperature_label, weather_widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0); - } + motor_vibe( 1 ); + } } xEventGroupClearBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST ); } diff --git a/src/gui/widget/weather/weather_fetch.cpp b/src/gui/widget/weather/weather_fetch.cpp index ac69f78..4ea1f6f 100644 --- a/src/gui/widget/weather/weather_fetch.cpp +++ b/src/gui/widget/weather/weather_fetch.cpp @@ -29,15 +29,14 @@ #include "weather_fetch.h" #include "weather_forecast.h" -void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) { +uint32_t weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *weather_today ) { WiFiClient today_client; - - weather_today->valide = false; + uint32_t retval = -1; if ( !today_client.connect( OWM_HOST, OWM_PORT ) ) { Serial.println("Connection failed"); - return; + return( -1 ); } today_client.printf( "GET /data/2.5/weather?lat=%s&lon=%s&appid=%s HTTP/1.1\r\n" @@ -50,10 +49,9 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w uint64_t startMillis = millis(); while ( today_client.available() == 0 ) { - yield(); if ( millis() - startMillis > 5000 ) { today_client.stop(); - return; + return( retval ); } } @@ -62,7 +60,6 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w bool data_begin = false; while( today_client.available() ) { - yield(); if ( data_begin ) { *ptr = today_client.read(); ptr++; @@ -75,10 +72,9 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w } *ptr = '\0'; if ( data_begin == false ) { - return; + return( retval ); } - yield(); today_client.stop(); DynamicJsonDocument doc(20000); @@ -89,10 +85,17 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w Serial.println(error.c_str()); doc.clear(); free( json ); - return; + return( retval ); + } + + retval = doc["cod"].as(); + + if ( retval != 200 ) { + doc.clear(); + free( json ); + return( retval ); } - yield(); weather_today->valide = true; snprintf( weather_today->temp, sizeof( weather_today->temp ),"%0.1f°C", doc["main"]["temp"].as() - 273.15 ); snprintf( weather_today->humidity, sizeof( weather_today->humidity ),"%f%%", doc["main"]["humidity"].as() ); @@ -102,17 +105,19 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w doc.clear(); free( json ); + return( retval ); } -void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) { +uint32_t weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ) { WiFiClient forecast_client; + uint32_t retval = -1; weather_forecast[ 0 ].valide = false; if ( !forecast_client.connect( OWM_HOST, OWM_PORT ) ) { Serial.println("Connection failed"); - return; + return( retval ); } forecast_client.printf( "GET /data/2.5/forecast?cnt=%d&lat=%s&lon=%s&appid=%s HTTP/1.1\r\n" @@ -125,10 +130,9 @@ void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t uint64_t startMillis = millis(); while ( forecast_client.available() == 0 ) { - yield(); if ( millis() - startMillis > 5000 ) { forecast_client.stop(); - return; + return( retval ); } } @@ -153,9 +157,8 @@ void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t if ( data_begin == false ) { Serial.printf("No json data\r\n"); free( json ); - return; + return( retval ); } - yield(); DynamicJsonDocument doc(20000); DeserializationError error = deserializeJson( doc, json ); @@ -164,10 +167,17 @@ void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t Serial.println(error.c_str()); doc.clear(); free( json ); - return; + return( retval ); + } + + retval = doc["cod"].as(); + + if ( retval != 200 ) { + doc.clear(); + free( json ); + return( retval ); } - yield(); weather_forecast[0].valide = true; for ( int i = 0 ; i < WEATHER_MAX_FORECAST ; i++ ) { snprintf( weather_forecast[ i ].temp, sizeof( weather_forecast[ i ].temp ),"%0.1f°C", doc["list"][i]["main"]["temp"].as() - 273.15 ); @@ -179,4 +189,5 @@ void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t doc.clear(); free( json ); + return( 200 ); } \ No newline at end of file diff --git a/src/gui/widget/weather/weather_fetch.h b/src/gui/widget/weather/weather_fetch.h index ef054fd..9755b61 100644 --- a/src/gui/widget/weather/weather_fetch.h +++ b/src/gui/widget/weather/weather_fetch.h @@ -25,7 +25,7 @@ #define OWM_HOST "api.openweathermap.org" #define OWM_PORT 80 - void weather_fetch_today( weather_config_t * weather_config, weather_forcast_t * weather_today ); - void weather_fetch_forecast( weather_config_t *weather_config, weather_forcast_t * weather_forecast ); + 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 ); #endif // _WEATHER_FETCH_H \ No newline at end of file diff --git a/src/gui/widget/weather/weather_forecast.cpp b/src/gui/widget/weather/weather_forecast.cpp index 31760ac..0d89c9c 100644 --- a/src/gui/widget/weather/weather_forecast.cpp +++ b/src/gui/widget/weather/weather_forecast.cpp @@ -126,7 +126,7 @@ void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hr xTaskCreate( weather_forecast_sync_Task, /* Function to implement the task */ "weather sync Task", /* Name of the task */ - 10000, /* Stack size in words */ + 5000, /* Stack size in words */ NULL, /* Task input parameter */ 1, /* Priority of the task */ &_weather_forecast_sync_Task ); /* Task handle. */ @@ -164,21 +164,20 @@ void weather_forecast_sync_request( void ) { } else { xEventGroupSetBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST ); + vTaskResume( _weather_forecast_sync_Task ); } - vTaskResume( _weather_forecast_sync_Task ); } void weather_forecast_sync_Task( void * pvParameters ) { weather_config_t *weather_config = weather_get_config(); + uint32_t retval = -1; while( true ) { vTaskDelay( 500 ); if ( xEventGroupGetBits( weather_forecast_event_handle ) & WEATHER_FORECAST_SYNC_REQUEST ) { if ( weather_config->autosync ) { - weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] ); - if ( !weather_forecast[ 0 ].valide ) - weather_fetch_forecast( weather_get_config() , &weather_forecast[ 0 ] ); - if ( weather_forecast[ 0 ].valide ) { + 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 ); @@ -196,7 +195,13 @@ void weather_forecast_sync_Task( void * pvParameters ) { strftime( buf, sizeof(buf), "updated: %d.%b %H:%M", &info ); lv_label_set_text( weather_forecast_update_label, buf ); } - } + motor_vibe( 1 ); + } + else { + char buf[64]; + snprintf( buf, sizeof(buf), "Error: %d", retval ); + lv_label_set_text( weather_forecast_update_label, buf ); + } } xEventGroupClearBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST ); } diff --git a/src/hardware/powermgm.cpp b/src/hardware/powermgm.cpp index 7e7dc31..91202e8 100644 --- a/src/hardware/powermgm.cpp +++ b/src/hardware/powermgm.cpp @@ -62,7 +62,7 @@ void powermgm_loop( TTGOClass *ttgo ) { // if we are in standby, wake up if ( powermgm_get_event( POWERMGM_STANDBY ) ) { powermgm_clear_event( POWERMGM_STANDBY ); - ttgo->power->setDCDC3Voltage( 3000 ); + ttgo->power->setDCDC3Voltage( 3300 ); ttgo->openBL(); ttgo->displayWakeup(); ttgo->bl->adjust( 0 ); @@ -81,12 +81,12 @@ void powermgm_loop( TTGOClass *ttgo ) { ttgo->displaySleep(); ttgo->closeBL(); 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 ) ) {} + while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN ) ) { yield(); } ttgo->stopLvglTick(); if ( bma_get_config( BMA_STEPCOUNTER ) ) ttgo->bma->enableStepCountInterrupt( false ); powermgm_set_event( POWERMGM_STANDBY ); - ttgo->power->setDCDC3Voltage( 2600 ); + ttgo->power->setDCDC3Voltage( 3000 ); setCpuFrequencyMhz( 10 ); gpio_wakeup_enable ((gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL); gpio_wakeup_enable ((gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL); diff --git a/src/hardware/powermgm.h b/src/hardware/powermgm.h index 657508a..4084f45 100644 --- a/src/hardware/powermgm.h +++ b/src/hardware/powermgm.h @@ -25,14 +25,16 @@ #include "TTGO.h" #define POWERMGM_STANDBY _BV(0) - #define POWERMGM_PMU_BUTTON _BV(1) - #define POWERMGM_PMU_BATTERY _BV(2) - #define POWERMGM_BMA_WAKEUP _BV(3) - #define POWERMGM_WIFI_ON_REQUEST _BV(5) - #define POWERMGM_WIFI_OFF_REQUEST _BV(6) - #define POWERMGM_WIFI_ACTIVE _BV(7) - #define POWERMGM_WIFI_SCAN _BV(8) - #define POWERMGM_WIFI_CONNECTED _BV(9) + #define POWERMGM_SILENCE_WAKEUP _BV(1) + #define POWERMGM_PMU_BUTTON _BV(2) + #define POWERMGM_PMU_BATTERY _BV(3) + #define POWERMGM_PMU_ALARM _BV(4) + #define POWERMGM_BMA_WAKEUP _BV(5) + #define POWERMGM_WIFI_ON_REQUEST _BV(6) + #define POWERMGM_WIFI_OFF_REQUEST _BV(7) + #define POWERMGM_WIFI_ACTIVE _BV(8) + #define POWERMGM_WIFI_SCAN _BV(9) + #define POWERMGM_WIFI_CONNECTED _BV(10) /* * @brief setp power managment, coordinate managment beween CPU, wifictl, pmu, bma, display, backlight and lvgl diff --git a/src/hardware/timesync.cpp b/src/hardware/timesync.cpp index 056ce01..5667c62 100644 --- a/src/hardware/timesync.cpp +++ b/src/hardware/timesync.cpp @@ -35,8 +35,13 @@ void timesync_setup( TTGOClass *ttgo ) { WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { if ( timesync_config.timesync ) { - xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST ); - vTaskResume( _timesync_Task ); + if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) { + return; + } + else { + xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST ); + vTaskResume( _timesync_Task ); + } } }, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP ); diff --git a/src/hardware/wifictl.cpp b/src/hardware/wifictl.cpp index 46a76f3..62e6512 100644 --- a/src/hardware/wifictl.cpp +++ b/src/hardware/wifictl.cpp @@ -118,14 +118,12 @@ void wifictl_setup( void ) { }, WiFiEvent_t::SYSTEM_EVENT_STA_STOP ); // start Wifo controll task - xTaskCreatePinnedToCore( - wifictl_Task, /* Function to implement the task */ - "wifictl Task", /* Name of the task */ - 2000, /* Stack size in words */ - NULL, /* Task input parameter */ - 1, /* Priority of the task */ - &_wifictl_Task, /* Task handle. */ - 1 ); /* Core where the task should run */ + xTaskCreate( wifictl_Task, /* Function to implement the task */ + "wifictl Task", /* Name of the task */ + 2000, /* Stack size in words */ + NULL, /* Task input parameter */ + 1, /* Priority of the task */ + &_wifictl_Task ); /* Task handle. */ } /* @@ -225,8 +223,13 @@ bool wifictl_insert_network( const char *ssid, const char *password ) { void wifictl_on( void ) { if ( wifi_init == false ) return; - vTaskResume( _wifictl_Task ); - powermgm_set_event( POWERMGM_WIFI_ON_REQUEST ); + if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) || powermgm_get_event( POWERMGM_WIFI_ON_REQUEST )) { + return; + } + else { + powermgm_set_event( POWERMGM_WIFI_ON_REQUEST ); + vTaskResume( _wifictl_Task ); + } } /* @@ -235,8 +238,13 @@ void wifictl_on( void ) { void wifictl_off( void ) { if ( wifi_init == false ) return; - vTaskResume( _wifictl_Task ); - powermgm_set_event( POWERMGM_WIFI_OFF_REQUEST ); + if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) || powermgm_get_event( POWERMGM_WIFI_ON_REQUEST )) { + return; + } + else { + powermgm_set_event( POWERMGM_WIFI_OFF_REQUEST ); + vTaskResume( _wifictl_Task ); + } } /* diff --git a/ttgo-t-watch2020_v1.ino.bin b/ttgo-t-watch2020_v1.ino.bin index 58ce060..d5cfc4b 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.txt b/ttgo-t-watch2020_v1.version.txt index e1fc041..bf50c4f 100644 --- a/ttgo-t-watch2020_v1.version.txt +++ b/ttgo-t-watch2020_v1.version.txt @@ -1 +1 @@ -2020072403 +2020072703