From 400fcbd6221cce0042e5f3b1025d43485495521c Mon Sep 17 00:00:00 2001 From: sharandac Date: Mon, 10 Aug 2020 12:35:39 +0200 Subject: [PATCH] some fixes --- platformio.ini | 6 ++-- src/config.h | 2 +- src/gui/gui.cpp | 7 +++- .../wlan_settings/wlan_settings.cpp | 32 ++++++++++++++++++- src/gui/screenshot.cpp | 4 +++ src/hardware/bma.cpp | 4 +-- src/hardware/display.cpp | 6 ++-- src/hardware/pmu.cpp | 8 ++--- src/hardware/powermgm.cpp | 10 +++++- src/hardware/wifictl.cpp | 32 +++++++++++++++---- src/hardware/wifictl.h | 3 ++ src/my-ttgo-watch.ino | 3 ++ src/webserver/webserver.cpp | 10 +++++- src/webserver/webserver.h | 3 +- 14 files changed, 107 insertions(+), 23 deletions(-) diff --git a/platformio.ini b/platformio.ini index 9ffc168..5e2d2d3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,9 +14,11 @@ board = ttgo-t-watch framework = arduino board_build.f_flash = 80000000L monitor_speed = 115200 -monitor_filters = default, esp32_exception_decoder +monitor_filters = + default + esp32_exception_decoder build_flags = -; -DCORE_DEBUG_LEVEL=3 + -DCORE_DEBUG_LEVEL=3 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue src_filter = diff --git a/src/config.h b/src/config.h index c32df47..8a62517 100644 --- a/src/config.h +++ b/src/config.h @@ -32,6 +32,6 @@ /* * firmeware version string */ - #define __FIRMWARE__ "2020081001" + #define __FIRMWARE__ "2020081004" #endif // _CONFIG_H diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e1a463b..725f6f3 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -88,7 +88,12 @@ void gui_setup(void) * */ void gui_loop( TTGOClass *ttgo ) { - // if we run in silence mode + // if we run in silence mode + if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP ) &&!powermgm_get_event( POWERMGM_STANDBY ) ) { + log_e("error while silence standby"); + while(1); + } + if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP ) ) { if ( lv_disp_get_inactive_time(NULL) < display_get_timeout() * 1000 ) { lv_task_handler(); 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 590f73d..f80c16c 100644 --- a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp +++ b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp @@ -292,8 +292,10 @@ static void exit_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event ) { } lv_obj_t *wifi_autoon_onoff; +lv_obj_t *wifi_webserver_onoff; static void wps_start_event_handler( lv_obj_t * obj, lv_event_t event ); static void wifi_autoon_onoff_event_handler( lv_obj_t * obj, lv_event_t event ); +static void wifi_webserver_onoff_event_handler( lv_obj_t * obj, lv_event_t event ); void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ) { // get an app tile and copy mainstyle @@ -334,9 +336,25 @@ void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ) { lv_label_set_text( wifi_autoon_label, "enable on wakeup"); lv_obj_align( wifi_autoon_label, wifi_autoon_onoff_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 ); + lv_obj_t *wifi_webserver_onoff_cont = lv_obj_create( wifi_setup_tile, NULL ); + lv_obj_set_size(wifi_webserver_onoff_cont, LV_HOR_RES_MAX , 40); + lv_obj_add_style( wifi_webserver_onoff_cont, LV_OBJ_PART_MAIN, &wifi_setup_style ); + lv_obj_align( wifi_webserver_onoff_cont, wifi_autoon_onoff_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 ); + + wifi_webserver_onoff = lv_switch_create( wifi_setup_tile, NULL ); + lv_obj_add_protect( wifi_webserver_onoff, LV_PROTECT_CLICK_FOCUS); + lv_obj_add_style( wifi_webserver_onoff, LV_SWITCH_PART_INDIC, mainbar_get_switch_style() ); + lv_switch_off( wifi_webserver_onoff, LV_ANIM_ON ); + lv_obj_align( wifi_webserver_onoff, wifi_webserver_onoff_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 ); + lv_obj_set_event_cb( wifi_webserver_onoff, wifi_webserver_onoff_event_handler ); + lv_obj_t *wifi_webserver_label = lv_label_create( wifi_webserver_onoff_cont, NULL); + lv_obj_add_style( wifi_webserver_label, LV_OBJ_PART_MAIN, &wifi_setup_style ); + lv_label_set_text( wifi_webserver_label, "enable webserver"); + lv_obj_align( wifi_webserver_label, wifi_webserver_onoff_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 ); + lv_obj_t *wps_btn = lv_btn_create( wifi_setup_tile, NULL); lv_obj_set_event_cb( wps_btn, wps_start_event_handler ); - lv_obj_align( wps_btn, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -40); + lv_obj_align( wps_btn, wifi_webserver_onoff_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); lv_obj_t *wps_btn_label = lv_label_create( wps_btn, NULL ); lv_label_set_text( wps_btn_label, "start WPS"); @@ -344,6 +362,11 @@ void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ) { lv_switch_on( wifi_autoon_onoff, LV_ANIM_OFF); else lv_switch_off( wifi_autoon_onoff, LV_ANIM_OFF); + + if ( wifictl_get_webserver() ) + lv_switch_on( wifi_webserver_onoff, LV_ANIM_OFF); + else + lv_switch_off( wifi_webserver_onoff, LV_ANIM_OFF); } static void wps_start_event_handler( lv_obj_t * obj, lv_event_t event ) { @@ -372,4 +395,11 @@ static void wifi_autoon_onoff_event_handler( lv_obj_t * obj, lv_event_t event ) case (LV_EVENT_VALUE_CHANGED): wifictl_set_autoon( lv_switch_get_state( obj ) ); break; } +} + +static void wifi_webserver_onoff_event_handler( lv_obj_t * obj, lv_event_t event ) { + switch (event) { + case (LV_EVENT_VALUE_CHANGED): wifictl_set_webserver( lv_switch_get_state( obj ) ); + break; + } } \ No newline at end of file diff --git a/src/gui/screenshot.cpp b/src/gui/screenshot.cpp index 6ded53c..07a2321 100644 --- a/src/gui/screenshot.cpp +++ b/src/gui/screenshot.cpp @@ -28,6 +28,10 @@ static void screenshot_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *are void screenshot_setup( void ) { png = (uint16_t*)ps_malloc( LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof( lv_color_t ) ); + if ( png == NULL ) { + log_e("error memory alloc"); + while(1); + } } void screenshot_take( void ) { diff --git a/src/hardware/bma.cpp b/src/hardware/bma.cpp index c9fb27d..5646b12 100644 --- a/src/hardware/bma.cpp +++ b/src/hardware/bma.cpp @@ -72,7 +72,7 @@ void bma_setup( TTGOClass *ttgo ) { void bma_standby( void ) { TTGOClass *ttgo = TTGOClass::getWatch(); - log_i("standby"); + log_i("go standby"); if ( bma_get_config( BMA_STEPCOUNTER ) ) ttgo->bma->enableStepCountInterrupt( false ); @@ -82,7 +82,7 @@ void bma_standby( void ) { void bma_wakeup( void ) { TTGOClass *ttgo = TTGOClass::getWatch(); - log_i("wakeup"); + log_i("go wakeup"); if ( bma_get_config( BMA_STEPCOUNTER ) ) ttgo->bma->enableStepCountInterrupt( true ); diff --git a/src/hardware/display.cpp b/src/hardware/display.cpp index 0340205..f32cd8b 100644 --- a/src/hardware/display.cpp +++ b/src/hardware/display.cpp @@ -69,7 +69,7 @@ void display_loop( TTGOClass *ttgo ) { void display_standby( void ) { TTGOClass *ttgo = TTGOClass::getWatch(); - log_i("standby"); + log_i("go standby"); ttgo->bl->adjust( 0 ); ttgo->displaySleep(); ttgo->closeBL(); @@ -82,7 +82,7 @@ void display_wakeup( void ) { // normal wake up from standby if ( powermgm_get_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP ) ) { - log_i("wakeup"); + log_i("go wakeup"); ttgo->openBL(); ttgo->displayWakeup(); ttgo->bl->adjust( 0 ); @@ -92,7 +92,7 @@ void display_wakeup( void ) { } // silence wakeup request from standby else if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP_REQUEST ) ) { - log_i("silence wakeup"); + log_i("go silence wakeup"); ttgo->openBL(); ttgo->displayWakeup(); ttgo->bl->adjust( 0 ); diff --git a/src/hardware/pmu.cpp b/src/hardware/pmu.cpp index 9cd9982..e861ce1 100644 --- a/src/hardware/pmu.cpp +++ b/src/hardware/pmu.cpp @@ -78,11 +78,11 @@ void pmu_standby( void ) { if ( pmu_get_experimental_power_save() ) { ttgo->power->setDCDC3Voltage( 2700 ); - log_i("enable 2.7V standby voltage"); + log_i("go standby, enable 2.7V standby voltage"); } else { ttgo->power->setDCDC3Voltage( 3000 ); - log_i("enable 3.0V standby voltage"); + log_i("go standby, enable 3.0V standby voltage"); } ttgo->power->setPowerOutPut(AXP202_LDO3, AXP202_OFF ); } @@ -92,11 +92,11 @@ void pmu_wakeup( void ) { if ( pmu_get_experimental_power_save() ) { ttgo->power->setDCDC3Voltage( 3000 ); - log_i("enable 3.0V voltage"); + log_i("go wakeup, enable 3.0V voltage"); } else { ttgo->power->setDCDC3Voltage( 3300 ); - log_i("enable 3.3V voltage"); + log_i("go wakeup, enable 3.3V voltage"); } ttgo->power->clearTimerStatus(); diff --git a/src/hardware/powermgm.cpp b/src/hardware/powermgm.cpp index 02cd59c..ea0cf1f 100644 --- a/src/hardware/powermgm.cpp +++ b/src/hardware/powermgm.cpp @@ -42,6 +42,7 @@ #include "gui/mainbar/mainbar.h" EventGroupHandle_t powermgm_status = NULL; +portMUX_TYPE powermgmMux = portMUX_INITIALIZER_UNLOCKED; /* * @@ -136,19 +137,26 @@ void powermgm_loop( TTGOClass *ttgo ) { * */ void powermgm_set_event( EventBits_t bits ) { + portENTER_CRITICAL_ISR(&powermgmMux); xEventGroupSetBits( powermgm_status, bits ); + portEXIT_CRITICAL_ISR(&powermgmMux); } /* * */ void powermgm_clear_event( EventBits_t bits ) { + portENTER_CRITICAL_ISR(&powermgmMux); xEventGroupClearBits( powermgm_status, bits ); + portEXIT_CRITICAL_ISR(&powermgmMux); } /* * */ EventBits_t powermgm_get_event( EventBits_t bits ) { - return( xEventGroupGetBits( powermgm_status ) & bits ); + portENTER_CRITICAL_ISR(&powermgmMux); + EventBits_t temp = xEventGroupGetBits( powermgm_status ) & bits; + portEXIT_CRITICAL_ISR(&powermgmMux); + return( temp ); } diff --git a/src/hardware/wifictl.cpp b/src/hardware/wifictl.cpp index d5dcd3d..5a148b2 100644 --- a/src/hardware/wifictl.cpp +++ b/src/hardware/wifictl.cpp @@ -124,7 +124,9 @@ void wifictl_setup( void ) { // label.concat('\n'); // label.concat(WiFi.localIPv6().toString()); statusbar_wifi_set_state( true, label.c_str() ); - asyncwebserver_setup(); + if ( wifictl_config.webserver ) { + asyncwebserver_start(); + } lv_obj_invalidate( lv_scr_act() ); }, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP ); @@ -144,10 +146,11 @@ void wifictl_setup( void ) { }, WiFiEvent_t::SYSTEM_EVENT_WIFI_READY ); WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) { - powermgm_clear_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST ); statusbar_hide_icon( STATUSBAR_WIFI ); statusbar_wifi_set_state( false, "" ); lv_obj_invalidate( lv_scr_act() ); + asyncwebserver_end(); + powermgm_clear_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST ); }, WiFiEvent_t::SYSTEM_EVENT_STA_STOP ); WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) { @@ -222,6 +225,15 @@ void wifictl_set_autoon( bool autoon ) { wifictl_config.autoon = autoon; wifictl_save_config(); } + +bool wifictl_get_webserver( void ) { + return( wifictl_config.webserver ); +} + +void wifictl_set_webserver( bool webserver ) { + wifictl_config.webserver = webserver; + wifictl_save_config(); +} /* * */ @@ -329,6 +341,7 @@ void wifictl_on( void ) { if ( wifi_init == false ) return; + log_i("request wifictl on"); if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) || powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) { return; } @@ -345,6 +358,7 @@ void wifictl_off( void ) { if ( wifi_init == false ) return; + log_i("request wifictl off"); if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) || powermgm_get_event( POWERMGM_WIFI_ON_REQUEST )) { return; } @@ -355,15 +369,19 @@ void wifictl_off( void ) { } void wifictl_standby( void ) { - log_i("standby"); + log_i("request wifictl 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 | POWERMGM_WIFI_WPS_REQUEST ) ) { yield(); } + while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST ) ) { + yield(); + } + log_i("request wifictl standby done"); } void wifictl_wakeup( void ) { if ( wifictl_config.autoon ) { - log_i("wakeup"); + log_i("request wifictl wakeup"); wifictl_on(); + log_i("request wifictl wakeup done"); } } @@ -409,8 +427,9 @@ void wifictl_Task( void * pvParameters ) { if ( powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) { statusbar_wifi_set_state( true, "activate" ); lv_obj_invalidate( lv_scr_act() ); - WiFi.mode( WIFI_STA ); powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_ON_REQUEST ); + WiFi.mode( WIFI_STA ); + log_i("request wifictl on done"); } else if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) ) { statusbar_wifi_set_state( false, "" ); @@ -418,6 +437,7 @@ void wifictl_Task( void * pvParameters ) { WiFi.mode( WIFI_OFF ); esp_wifi_stop(); powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_ON_REQUEST ); + log_i("request wifictl off done"); } vTaskSuspend( _wifictl_Task ); } diff --git a/src/hardware/wifictl.h b/src/hardware/wifictl.h index c0cd58a..d1fe7f4 100644 --- a/src/hardware/wifictl.h +++ b/src/hardware/wifictl.h @@ -40,6 +40,7 @@ typedef struct { bool autoon = true; + bool webserver = true; } wifictl_config_t; /* @@ -82,5 +83,7 @@ bool wifictl_get_autoon( void ); void wifictl_set_autoon( bool autoon ); void wifictl_start_wps( void ); + bool wifictl_get_webserver( void ); + void wifictl_set_webserver( bool webserver ); #endif // _WIFICTL_H \ No newline at end of file diff --git a/src/my-ttgo-watch.ino b/src/my-ttgo-watch.ino index 7e9e850..da83507 100644 --- a/src/my-ttgo-watch.ino +++ b/src/my-ttgo-watch.ino @@ -40,6 +40,8 @@ TTGOClass *ttgo = TTGOClass::getWatch(); void setup() { +// heap_caps_malloc_extmem_enable( 512 ); + motor_setup(); Serial.begin(115200); Serial.printf("starting t-watch V1, version: " __FIRMWARE__ "\r\n"); @@ -91,6 +93,7 @@ void setup() void loop() { + delay(10); gui_loop( ttgo ); powermgm_loop( ttgo ); } diff --git a/src/webserver/webserver.cpp b/src/webserver/webserver.cpp index a32f80b..5d53501 100644 --- a/src/webserver/webserver.cpp +++ b/src/webserver/webserver.cpp @@ -77,7 +77,7 @@ void handleUpdate( AsyncWebServerRequest *request, const String& filename, size_ /* * */ -void asyncwebserver_setup(void){ +void asyncwebserver_start(void){ asyncserver.on("/info", HTTP_GET, [](AsyncWebServerRequest *request) { String message("Firmwarestand: " __DATE__ " " __TIME__ "\nGCC-Version: " __VERSION__ "\n"); @@ -217,4 +217,12 @@ void asyncwebserver_setup(void){ SSDP.begin(); asyncserver.begin(); + + log_i("enable webserver and ssdp"); +} + +void asyncwebserver_end(void) { + SSDP.end(); + asyncserver.end(); + log_i("disable webserver and ssdp"); } \ No newline at end of file diff --git a/src/webserver/webserver.h b/src/webserver/webserver.h index 4e0c855..198dba0 100644 --- a/src/webserver/webserver.h +++ b/src/webserver/webserver.h @@ -33,6 +33,7 @@ /* * @brief setup builtin webserver, call after first wifi-connection. otherwise esp32 will crash */ - void asyncwebserver_setup(void); + void asyncwebserver_start(void); + void asyncwebserver_end(void); #endif // _ASYNCWEBSERVER_H \ No newline at end of file