feat: restore MCP settings and board customizations
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/hal/SdCard.h>
|
||||
#include <Tactility/lvgl/KeyboardDeviceListener.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/Statusbar.h>
|
||||
#include <Tactility/lvgl/TrackballInit.h>
|
||||
#include <Tactility/lvgl/UsbHidInput.h>
|
||||
@@ -189,6 +190,7 @@ namespace app {
|
||||
#ifdef ESP_PLATFORM
|
||||
namespace apwebserver { extern const ::AppManifest manifest; }
|
||||
namespace crashdiagnostics { extern const ::AppManifest manifest; }
|
||||
namespace mcpsettings { extern const ::AppManifest manifest; }
|
||||
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
||||
namespace keyboardsettings { extern const ::AppManifest manifest; } // T-Deck only for now
|
||||
#endif
|
||||
@@ -252,6 +254,7 @@ static void registerInternalApps() {
|
||||
#ifdef ESP_PLATFORM
|
||||
app_manager_add(&app::apwebserver::manifest);
|
||||
app_manager_add(&app::crashdiagnostics::manifest);
|
||||
app_manager_add(&app::mcpsettings::manifest);
|
||||
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
||||
app_manager_add(&app::keyboardsettings::manifest);
|
||||
#endif
|
||||
@@ -433,6 +436,7 @@ static void onLvglStarted() {
|
||||
if (auto* display = lv_display_get_default(); display != nullptr) {
|
||||
auto displaySettings = settings::display::loadOrGetDefault();
|
||||
lv_display_set_rotation(display, settings::display::toLvglDisplayRotation(displaySettings.orientation));
|
||||
lvgl::applyFontSize(displaySettings.fontSize);
|
||||
}
|
||||
lvgl_unlock();
|
||||
|
||||
|
||||
@@ -107,6 +107,9 @@ void showNoInternet(Context* ctx) {
|
||||
}
|
||||
|
||||
void showApps(Context* ctx) {
|
||||
if (ctx->contentWrapper == nullptr) {
|
||||
return;
|
||||
}
|
||||
// Refresh rebuilds the list from scratch (cached copy, then again once the network fetch
|
||||
// lands), which would otherwise reset the user's scroll position each time.
|
||||
int32_t scrollY;
|
||||
@@ -266,7 +269,9 @@ void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
|
||||
void destroyWidgets(void* userData) {
|
||||
auto* ctx = static_cast<Context*>(userData);
|
||||
ctx->scrollY = lv_obj_get_scroll_y(ctx->contentWrapper);
|
||||
if (ctx->contentWrapper != nullptr) {
|
||||
ctx->scrollY = lv_obj_get_scroll_y(ctx->contentWrapper);
|
||||
}
|
||||
ctx->contentWrapper = nullptr;
|
||||
ctx->refreshButton = nullptr;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ extern const ::AppManifest manifest = {
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN,
|
||||
.stack = { .depth = 2400, .desired_memory_capability = 0 },
|
||||
.stack = { .depth = 3072, .desired_memory_capability = 0 },
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||
#endif
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#include <app/event.h>
|
||||
@@ -90,6 +91,21 @@ void onOrientationSet(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
void onFontSizeChanged(lv_event_t* event) {
|
||||
auto* ctx = static_cast<Context*>(lv_event_get_user_data(event));
|
||||
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
|
||||
if (selected_index >= static_cast<uint32_t>(settings::display::FontSize::Count)) {
|
||||
return;
|
||||
}
|
||||
auto selected_size = static_cast<settings::display::FontSize>(selected_index);
|
||||
if (selected_size != ctx->displaySettings.fontSize) {
|
||||
ctx->displaySettings.fontSize = selected_size;
|
||||
ctx->displaySettingsUpdated = true;
|
||||
lvgl::applyFontSize(selected_size);
|
||||
}
|
||||
}
|
||||
|
||||
void onTimeoutSwitch(lv_event_t* event) {
|
||||
auto* ctx = static_cast<Context*>(lv_event_get_user_data(event));
|
||||
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
@@ -208,6 +224,23 @@ void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
// Set the dropdown to match current orientation enum
|
||||
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(ctx->displaySettings.orientation));
|
||||
|
||||
// Font size
|
||||
|
||||
auto* font_size_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(font_size_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(font_size_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* font_size_label = lv_label_create(font_size_wrapper);
|
||||
lv_label_set_text(font_size_label, "Font size");
|
||||
lv_obj_align(font_size_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
auto* font_size_dropdown = lv_dropdown_create(font_size_wrapper);
|
||||
lv_dropdown_set_options(font_size_dropdown, "Small\nDefault\nLarge");
|
||||
lv_obj_align(font_size_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(font_size_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
lv_dropdown_set_selected(font_size_dropdown, static_cast<uint16_t>(ctx->displaySettings.fontSize));
|
||||
|
||||
// Screen timeout
|
||||
// Note: DisplayIdleService doesn't act on these settings for kernel-driver displays yet
|
||||
// (it only looks up the deprecated tt::hal::display::DisplayDevice), so these currently
|
||||
@@ -274,7 +307,7 @@ void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
|
||||
ctx->screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||
lv_dropdown_set_options(ctx->screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
||||
lv_dropdown_set_options(ctx->screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan\nMCP Screen");
|
||||
lv_obj_align(ctx->screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(ctx->screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
lv_dropdown_set_selected(ctx->screensaverDropdown, static_cast<uint16_t>(ctx->displaySettings.screensaverType));
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/settings/WebServerSettings.h>
|
||||
#include <Tactility/service/webserver/WebServerService.h>
|
||||
#include <app/event.h>
|
||||
#include <app/manifest.h>
|
||||
#include <app/scheduler.h>
|
||||
#include <lvgl_window_manager/window_manager.h>
|
||||
#include <lvgl/widgets/toolbar.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/log.h>
|
||||
#include <esp_netif.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace tt::app::mcpsettings {
|
||||
constexpr auto* TAG = "McpSettingsApp";
|
||||
extern const ::AppManifest manifest;
|
||||
namespace {
|
||||
struct Context {
|
||||
uint32_t appInstanceId;
|
||||
settings::mcp::McpSettings mcpSettings;
|
||||
settings::webserver::WebServerSettings wsSettings;
|
||||
lv_obj_t* switchMcpEnabled = nullptr;
|
||||
lv_obj_t* labelUrlValue = nullptr;
|
||||
};
|
||||
|
||||
void updateUrlDisplay(Context* ctx) {
|
||||
if (ctx->labelUrlValue == nullptr) return;
|
||||
if (!ctx->mcpSettings.mcpEnabled) { lv_label_set_text(ctx->labelUrlValue, "Disabled"); return; }
|
||||
std::string url = "http://";
|
||||
bool ipAdded = false;
|
||||
for (const char* key : {"WIFI_STA_DEF", "WIFI_AP_DEF"}) {
|
||||
auto* netif = esp_netif_get_handle_from_ifkey(key);
|
||||
if (netif != nullptr) {
|
||||
esp_netif_ip_info_t info;
|
||||
if (esp_netif_get_ip_info(netif, &info) == ESP_OK && info.ip.addr != 0) {
|
||||
char ip[16]; snprintf(ip, sizeof(ip), IPSTR, IP2STR(&info.ip));
|
||||
url += ip; ipAdded = true; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ipAdded) url += ctx->wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint ? "192.168.4.1" : "Connecting...";
|
||||
if (url.starts_with("http://") && ctx->wsSettings.webServerPort != 80) url += ":" + std::to_string(ctx->wsSettings.webServerPort);
|
||||
url += "/api/mcp";
|
||||
lv_label_set_text(ctx->labelUrlValue, url.c_str());
|
||||
}
|
||||
|
||||
void onBackPressed(lv_event_t* event) {
|
||||
auto* ctx = static_cast<Context*>(lv_event_get_user_data(event));
|
||||
app_event_emit_close(ctx->appInstanceId);
|
||||
}
|
||||
|
||||
void onMcpEnabledSwitch(lv_event_t* event) {
|
||||
auto* ctx = static_cast<Context*>(lv_event_get_user_data(event));
|
||||
const bool enabled = lv_obj_has_state(ctx->switchMcpEnabled, LV_STATE_CHECKED);
|
||||
getMainDispatcher().dispatch([ctx, enabled] {
|
||||
ctx->mcpSettings.mcpEnabled = enabled;
|
||||
lvgl_lock(); updateUrlDisplay(ctx); lvgl_unlock();
|
||||
if (!settings::mcp::save(ctx->mcpSettings)) LOG_W(TAG, "Failed to persist MCP settings");
|
||||
service::webserver::getPubsub()->publish(service::webserver::WebServerEvent::WebServerSettingsChanged);
|
||||
service::webserver::setWebServerEnabled(enabled);
|
||||
});
|
||||
}
|
||||
|
||||
void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
auto* ctx = static_cast<Context*>(userData);
|
||||
ctx->wsSettings = settings::webserver::loadOrGetDefault();
|
||||
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||
auto* toolbar = lvgl_toolbar_create(parent, "MCP Settings");
|
||||
lvgl_toolbar_set_nav_action(toolbar, LV_SYMBOL_CLOSE, onBackPressed, ctx);
|
||||
ctx->switchMcpEnabled = lvgl_toolbar_add_switch_action(toolbar);
|
||||
if (ctx->mcpSettings.mcpEnabled) lv_obj_add_state(ctx->switchMcpEnabled, LV_STATE_CHECKED);
|
||||
lv_obj_add_event_cb(ctx->switchMcpEnabled, onMcpEnabledSwitch, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
auto* main = lv_obj_create(parent); lv_obj_set_flex_flow(main, LV_FLEX_FLOW_COLUMN); lv_obj_set_width(main, LV_PCT(100)); lv_obj_set_flex_grow(main, 1);
|
||||
auto* wrapper = lv_obj_create(main); lv_obj_set_size(wrapper, LV_PCT(100), LV_SIZE_CONTENT); lv_obj_set_style_pad_all(wrapper, 10, LV_STATE_DEFAULT); lv_obj_set_style_border_width(wrapper, 1, LV_STATE_DEFAULT); lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN); lv_obj_set_style_flex_cross_place(wrapper, LV_FLEX_ALIGN_START, 0);
|
||||
auto* title = lv_label_create(wrapper); lv_label_set_text(title, "MCP Endpoint URL:");
|
||||
ctx->labelUrlValue = lv_label_create(wrapper); updateUrlDisplay(ctx);
|
||||
auto* info = lv_label_create(main); lv_label_set_long_mode(info, LV_LABEL_LONG_WRAP); lv_obj_set_width(info, LV_PCT(95));
|
||||
lv_label_set_text(info, "MCP (Model Context Protocol) Screen service allows LLMs to interact with the device screen, audio, and tools directly.\n\nEndpoints:\n- POST /api/mcp (JSON-RPC tools)\n- POST /api/screen/raw (big-endian RGB565 writes)\n\nTo show the LLM canvas, select 'MCP Screen' in Settings -> Display -> Screensaver. The canvas also pops up automatically when an LLM sends a draw command.");
|
||||
}
|
||||
|
||||
int32_t appMain(int, char**) {
|
||||
Context ctx{}; ctx.appInstanceId = app_scheduler_current_app_id(); ctx.mcpSettings = settings::mcp::loadOrGetDefault();
|
||||
TaskEventGroup group{}; task_event_group_construct(&group); AppEventSubscription sub{}; check(app_event_subscribe(&sub, &group) == ERROR_NONE);
|
||||
auto window = window_manager_create(ctx.appInstanceId, createWidgets, &ctx); bool close = false;
|
||||
while (!close) { task_event_group_wait_any(&group, nullptr, portMAX_DELAY); AppEvent event{}; while (app_event_poll(&sub, &event) == ERROR_NONE) if (event.type == APP_EVENT_CLOSE) { close = true; break; } }
|
||||
window_manager_remove(window); check(app_event_unsubscribe(&sub) == ERROR_NONE); task_event_group_destruct(&group); return 0;
|
||||
}
|
||||
}
|
||||
extern const ::AppManifest manifest = { .id = "McpSettings", .name = "MCP Screen", .category = APP_CATEGORY_SETTINGS, .location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }, .flags = 0, .stack = { .depth = 8192, .desired_memory_capability = 0 } };
|
||||
}
|
||||
#endif
|
||||
@@ -118,7 +118,7 @@ extern const ::AppManifest manifest = {
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { .type = APP_LOCATION_MEMORY, .location = reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN,
|
||||
.stack = { .depth = 2400, .desired_memory_capability = 0 },
|
||||
.stack = { .depth = 3072, .desired_memory_capability = 0 },
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#include <lvgl/fonts.h>
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
void applyFontSize(settings::display::FontSize fontSize) {
|
||||
LvglFontScale scale;
|
||||
switch (fontSize) {
|
||||
using enum settings::display::FontSize;
|
||||
case Small:
|
||||
scale = FONT_SCALE_SMALL;
|
||||
break;
|
||||
case Large:
|
||||
scale = FONT_SCALE_LARGE;
|
||||
break;
|
||||
case Default:
|
||||
default:
|
||||
scale = FONT_SCALE_DEFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
lvgl_set_text_font_scale(scale);
|
||||
const lv_font_t* font = lvgl_get_text_font(FONT_SIZE_DEFAULT);
|
||||
|
||||
for (lv_display_t* display = lv_display_get_next(nullptr);
|
||||
display != nullptr;
|
||||
display = lv_display_get_next(display)) {
|
||||
#if LV_USE_THEME_DEFAULT
|
||||
if (lv_display_get_theme(display) == lv_theme_default_get()) {
|
||||
lv_obj_t* screen = lv_display_get_screen_active(display);
|
||||
lv_theme_default_init(
|
||||
display,
|
||||
lv_theme_get_color_primary(screen),
|
||||
lv_theme_get_color_secondary(screen),
|
||||
LV_THEME_DEFAULT_DARK,
|
||||
font
|
||||
);
|
||||
}
|
||||
#endif
|
||||
// The display layers are independent inheritance roots. Updating all of them makes
|
||||
// the new size visible immediately in regular screens, overlays, and the status bar.
|
||||
lv_obj_set_style_text_font(lv_display_get_screen_active(display), font, LV_PART_MAIN);
|
||||
lv_obj_set_style_text_font(lv_display_get_layer_top(display), font, LV_PART_MAIN);
|
||||
lv_obj_set_style_text_font(lv_display_get_layer_sys(display), font, LV_PART_MAIN);
|
||||
lv_obj_set_style_text_font(lv_display_get_layer_bottom(display), font, LV_PART_MAIN);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace tt::lvgl
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,10 +3,12 @@
|
||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
|
||||
#include "BouncingBallsScreensaver.h"
|
||||
#include "MatrixRainScreensaver.h"
|
||||
#include "MystifyScreensaver.h"
|
||||
#include "McpScreensaver.h"
|
||||
#include "Screensaver.h"
|
||||
#include "StackChanScreensaver.h"
|
||||
|
||||
@@ -127,6 +129,9 @@ void DisplayIdleService::activateScreensaver() {
|
||||
case settings::display::ScreensaverType::StackChan:
|
||||
screensaver = std::make_unique<StackChanScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::McpScreen:
|
||||
screensaver = std::make_unique<McpScreensaver>();
|
||||
break;
|
||||
case settings::display::ScreensaverType::None:
|
||||
default:
|
||||
// Just black screen, no animated screensaver
|
||||
@@ -273,6 +278,49 @@ bool DisplayIdleService::isScreensaverActive() const {
|
||||
return screensaverOverlay != nullptr;
|
||||
}
|
||||
|
||||
void DisplayIdleService::startMcpScreensaver() {
|
||||
if (!lvgl_try_lock(200)) {
|
||||
LOG_W(TAG, "startMcpScreensaver: failed to acquire LVGL lock");
|
||||
return;
|
||||
}
|
||||
|
||||
if (screensaverOverlay != nullptr) {
|
||||
const auto& mcpState = mcp::getState();
|
||||
if (mcpState.drawArea != nullptr) {
|
||||
lvgl_unlock();
|
||||
return;
|
||||
}
|
||||
if (screensaver) {
|
||||
screensaver->stop();
|
||||
screensaver.reset();
|
||||
}
|
||||
lv_obj_delete(screensaverOverlay);
|
||||
screensaverOverlay = nullptr;
|
||||
}
|
||||
|
||||
screensaverActiveCounter = 0;
|
||||
backlightOff = false;
|
||||
setBacklightBrightness(cachedDisplaySettings.backlightDuty == 0
|
||||
? 255 : cachedDisplaySettings.backlightDuty);
|
||||
|
||||
lv_coord_t screenW = lv_display_get_horizontal_resolution(nullptr);
|
||||
lv_coord_t screenH = lv_display_get_vertical_resolution(nullptr);
|
||||
screensaverOverlay = lv_obj_create(lv_layer_top());
|
||||
lv_obj_remove_style_all(screensaverOverlay);
|
||||
lv_obj_set_size(screensaverOverlay, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_pos(screensaverOverlay, 0, 0);
|
||||
lv_obj_set_style_bg_color(screensaverOverlay, lv_color_black(), 0);
|
||||
lv_obj_set_style_bg_opa(screensaverOverlay, LV_OPA_COVER, 0);
|
||||
lv_obj_add_flag(screensaverOverlay, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(screensaverOverlay, stopScreensaverCb, LV_EVENT_CLICKED, this);
|
||||
|
||||
screensaver = std::make_unique<McpScreensaver>();
|
||||
screensaver->start(screensaverOverlay, screenW, screenH);
|
||||
lvgl_unlock();
|
||||
displayDimmed = true;
|
||||
LOG_I(TAG, "MCP screensaver activated");
|
||||
}
|
||||
|
||||
void DisplayIdleService::reloadSettings() {
|
||||
// Set flag for thread-safe reload - actual reload happens in tick()
|
||||
settingsReloadRequested.store(true, std::memory_order_release);
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "McpScreensaver.h"
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "McpScreensaver";
|
||||
#include <esp_heap_caps.h>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
|
||||
void McpScreensaver::start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) {
|
||||
auto& state = mcp::getState();
|
||||
|
||||
// Full-screen canvas on the overlay
|
||||
lv_obj_t* canvas = lv_canvas_create(overlay);
|
||||
lv_obj_set_size(canvas, screenW, screenH);
|
||||
lv_obj_set_pos(canvas, 0, 0);
|
||||
lv_obj_set_style_radius(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_border_width(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_set_style_pad_all(canvas, 0, LV_PART_MAIN);
|
||||
lv_obj_remove_flag(canvas, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
// Allocate framebuffer (prefer SPIRAM)
|
||||
size_t requiredSize = (size_t)screenW * screenH * sizeof(uint16_t);
|
||||
framebuffer = (uint16_t*)heap_caps_malloc(requiredSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (framebuffer == nullptr) {
|
||||
framebuffer = (uint16_t*)heap_caps_malloc(requiredSize, MALLOC_CAP_8BIT);
|
||||
}
|
||||
framebufferSize = (framebuffer != nullptr) ? requiredSize : 0;
|
||||
|
||||
if (framebuffer == nullptr) {
|
||||
LOG_E(TAG, "Failed to allocate %uB framebuffer", (unsigned)requiredSize);
|
||||
lv_obj_t* err = lv_label_create(canvas);
|
||||
lv_label_set_text(err, "Framebuffer alloc failed");
|
||||
lv_obj_center(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fill with a dark slate background (inverted for display path)
|
||||
size_t pixelCount = (size_t)screenW * screenH;
|
||||
for (size_t i = 0; i < pixelCount; ++i) {
|
||||
framebuffer[i] = ~0x18E3; // dark blue-grey
|
||||
}
|
||||
|
||||
lv_canvas_set_buffer(canvas, framebuffer, screenW, screenH, LV_COLOR_FORMAT_RGB565);
|
||||
|
||||
// Waiting label (removed on first MCP draw via lv_obj_clean)
|
||||
lv_obj_t* waitLabel = lv_label_create(canvas);
|
||||
lv_label_set_text(waitLabel, "Waiting for LLM...");
|
||||
lv_obj_set_style_text_color(waitLabel, lv_color_black(), LV_PART_MAIN); // white on screen (inverted)
|
||||
lv_obj_align(waitLabel, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
lv_obj_t* resLabel = lv_label_create(canvas);
|
||||
lv_label_set_text_fmt(resLabel, "Display: %dx%d", (int)screenW, (int)screenH);
|
||||
lv_color_t resColor = lv_palette_lighten(LV_PALETTE_BLUE, 3);
|
||||
lv_obj_set_style_text_color(resLabel, lv_color_make(~resColor.red, ~resColor.green, ~resColor.blue), LV_PART_MAIN);
|
||||
lv_obj_align(resLabel, LV_ALIGN_CENTER, 0, 10);
|
||||
|
||||
// Register with McpSystemState
|
||||
std::lock_guard<std::mutex> lock(state.mutex);
|
||||
state.drawArea = canvas;
|
||||
state.framebuffer = framebuffer;
|
||||
state.framebufferSize = framebufferSize;
|
||||
state.displayWidth = (uint16_t)screenW;
|
||||
state.displayHeight = (uint16_t)screenH;
|
||||
state.drawWidth = (uint16_t)screenW;
|
||||
state.drawHeight = (uint16_t)screenH;
|
||||
// Don't reset overrideActive — if the LLM already drew, we keep the content
|
||||
|
||||
LOG_I(TAG, "McpScreensaver started (%dx%d)", (int)screenW, (int)screenH);
|
||||
}
|
||||
|
||||
void McpScreensaver::stop() {
|
||||
auto& state = mcp::getState();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(state.mutex);
|
||||
state.drawArea = nullptr;
|
||||
state.framebuffer = nullptr;
|
||||
state.framebufferSize = 0;
|
||||
state.overrideActive = false;
|
||||
}
|
||||
|
||||
if (framebuffer != nullptr) {
|
||||
heap_caps_free(framebuffer);
|
||||
framebuffer = nullptr;
|
||||
framebufferSize = 0;
|
||||
}
|
||||
|
||||
LOG_I(TAG, "McpScreensaver stopped");
|
||||
}
|
||||
|
||||
void McpScreensaver::update(lv_coord_t /*screenW*/, lv_coord_t /*screenH*/) {
|
||||
// MCP draws on demand via HTTP — no per-frame animation needed
|
||||
}
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "Screensaver.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace tt::service::displayidle {
|
||||
|
||||
/**
|
||||
* MCP Screen screensaver.
|
||||
* Creates a full-screen LVGL canvas on the overlay and registers it in
|
||||
* McpSystemState so that MCP HTTP draw commands can paint to it.
|
||||
* Dismissed by a touch event (handled by the parent DisplayIdle overlay).
|
||||
*/
|
||||
class McpScreensaver final : public Screensaver {
|
||||
uint16_t* framebuffer = nullptr;
|
||||
size_t framebufferSize = 0;
|
||||
|
||||
public:
|
||||
McpScreensaver() = default;
|
||||
~McpScreensaver() override = default;
|
||||
|
||||
void start(lv_obj_t* overlay, lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
void stop() override;
|
||||
void update(lv_coord_t screenW, lv_coord_t screenH) override;
|
||||
};
|
||||
|
||||
} // namespace tt::service::displayidle
|
||||
|
||||
#endif // ESP_PLATFORM
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,6 +32,8 @@
|
||||
#include "app/manager.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <esp_chip_info.h>
|
||||
#include <esp_flash.h>
|
||||
#include <esp_heap_caps.h>
|
||||
@@ -213,7 +215,7 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
serverEnabled = g_cachedSettings.webServerEnabled;
|
||||
serverEnabled = g_cachedSettings.webServerEnabled || settings::mcp::loadOrGetDefault().mcpEnabled;
|
||||
}
|
||||
// Subscribe to settings change events to refresh cache
|
||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||
@@ -222,6 +224,10 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
const bool enabled = g_cachedSettings.webServerEnabled || settings::mcp::loadOrGetDefault().mcpEnabled;
|
||||
if (g_webServerInstance.load() != nullptr) {
|
||||
g_webServerInstance.load()->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -481,6 +487,21 @@ bool WebServerService::startServer() {
|
||||
.callback = handleAdminPost,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
#ifdef ESP_PLATFORM
|
||||
// MCP is LAN-local and is enabled whenever the web server is enabled.
|
||||
{
|
||||
.uri = "/api/mcp",
|
||||
.method = HTTP_METHOD_POST,
|
||||
.callback = handleApiMcp,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
{
|
||||
.uri = "/api/screen/raw",
|
||||
.method = HTTP_METHOD_POST,
|
||||
.callback = handleApiScreenRaw,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
#endif
|
||||
// API endpoints for system info, apps, wifi, etc
|
||||
{
|
||||
.uri = "/api/*",
|
||||
@@ -528,6 +549,12 @@ bool WebServerService::startServer() {
|
||||
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
||||
publish_event(this, WebServerEvent::WebServerStarted);
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
if (settings::mcp::loadOrGetDefault().mcpEnabled) {
|
||||
mcp::startVideoStreamServer();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Show statusbar icon
|
||||
if (statusbarIconId >= 0) {
|
||||
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
||||
@@ -544,6 +571,9 @@ void WebServerService::stopServer() {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
mcp::stopVideoStreamServer();
|
||||
#endif
|
||||
http_server_free(httpServer);
|
||||
httpServer = nullptr;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ static std::string getSettingsFilePath() {
|
||||
}
|
||||
|
||||
constexpr auto* SETTINGS_KEY_ORIENTATION = "orientation";
|
||||
constexpr auto* SETTINGS_KEY_FONT_SIZE = "fontSize";
|
||||
constexpr auto* SETTINGS_KEY_GAMMA_CURVE = "gammaCurve";
|
||||
constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
||||
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
||||
@@ -73,6 +74,34 @@ static bool fromString(const std::string& str, Orientation& orientation) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::string toString(FontSize font_size) {
|
||||
switch (font_size) {
|
||||
using enum FontSize;
|
||||
case Small:
|
||||
return "Small";
|
||||
case Default:
|
||||
return "Default";
|
||||
case Large:
|
||||
return "Large";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
static bool fromString(const std::string& str, FontSize& font_size) {
|
||||
if (str == "Small") {
|
||||
font_size = FontSize::Small;
|
||||
return true;
|
||||
} else if (str == "Default") {
|
||||
font_size = FontSize::Default;
|
||||
return true;
|
||||
} else if (str == "Large") {
|
||||
font_size = FontSize::Large;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string toString(ScreensaverType type) {
|
||||
switch (type) {
|
||||
using enum ScreensaverType;
|
||||
@@ -86,6 +115,8 @@ static std::string toString(ScreensaverType type) {
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
case McpScreen:
|
||||
return "McpScreen";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -107,6 +138,9 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
||||
} else if (str == "StackChan") {
|
||||
type = ScreensaverType::StackChan;
|
||||
return true;
|
||||
} else if (str == "McpScreen") {
|
||||
type = ScreensaverType::McpScreen;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -129,6 +163,12 @@ bool load(DisplaySettings& settings) {
|
||||
orientation = getDefaultOrientation();
|
||||
}
|
||||
|
||||
auto font_size_entry = map.find(SETTINGS_KEY_FONT_SIZE);
|
||||
FontSize font_size = FontSize::Default;
|
||||
if (font_size_entry != map.end()) {
|
||||
fromString(font_size_entry->second, font_size);
|
||||
}
|
||||
|
||||
auto gamma_entry = map.find(SETTINGS_KEY_GAMMA_CURVE);
|
||||
int gamma_curve = 0;
|
||||
if (gamma_entry != map.end()) {
|
||||
@@ -163,6 +203,7 @@ bool load(DisplaySettings& settings) {
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
settings.fontSize = font_size;
|
||||
settings.gammaCurve = gamma_curve;
|
||||
settings.backlightDuty = backlight_duty;
|
||||
settings.backlightTimeoutEnabled = timeout_enabled;
|
||||
@@ -175,6 +216,7 @@ bool load(DisplaySettings& settings) {
|
||||
DisplaySettings getDefault() {
|
||||
return DisplaySettings {
|
||||
.orientation = getDefaultOrientation(),
|
||||
.fontSize = FontSize::Default,
|
||||
.gammaCurve = 1,
|
||||
.backlightDuty = 200,
|
||||
.backlightTimeoutEnabled = false,
|
||||
@@ -196,6 +238,7 @@ bool save(const DisplaySettings& settings) {
|
||||
map[SETTINGS_KEY_BACKLIGHT_DUTY] = std::to_string(settings.backlightDuty);
|
||||
map[SETTINGS_KEY_GAMMA_CURVE] = std::to_string(settings.gammaCurve);
|
||||
map[SETTINGS_KEY_ORIENTATION] = toString(settings.orientation);
|
||||
map[SETTINGS_KEY_FONT_SIZE] = toString(settings.fontSize);
|
||||
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
||||
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
||||
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <tactility/log.h>
|
||||
#include <app/paths.h>
|
||||
|
||||
constexpr auto* TAG = "McpSettings";
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::settings::mcp {
|
||||
|
||||
|
||||
static std::string getSettingsFilePath() {
|
||||
char path[256];
|
||||
if (app_paths_get_user_data_path("tactility.mcpsettings", "mcp.properties", path, sizeof(path)) != ERROR_NONE) {
|
||||
return "";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
constexpr auto* KEY_MCP_ENABLED = "mcpEnabled";
|
||||
|
||||
bool load(McpSettings& settings) {
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::isFile(settings_path)) {
|
||||
return false;
|
||||
}
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(settings_path, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mcp_enabled = map.find(KEY_MCP_ENABLED);
|
||||
settings.mcpEnabled = (mcp_enabled != map.end())
|
||||
? (mcp_enabled->second == "1" || mcp_enabled->second == "true")
|
||||
: false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
McpSettings getDefault() {
|
||||
return McpSettings{
|
||||
.mcpEnabled = false
|
||||
};
|
||||
}
|
||||
|
||||
McpSettings loadOrGetDefault() {
|
||||
McpSettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
if (!save(settings)) {
|
||||
LOG_W(TAG, "Failed to save default MCP settings");
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool save(const McpSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[KEY_MCP_ENABLED] = settings.mcpEnabled ? "true" : "false";
|
||||
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
LOG_E(TAG, "Failed to create parent dir for %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file::savePropertiesFile(settings_path, map)) {
|
||||
LOG_E(TAG, "Failed to save MCP settings to %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user