Give activities names and log when entering and exiting them (#92)
## Summary * Give activities name and log when entering and exiting them * Clearer logs when attempting to debug, knowing where users are coming from/going to helps
This commit is contained in:
@@ -11,7 +11,8 @@ void CrossPointWebServerActivity::taskTrampoline(void* param) {
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::onEnter() {
|
||||
Serial.printf("[%lu] [WEBACT] ========== CrossPointWebServerActivity onEnter ==========\n", millis());
|
||||
ActivityWithSubactivity::onEnter();
|
||||
|
||||
Serial.printf("[%lu] [WEBACT] [MEM] Free heap at onEnter: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
@@ -36,13 +37,13 @@ void CrossPointWebServerActivity::onEnter() {
|
||||
|
||||
// Launch WiFi selection subactivity
|
||||
Serial.printf("[%lu] [WEBACT] Launching WifiSelectionActivity...\n", millis());
|
||||
wifiSelection.reset(new WifiSelectionActivity(renderer, inputManager,
|
||||
[this](bool connected) { onWifiSelectionComplete(connected); }));
|
||||
wifiSelection->onEnter();
|
||||
enterNewActivity(new WifiSelectionActivity(renderer, inputManager,
|
||||
[this](const bool connected) { onWifiSelectionComplete(connected); }));
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::onExit() {
|
||||
Serial.printf("[%lu] [WEBACT] ========== CrossPointWebServerActivity onExit START ==========\n", millis());
|
||||
ActivityWithSubactivity::onExit();
|
||||
|
||||
Serial.printf("[%lu] [WEBACT] [MEM] Free heap at onExit start: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
state = WebServerActivityState::SHUTTING_DOWN;
|
||||
@@ -50,14 +51,6 @@ void CrossPointWebServerActivity::onExit() {
|
||||
// Stop the web server first (before disconnecting WiFi)
|
||||
stopWebServer();
|
||||
|
||||
// Exit WiFi selection subactivity if still active
|
||||
if (wifiSelection) {
|
||||
Serial.printf("[%lu] [WEBACT] Exiting WifiSelectionActivity...\n", millis());
|
||||
wifiSelection->onExit();
|
||||
wifiSelection.reset();
|
||||
Serial.printf("[%lu] [WEBACT] WifiSelectionActivity exited\n", millis());
|
||||
}
|
||||
|
||||
// CRITICAL: Wait for LWIP stack to flush any pending packets
|
||||
Serial.printf("[%lu] [WEBACT] Waiting 500ms for network stack to flush pending packets...\n", millis());
|
||||
delay(500);
|
||||
@@ -92,20 +85,17 @@ void CrossPointWebServerActivity::onExit() {
|
||||
Serial.printf("[%lu] [WEBACT] Mutex deleted\n", millis());
|
||||
|
||||
Serial.printf("[%lu] [WEBACT] [MEM] Free heap at onExit end: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
Serial.printf("[%lu] [WEBACT] ========== CrossPointWebServerActivity onExit COMPLETE ==========\n", millis());
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::onWifiSelectionComplete(bool connected) {
|
||||
void CrossPointWebServerActivity::onWifiSelectionComplete(const bool connected) {
|
||||
Serial.printf("[%lu] [WEBACT] WifiSelectionActivity completed, connected=%d\n", millis(), connected);
|
||||
|
||||
if (connected) {
|
||||
// Get connection info before exiting subactivity
|
||||
connectedIP = wifiSelection->getConnectedIP();
|
||||
connectedIP = static_cast<WifiSelectionActivity*>(subActivity.get())->getConnectedIP();
|
||||
connectedSSID = WiFi.SSID().c_str();
|
||||
|
||||
// Exit the wifi selection subactivity
|
||||
wifiSelection->onExit();
|
||||
wifiSelection.reset();
|
||||
exitActivity();
|
||||
|
||||
// Start the web server
|
||||
startWebServer();
|
||||
@@ -150,47 +140,40 @@ void CrossPointWebServerActivity::stopWebServer() {
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::loop() {
|
||||
if (subActivity) {
|
||||
// Forward loop to subactivity
|
||||
subActivity->loop();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle different states
|
||||
switch (state) {
|
||||
case WebServerActivityState::WIFI_SELECTION:
|
||||
// Forward loop to WiFi selection subactivity
|
||||
if (wifiSelection) {
|
||||
wifiSelection->loop();
|
||||
}
|
||||
break;
|
||||
if (state == WebServerActivityState::SERVER_RUNNING) {
|
||||
// Handle web server requests - call handleClient multiple times per loop
|
||||
// to improve responsiveness and upload throughput
|
||||
if (webServer && webServer->isRunning()) {
|
||||
const unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
|
||||
|
||||
case WebServerActivityState::SERVER_RUNNING:
|
||||
// Handle web server requests - call handleClient multiple times per loop
|
||||
// to improve responsiveness and upload throughput
|
||||
if (webServer && webServer->isRunning()) {
|
||||
unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
|
||||
|
||||
// Log if there's a significant gap between handleClient calls (>100ms)
|
||||
if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) {
|
||||
Serial.printf("[%lu] [WEBACT] WARNING: %lu ms gap since last handleClient\n", millis(),
|
||||
timeSinceLastHandleClient);
|
||||
}
|
||||
|
||||
// Call handleClient multiple times to process pending requests faster
|
||||
// This is critical for upload performance - HTTP file uploads send data
|
||||
// in chunks and each handleClient() call processes incoming data
|
||||
constexpr int HANDLE_CLIENT_ITERATIONS = 10;
|
||||
for (int i = 0; i < HANDLE_CLIENT_ITERATIONS && webServer->isRunning(); i++) {
|
||||
webServer->handleClient();
|
||||
}
|
||||
lastHandleClientTime = millis();
|
||||
// Log if there's a significant gap between handleClient calls (>100ms)
|
||||
if (lastHandleClientTime > 0 && timeSinceLastHandleClient > 100) {
|
||||
Serial.printf("[%lu] [WEBACT] WARNING: %lu ms gap since last handleClient\n", millis(),
|
||||
timeSinceLastHandleClient);
|
||||
}
|
||||
|
||||
// Handle exit on Back button
|
||||
if (inputManager.wasPressed(InputManager::BTN_BACK)) {
|
||||
onGoBack();
|
||||
return;
|
||||
// Call handleClient multiple times to process pending requests faster
|
||||
// This is critical for upload performance - HTTP file uploads send data
|
||||
// in chunks and each handleClient() call processes incoming data
|
||||
constexpr int HANDLE_CLIENT_ITERATIONS = 10;
|
||||
for (int i = 0; i < HANDLE_CLIENT_ITERATIONS && webServer->isRunning(); i++) {
|
||||
webServer->handleClient();
|
||||
}
|
||||
break;
|
||||
lastHandleClientTime = millis();
|
||||
}
|
||||
|
||||
case WebServerActivityState::SHUTTING_DOWN:
|
||||
// Do nothing - waiting for cleanup
|
||||
break;
|
||||
// Handle exit on Back button
|
||||
if (inputManager.wasPressed(InputManager::BTN_BACK)) {
|
||||
onGoBack();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "WifiSelectionActivity.h"
|
||||
#include "activities/ActivityWithSubactivity.h"
|
||||
#include "server/CrossPointWebServer.h"
|
||||
|
||||
// Web server activity states
|
||||
@@ -26,16 +27,13 @@ enum class WebServerActivityState {
|
||||
* - Handles client requests in its loop() function
|
||||
* - Cleans up the server and shuts down WiFi on exit
|
||||
*/
|
||||
class CrossPointWebServerActivity final : public Activity {
|
||||
class CrossPointWebServerActivity final : public ActivityWithSubactivity {
|
||||
TaskHandle_t displayTaskHandle = nullptr;
|
||||
SemaphoreHandle_t renderingMutex = nullptr;
|
||||
bool updateRequired = false;
|
||||
WebServerActivityState state = WebServerActivityState::WIFI_SELECTION;
|
||||
const std::function<void()> onGoBack;
|
||||
|
||||
// WiFi selection subactivity
|
||||
std::unique_ptr<WifiSelectionActivity> wifiSelection;
|
||||
|
||||
// Web server - owned by this activity
|
||||
std::unique_ptr<CrossPointWebServer> webServer;
|
||||
|
||||
@@ -58,7 +56,7 @@ class CrossPointWebServerActivity final : public Activity {
|
||||
public:
|
||||
explicit CrossPointWebServerActivity(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::function<void()>& onGoBack)
|
||||
: Activity(renderer, inputManager), onGoBack(onGoBack) {}
|
||||
: ActivityWithSubactivity("CrossPointWebServer", renderer, inputManager), onGoBack(onGoBack) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
|
||||
@@ -14,6 +14,8 @@ void WifiSelectionActivity::taskTrampoline(void* param) {
|
||||
}
|
||||
|
||||
void WifiSelectionActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
|
||||
renderingMutex = xSemaphoreCreateMutex();
|
||||
|
||||
// Load saved WiFi credentials
|
||||
@@ -47,7 +49,8 @@ void WifiSelectionActivity::onEnter() {
|
||||
}
|
||||
|
||||
void WifiSelectionActivity::onExit() {
|
||||
Serial.printf("[%lu] [WIFI] ========== WifiSelectionActivity onExit START ==========\n", millis());
|
||||
Activity::onExit();
|
||||
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit start: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
|
||||
// Stop any ongoing WiFi scan
|
||||
@@ -78,7 +81,6 @@ void WifiSelectionActivity::onExit() {
|
||||
Serial.printf("[%lu] [WIFI] Mutex deleted\n", millis());
|
||||
|
||||
Serial.printf("[%lu] [WIFI] [MEM] Free heap at onExit end: %d bytes\n", millis(), ESP.getFreeHeap());
|
||||
Serial.printf("[%lu] [WIFI] ========== WifiSelectionActivity onExit COMPLETE ==========\n", millis());
|
||||
}
|
||||
|
||||
void WifiSelectionActivity::startWifiScan() {
|
||||
|
||||
@@ -98,7 +98,7 @@ class WifiSelectionActivity final : public Activity {
|
||||
public:
|
||||
explicit WifiSelectionActivity(GfxRenderer& renderer, InputManager& inputManager,
|
||||
const std::function<void(bool connected)>& onComplete)
|
||||
: Activity(renderer, inputManager), onComplete(onComplete) {}
|
||||
: Activity("WifiSelection", renderer, inputManager), onComplete(onComplete) {}
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
|
||||
Reference in New Issue
Block a user