mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 14:47:37 +03:00
Move to server activity
This commit is contained in:
parent
5d706685c5
commit
34dbbc5503
@ -9,6 +9,7 @@
|
||||
// Initialize the static instance
|
||||
WifiCredentialStore WifiCredentialStore::instance;
|
||||
|
||||
namespace {
|
||||
// File format version
|
||||
constexpr uint8_t WIFI_FILE_VERSION = 1;
|
||||
|
||||
@ -19,6 +20,7 @@ constexpr char WIFI_FILE[] = "/sd/.crosspoint/wifi.bin";
|
||||
// This is NOT cryptographic security, just prevents casual file reading
|
||||
constexpr uint8_t OBFUSCATION_KEY[] = {0x43, 0x72, 0x6F, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74};
|
||||
constexpr size_t KEY_LENGTH = sizeof(OBFUSCATION_KEY);
|
||||
} // namespace
|
||||
|
||||
void WifiCredentialStore::obfuscate(std::string& data) const {
|
||||
Serial.printf("[%lu] [WCS] Obfuscating/deobfuscating %zu bytes\n", millis(), data.size());
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "CrossPointWebServer.h"
|
||||
#include "config.h"
|
||||
|
||||
void CrossPointWebServerActivity::taskTrampoline(void* param) {
|
||||
@ -119,9 +118,11 @@ void CrossPointWebServerActivity::onWifiSelectionComplete(bool connected) {
|
||||
void CrossPointWebServerActivity::startWebServer() {
|
||||
Serial.printf("[%lu] [WEBACT] Starting web server...\n", millis());
|
||||
|
||||
crossPointWebServer.begin();
|
||||
// Create the web server instance
|
||||
webServer.reset(new CrossPointWebServer());
|
||||
webServer->begin();
|
||||
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
if (webServer->isRunning()) {
|
||||
state = WebServerActivityState::SERVER_RUNNING;
|
||||
Serial.printf("[%lu] [WEBACT] Web server started successfully\n", millis());
|
||||
|
||||
@ -133,17 +134,19 @@ void CrossPointWebServerActivity::startWebServer() {
|
||||
Serial.printf("[%lu] [WEBACT] Rendered File Transfer screen\n", millis());
|
||||
} else {
|
||||
Serial.printf("[%lu] [WEBACT] ERROR: Failed to start web server!\n", millis());
|
||||
webServer.reset();
|
||||
// Go back on error
|
||||
onGoBack();
|
||||
}
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::stopWebServer() {
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
if (webServer && webServer->isRunning()) {
|
||||
Serial.printf("[%lu] [WEBACT] Stopping web server...\n", millis());
|
||||
crossPointWebServer.stop();
|
||||
webServer->stop();
|
||||
Serial.printf("[%lu] [WEBACT] Web server stopped\n", millis());
|
||||
}
|
||||
webServer.reset();
|
||||
}
|
||||
|
||||
void CrossPointWebServerActivity::loop() {
|
||||
@ -158,7 +161,7 @@ void CrossPointWebServerActivity::loop() {
|
||||
|
||||
case WebServerActivityState::SERVER_RUNNING:
|
||||
// Handle web server requests
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
if (webServer && webServer->isRunning()) {
|
||||
unsigned long timeSinceLastHandleClient = millis() - lastHandleClientTime;
|
||||
|
||||
// Log if there's a significant gap between handleClient calls (>100ms)
|
||||
@ -167,7 +170,7 @@ void CrossPointWebServerActivity::loop() {
|
||||
timeSinceLastHandleClient);
|
||||
}
|
||||
|
||||
crossPointWebServer.handleClient();
|
||||
webServer->handleClient();
|
||||
lastHandleClientTime = millis();
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "WifiSelectionActivity.h"
|
||||
#include "server/CrossPointWebServer.h"
|
||||
|
||||
// Web server activity states
|
||||
enum class WebServerActivityState {
|
||||
@ -35,6 +36,9 @@ class CrossPointWebServerActivity final : public Activity {
|
||||
// WiFi selection subactivity
|
||||
std::unique_ptr<WifiSelectionActivity> wifiSelection;
|
||||
|
||||
// Web server - owned by this activity
|
||||
std::unique_ptr<CrossPointWebServer> webServer;
|
||||
|
||||
// Server status
|
||||
std::string connectedIP;
|
||||
std::string connectedSSID;
|
||||
@ -58,4 +62,7 @@ class CrossPointWebServerActivity final : public Activity {
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void loop() override;
|
||||
|
||||
// Check if web server is running (used by main loop for timing optimization)
|
||||
bool isWebServerRunning() const { return webServer && webServer->isRunning(); }
|
||||
};
|
||||
|
||||
@ -10,9 +10,6 @@
|
||||
#include "html/FilesPageHeaderHtml.generated.h"
|
||||
#include "html/HomePageHtml.generated.h"
|
||||
|
||||
// Global instance
|
||||
CrossPointWebServer crossPointWebServer;
|
||||
|
||||
// Folders/files to hide from the web interface file browser
|
||||
// Note: Items starting with "." are automatically hidden
|
||||
static const char* HIDDEN_ITEMS[] = {"System Volume Information", "XTCache"};
|
||||
@ -54,6 +54,3 @@ class CrossPointWebServer {
|
||||
void handleCreateFolder();
|
||||
void handleDelete();
|
||||
};
|
||||
|
||||
// Global instance
|
||||
extern CrossPointWebServer crossPointWebServer;
|
||||
@ -17,7 +17,6 @@
|
||||
#include "Battery.h"
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "CrossPointWebServer.h"
|
||||
#include "activities/boot_sleep/BootActivity.h"
|
||||
#include "activities/boot_sleep/SleepActivity.h"
|
||||
#include "activities/home/HomeActivity.h"
|
||||
@ -45,6 +44,7 @@ EInkDisplay einkDisplay(EPD_SCLK, EPD_MOSI, EPD_CS, EPD_DC, EPD_RST, EPD_BUSY);
|
||||
InputManager inputManager;
|
||||
GfxRenderer renderer(einkDisplay);
|
||||
Activity* currentActivity;
|
||||
CrossPointWebServerActivity* webServerActivity = nullptr; // Track web server activity for loop timing
|
||||
|
||||
// Fonts
|
||||
EpdFont bookerlyFont(&bookerly_2b);
|
||||
@ -72,6 +72,8 @@ void exitActivity() {
|
||||
if (currentActivity) {
|
||||
currentActivity->onExit();
|
||||
delete currentActivity;
|
||||
currentActivity = nullptr;
|
||||
webServerActivity = nullptr; // Clear web server activity pointer when exiting
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +147,8 @@ void onGoToReaderHome() { onGoToReader(std::string()); }
|
||||
|
||||
void onGoToFileTransfer() {
|
||||
exitActivity();
|
||||
enterNewActivity(new CrossPointWebServerActivity(renderer, inputManager, onGoHome));
|
||||
webServerActivity = new CrossPointWebServerActivity(renderer, inputManager, onGoHome);
|
||||
enterNewActivity(webServerActivity);
|
||||
}
|
||||
|
||||
void onGoToSettings() {
|
||||
@ -207,7 +210,7 @@ void loop() {
|
||||
|
||||
// Reduce delay when webserver is running to allow faster handleClient() calls
|
||||
// This is critical for upload performance and preventing TCP timeouts
|
||||
if (crossPointWebServer.isRunning()) {
|
||||
if (webServerActivity && webServerActivity->isWebServerRunning()) {
|
||||
delay(1); // Minimal delay to prevent tight loop
|
||||
} else {
|
||||
delay(10); // Normal delay when webserver not active
|
||||
|
||||
Loading…
Reference in New Issue
Block a user