feat(mcp): restore MCP system with native log.h
- MCP 3.3K LOC: McpSystem 1899 + McpHandler 1029 + McpScreensaver + 2 apps
- Uses native tactility/log.h TAG macros, no old Logger.h
- DisplaySettings McpScreen enum, WebServer coexistence (MCP enabled starts HTTP)
- DisplayIdle: startMcpScreensaver + isDeviceCharging + lock inversion fix 3629ffef
- LVGL 512K PSRAM cache retained from previous perf patch
- Audio kept upstream es8311-module per note we might not need custom
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <Tactility/service/webserver/AssetVersion.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/settings/WebServerSettings.h>
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/MountPoints.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
@@ -215,7 +217,8 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
serverEnabled = g_cachedSettings.webServerEnabled;
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
serverEnabled = g_cachedSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
||||
}
|
||||
// Subscribe to settings change events to refresh cache
|
||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||
@@ -259,13 +262,17 @@ void WebServerService::onStop(ServiceContext& service) {
|
||||
void WebServerService::setEnabled(bool enabled) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
|
||||
if (enabled) {
|
||||
if (!httpServer || !httpServer->isStarted()) {
|
||||
startServer();
|
||||
}
|
||||
} else {
|
||||
if (httpServer && httpServer->isStarted()) {
|
||||
// Stop only if both web server and MCP are disabled
|
||||
auto wsSettings = settings::webserver::loadOrGetDefault();
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
bool anyEnabled = wsSettings.webServerEnabled || mcpSettings.mcpEnabled;
|
||||
if (!anyEnabled && httpServer && httpServer->isStarted()) {
|
||||
stopServer();
|
||||
}
|
||||
}
|
||||
@@ -514,6 +521,11 @@ bool WebServerService::startServer() {
|
||||
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
||||
publish_event(this, WebServerEvent::WebServerStarted);
|
||||
|
||||
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
if (mcpSettings.mcpEnabled) {
|
||||
mcp::startVideoStreamServer();
|
||||
}
|
||||
|
||||
// Show statusbar icon
|
||||
if (statusbarIconId >= 0) {
|
||||
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
||||
@@ -533,6 +545,8 @@ void WebServerService::stopServer() {
|
||||
httpServer->stop();
|
||||
httpServer.reset();
|
||||
|
||||
mcp::stopVideoStreamServer();
|
||||
|
||||
// Stop AP mode WiFi if we started it
|
||||
if (apWifiInitialized || apNetif != nullptr) {
|
||||
stopApMode();
|
||||
@@ -1025,15 +1039,24 @@ esp_err_t WebServerService::handleApiGet(httpd_req_t* request) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// API POST dispatcher - all POST endpoints require authentication
|
||||
// API POST dispatcher - all POST endpoints require authentication except MCP
|
||||
esp_err_t WebServerService::handleApiPost(httpd_req_t* request) {
|
||||
const char* uri = request->uri;
|
||||
|
||||
// MCP endpoints are unauthenticated (local network)
|
||||
if (strncmp(uri, "/api/mcp", 8) == 0) {
|
||||
return handleApiMcp(request);
|
||||
}
|
||||
if (strncmp(uri, "/api/screen/raw", 15) == 0) {
|
||||
return handleApiScreenRaw(request);
|
||||
}
|
||||
|
||||
bool authPassed = false;
|
||||
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
||||
if (!authPassed) {
|
||||
return authResult;
|
||||
}
|
||||
|
||||
const char* uri = request->uri;
|
||||
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
||||
return handleApiAppsRun(request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user