Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c937bb3177 | |||
| 28a277184a | |||
| 69e66d4e79 | |||
| 78d6bc0bf7 | |||
| a158fe1696 |
@@ -553,9 +553,14 @@ error_t close_stream(AudioStreamHandle handle_base) {
|
|||||||
Device* codec = is_input ? data->input_codec : data->output_codec;
|
Device* codec = is_input ? data->input_codec : data->output_codec;
|
||||||
AudioStreamHandleImpl** slot = is_input ? &data->open_input : &data->open_output;
|
AudioStreamHandleImpl** slot = is_input ? &data->open_input : &data->open_output;
|
||||||
|
|
||||||
|
// Determine if underlying codec is shared (BOTH codec used for both directions)
|
||||||
|
// In that case we must NOT close the codec if the other direction is still active.
|
||||||
|
Device* other_codec = is_input ? data->output_codec : data->input_codec;
|
||||||
|
AudioStreamHandleImpl** other_slot = is_input ? &data->open_output : &data->open_input;
|
||||||
|
bool codec_shared = (codec != nullptr && other_codec != nullptr && codec == other_codec);
|
||||||
|
|
||||||
xSemaphoreTake(data->mutex, portMAX_DELAY);
|
xSemaphoreTake(data->mutex, portMAX_DELAY);
|
||||||
if (handle->closing) {
|
if (handle->closing) {
|
||||||
// Already being closed by another caller (e.g. concurrent set_enabled + app close).
|
|
||||||
xSemaphoreGive(data->mutex);
|
xSemaphoreGive(data->mutex);
|
||||||
return ERROR_NONE;
|
return ERROR_NONE;
|
||||||
}
|
}
|
||||||
@@ -563,14 +568,16 @@ error_t close_stream(AudioStreamHandle handle_base) {
|
|||||||
if (*slot == handle) {
|
if (*slot == handle) {
|
||||||
*slot = nullptr;
|
*slot = nullptr;
|
||||||
}
|
}
|
||||||
|
bool other_still_open = (other_slot != nullptr && *other_slot != nullptr && *other_slot != reinterpret_cast<AudioStreamHandleImpl*>(1));
|
||||||
bool must_drain = (handle->busy_count > 0);
|
bool must_drain = (handle->busy_count > 0);
|
||||||
|
bool should_close_codec = !codec_shared || !other_still_open;
|
||||||
xSemaphoreGive(data->mutex);
|
xSemaphoreGive(data->mutex);
|
||||||
|
|
||||||
if (must_drain && handle->drain_semaphore != nullptr) {
|
if (must_drain && handle->drain_semaphore != nullptr) {
|
||||||
xSemaphoreTake(handle->drain_semaphore, portMAX_DELAY);
|
xSemaphoreTake(handle->drain_semaphore, portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codec != nullptr) {
|
if (should_close_codec && codec != nullptr) {
|
||||||
audio_codec_close(codec);
|
audio_codec_close(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,16 +53,36 @@ error_t open(Device* device, const struct AudioCodecStreamConfig* config) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (data->is_open) {
|
if (data->is_open) {
|
||||||
// open_direction == BOTH already serves INPUT-only or OUTPUT-only requests on the
|
// ES8311 is configured for WORK_MODE_BOTH, so an already-open device
|
||||||
// same sample settings -- only an exact direction mismatch (e.g. requesting BOTH
|
// can serve the opposite direction without reopening, provided sample
|
||||||
// while opened for INPUT only) needs a reopen.
|
// settings match. Promote open_direction to BOTH when we see a
|
||||||
bool direction_compatible = data->open_direction == config->direction
|
// complementary request.
|
||||||
|| data->open_direction == AUDIO_CODEC_DIR_BOTH;
|
bool is_complementary = (data->open_direction == AUDIO_CODEC_DIR_OUTPUT && config->direction == AUDIO_CODEC_DIR_INPUT)
|
||||||
|
|| (data->open_direction == AUDIO_CODEC_DIR_INPUT && config->direction == AUDIO_CODEC_DIR_OUTPUT);
|
||||||
|
bool direction_compatible = (data->open_direction == config->direction)
|
||||||
|
|| (data->open_direction == AUDIO_CODEC_DIR_BOTH)
|
||||||
|
|| (config->direction == AUDIO_CODEC_DIR_BOTH)
|
||||||
|
|| is_complementary;
|
||||||
bool same_config = direction_compatible
|
bool same_config = direction_compatible
|
||||||
&& data->open_sample_info.bits_per_sample == sample_info.bits_per_sample
|
&& data->open_sample_info.bits_per_sample == sample_info.bits_per_sample
|
||||||
&& data->open_sample_info.channel == sample_info.channel
|
&& data->open_sample_info.channel == sample_info.channel
|
||||||
&& data->open_sample_info.sample_rate == sample_info.sample_rate;
|
&& data->open_sample_info.sample_rate == sample_info.sample_rate;
|
||||||
return same_config ? ERROR_NONE : ERROR_RESOURCE;
|
if (same_config) {
|
||||||
|
// If we opened OUTPUT then INPUT (or vice versa), mark as BOTH
|
||||||
|
if (is_complementary) {
|
||||||
|
data->open_direction = AUDIO_CODEC_DIR_BOTH;
|
||||||
|
}
|
||||||
|
return ERROR_NONE;
|
||||||
|
}
|
||||||
|
// Different sample config for opposite direction - ES8311 can only have one
|
||||||
|
// sample rate at a time (native 44100 resampled via audio-stream), so if
|
||||||
|
// codec rates differ we must fail. But if both sides use native 44100 (audio-stream
|
||||||
|
// always opens codec with native rate), we allow it.
|
||||||
|
if (direction_compatible) {
|
||||||
|
// Allow if both use same native rate path (audio-stream opens with codec's native)
|
||||||
|
return ERROR_RESOURCE;
|
||||||
|
}
|
||||||
|
return ERROR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esp_codec_dev_open(data->codec_device, &sample_info) != ESP_CODEC_DEV_OK) {
|
if (esp_codec_dev_open(data->codec_device, &sample_info) != ESP_CODEC_DEV_OK) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ enum class ScreensaverType {
|
|||||||
Mystify,
|
Mystify,
|
||||||
MatrixRain,
|
MatrixRain,
|
||||||
StackChan,
|
StackChan,
|
||||||
|
McpScreen,
|
||||||
Count // Sentinel for bounds checking - must be last
|
Count // Sentinel for bounds checking - must be last
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ struct DisplaySettings {
|
|||||||
bool backlightTimeoutEnabled;
|
bool backlightTimeoutEnabled;
|
||||||
uint32_t backlightTimeoutMs; // 0 = Never
|
uint32_t backlightTimeoutMs; // 0 = Never
|
||||||
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
||||||
|
bool disableScreensaverWhenCharging = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Compares default settings with the function parameter to return the difference */
|
/** Compares default settings with the function parameter to return the difference */
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace tt::settings::mcp {
|
||||||
|
|
||||||
|
struct McpSettings {
|
||||||
|
bool mcpEnabled = false; // Enable MCP server endpoints on system web server
|
||||||
|
};
|
||||||
|
|
||||||
|
bool load(McpSettings& settings);
|
||||||
|
McpSettings getDefault();
|
||||||
|
McpSettings loadOrGetDefault();
|
||||||
|
bool save(const McpSettings& settings);
|
||||||
|
|
||||||
|
} // namespace tt::settings::mcp
|
||||||
@@ -14,6 +14,9 @@ bool isValidAppVersionName(const std::string& version);
|
|||||||
bool isValidAppVersionCode(const std::string& version);
|
bool isValidAppVersionCode(const std::string& version);
|
||||||
bool isValidName(const std::string& name);
|
bool isValidName(const std::string& name);
|
||||||
|
|
||||||
|
/** Parses a comma-separated flags string (e.g. "HideStatusBar,Hidden") into appFlags bitmask. */
|
||||||
|
uint16_t parseAppFlagsString(const std::string& raw);
|
||||||
|
|
||||||
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
/** Parses a V1 (sectioned INI, e.g. "[app]versionName=...") manifest map. */
|
||||||
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest& manifest);
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
namespace tt::app::files { bool isSupportedAppFile(const std::string& filename); bool isSupportedImageFile(const std::string& filename); bool isSupportedTextFile(const std::string& filename); bool isSupportedAudioFile(const std::string& filename); } // namespace
|
||||||
namespace tt::app::files {
|
|
||||||
|
|
||||||
bool isSupportedAppFile(const std::string& filename);
|
|
||||||
bool isSupportedImageFile(const std::string& filename);
|
|
||||||
bool isSupportedTextFile(const std::string& filename);
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <mutex>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <tactility/device.h>
|
||||||
|
#include <tactility/drivers/audio_stream.h>
|
||||||
|
|
||||||
|
namespace tt::mcp {
|
||||||
|
|
||||||
|
struct McpSystemState {
|
||||||
|
std::mutex mutex;
|
||||||
|
bool overrideActive = false;
|
||||||
|
|
||||||
|
// UI elements when McpOverrideApp is active
|
||||||
|
lv_obj_t* drawArea = nullptr;
|
||||||
|
uint16_t* framebuffer = nullptr;
|
||||||
|
size_t framebufferSize = 0;
|
||||||
|
uint16_t displayWidth = 320;
|
||||||
|
uint16_t displayHeight = 240;
|
||||||
|
uint16_t drawWidth = 320;
|
||||||
|
uint16_t drawHeight = 240;
|
||||||
|
int drawColor = 1; // 0 = white, 1 = black
|
||||||
|
|
||||||
|
// Audio device status
|
||||||
|
Device* i2sDevice = nullptr;
|
||||||
|
Device* audioStreamDevice = nullptr;
|
||||||
|
AudioStreamHandle audioHandle = nullptr;
|
||||||
|
volatile bool audioBusy = false;
|
||||||
|
volatile bool audioRunning = false; // Used to abort play/record loop
|
||||||
|
|
||||||
|
// Video streaming state
|
||||||
|
volatile bool streamRunning = false;
|
||||||
|
void* streamTaskHandle = nullptr; // use void* to avoid freertos header inclusion dependency
|
||||||
|
uint32_t framesDrawn = 0;
|
||||||
|
uint32_t tcpBytesReceived = 0;
|
||||||
|
uint32_t lastDrawMs = 0;
|
||||||
|
double lastFps = 0.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
McpSystemState& getState();
|
||||||
|
|
||||||
|
bool clearScreen(int color);
|
||||||
|
bool drawText(const std::string& text, int x, int y, int size);
|
||||||
|
bool drawRgb565(const uint8_t* data, size_t size, int x, int y, int w, int h);
|
||||||
|
bool drawBmp(const uint8_t* data, size_t size, int x, int y);
|
||||||
|
bool drawPbm(const uint8_t* data, size_t size, int x, int y);
|
||||||
|
std::string getScreenshotPbmBase64();
|
||||||
|
|
||||||
|
bool playTone(int frequency, int durationMs, int volume, std::string& error);
|
||||||
|
bool recordVoice(int durationSec, const std::string& filename, size_t& recordedBytes, std::string& error);
|
||||||
|
bool playAudioFile(const std::string& filename, int volume, std::string& error);
|
||||||
|
bool playWavMemory(const uint8_t* data, size_t size, int volume, std::string& error);
|
||||||
|
bool playMp3File(const std::string& filename, int volume, std::string& error);
|
||||||
|
bool playMp3Memory(const uint8_t* data, size_t size, int volume, std::string& error);
|
||||||
|
|
||||||
|
bool getBatteryStatus(double& voltage_v, int& percentage_pct, std::string& error);
|
||||||
|
bool setLedColor(int r, int g, int b, const std::string& mode, std::string& error);
|
||||||
|
bool getSensors(double& temp_c, double& hum_pct, std::string& imu_json, std::string& error);
|
||||||
|
bool scanBleDevices(int duration_ms, std::string& devices_json, std::string& error);
|
||||||
|
bool writeSdFile(const std::string& filename, const std::string& content, std::string& error);
|
||||||
|
bool readSdFile(const std::string& filename, std::string& content, std::string& error);
|
||||||
|
bool downloadSdFile(const std::string& url, const std::string& filename, std::string& error);
|
||||||
|
|
||||||
|
bool startVideoStreamServer();
|
||||||
|
void stopVideoStreamServer();
|
||||||
|
bool getVideoStreamStats(std::string& stats_json);
|
||||||
|
|
||||||
|
bool listApps(std::string& apps_json, std::string& error);
|
||||||
|
bool runApp(const std::string& appId, std::string& error);
|
||||||
|
bool listSdFiles(const std::string& directory, std::string& files_json, std::string& error);
|
||||||
|
|
||||||
|
} // namespace tt::mcp
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,7 @@ class DisplayIdleService final : public Service {
|
|||||||
bool backlightOff = false;
|
bool backlightOff = false;
|
||||||
|
|
||||||
static void stopScreensaverCb(lv_event_t* e);
|
static void stopScreensaverCb(lv_event_t* e);
|
||||||
|
void stopScreensaverLocked();
|
||||||
|
|
||||||
/** @pre Caller must hold LVGL lock */
|
/** @pre Caller must hold LVGL lock */
|
||||||
void activateScreensaver();
|
void activateScreensaver();
|
||||||
@@ -63,6 +64,7 @@ public:
|
|||||||
* arbitrary threads while the timer is running.
|
* arbitrary threads while the timer is running.
|
||||||
*/
|
*/
|
||||||
void stopScreensaver();
|
void stopScreensaver();
|
||||||
|
void startMcpScreensaver();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the screensaver is currently active.
|
* Check if the screensaver is currently active.
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ private:
|
|||||||
static esp_err_t handleApiAppsInstall(httpd_req_t* request);
|
static esp_err_t handleApiAppsInstall(httpd_req_t* request);
|
||||||
static esp_err_t handleApiWifi(httpd_req_t* request);
|
static esp_err_t handleApiWifi(httpd_req_t* request);
|
||||||
static esp_err_t handleApiScreenshot(httpd_req_t* request);
|
static esp_err_t handleApiScreenshot(httpd_req_t* request);
|
||||||
|
static esp_err_t handleApiMcp(httpd_req_t* request);
|
||||||
|
static esp_err_t handleApiScreenRaw(httpd_req_t* request);
|
||||||
|
|
||||||
// Dynamic asset serving
|
// Dynamic asset serving
|
||||||
static esp_err_t handleAssets(httpd_req_t* request);
|
static esp_err_t handleAssets(httpd_req_t* request);
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ namespace app {
|
|||||||
namespace apwebserver { extern const AppManifest manifest; }
|
namespace apwebserver { extern const AppManifest manifest; }
|
||||||
namespace crashdiagnostics { extern const AppManifest manifest; }
|
namespace crashdiagnostics { extern const AppManifest manifest; }
|
||||||
namespace webserversettings { extern const AppManifest manifest; }
|
namespace webserversettings { extern const AppManifest manifest; }
|
||||||
|
namespace mcpsettings { extern const AppManifest manifest; }
|
||||||
|
namespace mcpoverride { extern const AppManifest manifest; }
|
||||||
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
#if CONFIG_TT_TDECK_WORKAROUND == 1
|
||||||
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
namespace keyboardsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||||
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
namespace trackballsettings { extern const AppManifest manifest; } // T-Deck only for now
|
||||||
@@ -213,6 +215,8 @@ static void registerInternalApps() {
|
|||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
addAppManifest(app::apwebserver::manifest);
|
addAppManifest(app::apwebserver::manifest);
|
||||||
addAppManifest(app::webserversettings::manifest);
|
addAppManifest(app::webserversettings::manifest);
|
||||||
|
addAppManifest(app::mcpsettings::manifest);
|
||||||
|
// mcpoverride internal only via McpScreensaver, not shown in launcher
|
||||||
addAppManifest(app::crashdiagnostics::manifest);
|
addAppManifest(app::crashdiagnostics::manifest);
|
||||||
addAppManifest(app::development::manifest);
|
addAppManifest(app::development::manifest);
|
||||||
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
#if defined(CONFIG_TT_TDECK_WORKAROUND)
|
||||||
|
|||||||
@@ -56,6 +56,34 @@ bool isValidName(const std::string& name) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t parseAppFlagsString(const std::string& raw) {
|
||||||
|
uint16_t flags = AppManifest::Flags::None;
|
||||||
|
if (raw.empty()) {
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto parts = string::split(raw, ",");
|
||||||
|
for (auto& part : parts) {
|
||||||
|
std::string trimmed = string::trim(part, " \t\r\n");
|
||||||
|
if (trimmed.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string lower = string::lowercase(trimmed);
|
||||||
|
|
||||||
|
if (lower == "hidestatusbar" || lower == "hide_statusbar" || lower == "hide-statusbar" || lower == "hide_status_bar") {
|
||||||
|
flags |= AppManifest::Flags::HideStatusBar;
|
||||||
|
} else if (lower == "hidden") {
|
||||||
|
flags |= AppManifest::Flags::Hidden;
|
||||||
|
} else if (lower == "none" || lower == "0" || lower == "") {
|
||||||
|
// keep as none, no additional flag
|
||||||
|
} else {
|
||||||
|
LOG_W(TAG, "Unknown app flag \"%s\" - ignoring", trimmed.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
/** The V1 format's first line is always the literal "[manifest]" section header; V2 files are flat from the first line onward. */
|
||||||
static bool detectIsV1Format(const std::string& filePath) {
|
static bool detectIsV1Format(const std::string& filePath) {
|
||||||
std::string first_line;
|
std::string first_line;
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ bool parseManifestV1(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional: [app]flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
||||||
|
auto flags_it = map.find("[app]flags");
|
||||||
|
if (flags_it != map.end()) {
|
||||||
|
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ bool parseManifestV2(const std::map<std::string, std::string>& map, AppManifest&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optional: app.flags - e.g. "HideStatusBar" or "HideStatusBar,Hidden"
|
||||||
|
auto flags_it = map.find("app.flags");
|
||||||
|
if (flags_it != map.end()) {
|
||||||
|
manifest.appFlags = parseAppFlagsString(flags_it->second);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class HalDisplayApp final : public App {
|
|||||||
lv_obj_t* timeoutSwitch = nullptr;
|
lv_obj_t* timeoutSwitch = nullptr;
|
||||||
lv_obj_t* timeoutDropdown = nullptr;
|
lv_obj_t* timeoutDropdown = nullptr;
|
||||||
lv_obj_t* screensaverDropdown = nullptr;
|
lv_obj_t* screensaverDropdown = nullptr;
|
||||||
|
lv_obj_t* disableWhenChargingWrapper = nullptr;
|
||||||
|
lv_obj_t* disableWhenChargingSwitch = nullptr;
|
||||||
|
|
||||||
static void onBacklightSliderEvent(lv_event_t* event) {
|
static void onBacklightSliderEvent(lv_event_t* event) {
|
||||||
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
@@ -72,6 +74,14 @@ class HalDisplayApp final : public App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void onDisableWhenChargingChanged(lv_event_t* event) {
|
||||||
|
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
||||||
|
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
|
bool enabled = lv_obj_has_state(sw, LV_STATE_CHECKED);
|
||||||
|
app->displaySettings.disableScreensaverWhenCharging = enabled;
|
||||||
|
app->displaySettingsUpdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
static void onTimeoutSwitch(lv_event_t* event) {
|
static void onTimeoutSwitch(lv_event_t* event) {
|
||||||
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
|
||||||
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||||
@@ -84,11 +94,17 @@ class HalDisplayApp final : public App {
|
|||||||
if (app->screensaverDropdown) {
|
if (app->screensaverDropdown) {
|
||||||
lv_obj_clear_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_clear_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
if (app->disableWhenChargingWrapper) {
|
||||||
|
lv_obj_clear_state(app->disableWhenChargingWrapper, LV_STATE_DISABLED);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
lv_obj_add_state(app->timeoutDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(app->timeoutDropdown, LV_STATE_DISABLED);
|
||||||
if (app->screensaverDropdown) {
|
if (app->screensaverDropdown) {
|
||||||
lv_obj_add_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(app->screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
if (app->disableWhenChargingWrapper) {
|
||||||
|
lv_obj_add_state(app->disableWhenChargingWrapper, LV_STATE_DISABLED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,13 +287,33 @@ public:
|
|||||||
|
|
||||||
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
screensaverDropdown = lv_dropdown_create(screensaver_wrapper);
|
||||||
// Note: order correlates with settings::display::ScreensaverType enum order
|
// Note: order correlates with settings::display::ScreensaverType enum order
|
||||||
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan");
|
lv_dropdown_set_options(screensaverDropdown, "None\nBouncing Balls\nMystify\nMatrix Rain\nStackChan\nMcpScreen");
|
||||||
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
lv_obj_align(screensaverDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||||
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
lv_obj_add_event_cb(screensaverDropdown, onScreensaverChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||||
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
lv_dropdown_set_selected(screensaverDropdown, static_cast<uint16_t>(displaySettings.screensaverType));
|
||||||
if (!displaySettings.backlightTimeoutEnabled) {
|
if (!displaySettings.backlightTimeoutEnabled) {
|
||||||
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
lv_obj_add_state(screensaverDropdown, LV_STATE_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable screensaver when charging toggle
|
||||||
|
disableWhenChargingWrapper = lv_obj_create(main_wrapper);
|
||||||
|
lv_obj_set_size(disableWhenChargingWrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_all(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_border_width(disableWhenChargingWrapper, 0, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
auto* charging_label = lv_label_create(disableWhenChargingWrapper);
|
||||||
|
lv_label_set_text(charging_label, "Disable on charging");
|
||||||
|
lv_obj_align(charging_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||||
|
|
||||||
|
disableWhenChargingSwitch = lv_switch_create(disableWhenChargingWrapper);
|
||||||
|
if (displaySettings.disableScreensaverWhenCharging) {
|
||||||
|
lv_obj_add_state(disableWhenChargingSwitch, LV_STATE_CHECKED);
|
||||||
|
}
|
||||||
|
lv_obj_align(disableWhenChargingSwitch, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||||
|
lv_obj_add_event_cb(disableWhenChargingSwitch, onDisableWhenChargingChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||||
|
if (!displaySettings.backlightTimeoutEnabled) {
|
||||||
|
lv_obj_add_state(disableWhenChargingWrapper, LV_STATE_DISABLED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,3 @@
|
|||||||
#include <Tactility/StringUtils.h>
|
#include <Tactility/StringUtils.h>
|
||||||
#include <Tactility/TactilityCore.h>
|
#include <Tactility/TactilityCore.h>
|
||||||
|
namespace tt::app::files { constexpr auto* TAG = "Files"; bool isSupportedAppFile(const std::string& filename) { return filename.ends_with(".app"); } bool isSupportedImageFile(const std::string& filename) { return string::lowercase(filename).ends_with(".png"); } bool isSupportedTextFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".txt")||l.ends_with(".ini")||l.ends_with(".json")||l.ends_with(".yaml")||l.ends_with(".yml")||l.ends_with(".lua")||l.ends_with(".js")||l.ends_with(".properties"); } bool isSupportedAudioFile(const std::string& filename) { std::string l=string::lowercase(filename); return l.ends_with(".mp3")||l.ends_with(".wav")||l.ends_with(".ogg")||l.ends_with(".flac"); } } // namespace
|
||||||
namespace tt::app::files {
|
|
||||||
|
|
||||||
constexpr auto* TAG = "Files";
|
|
||||||
|
|
||||||
bool isSupportedAppFile(const std::string& filename) {
|
|
||||||
return filename.ends_with(".app");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSupportedImageFile(const std::string& filename) {
|
|
||||||
// Currently only the PNG library is built into Tactility
|
|
||||||
return string::lowercase(filename).ends_with(".png");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSupportedTextFile(const std::string& filename) {
|
|
||||||
std::string filename_lower = string::lowercase(filename);
|
|
||||||
return filename_lower.ends_with(".txt") ||
|
|
||||||
filename_lower.ends_with(".ini") ||
|
|
||||||
filename_lower.ends_with(".json") ||
|
|
||||||
filename_lower.ends_with(".yaml") ||
|
|
||||||
filename_lower.ends_with(".yml") ||
|
|
||||||
filename_lower.ends_with(".lua") ||
|
|
||||||
filename_lower.ends_with(".js") ||
|
|
||||||
filename_lower.ends_with(".properties");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace tt::app::filebrowser
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <Tactility/app/files/SupportedFiles.h>
|
#include <Tactility/app/files/SupportedFiles.h>
|
||||||
|
#include <Tactility/Bundle.h>
|
||||||
#include <Tactility/app/files/View.h>
|
#include <Tactility/app/files/View.h>
|
||||||
|
|
||||||
#include <Tactility/Platform.h>
|
#include <Tactility/Platform.h>
|
||||||
@@ -228,9 +229,17 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
|||||||
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
if (kernel::getPlatform() == kernel::PlatformEsp) {
|
||||||
notes::start(processed_filepath);
|
notes::start(processed_filepath);
|
||||||
} else {
|
} else {
|
||||||
// Remove forward slash, because we need a relative path
|
|
||||||
notes::start(processed_filepath.substr(1));
|
notes::start(processed_filepath.substr(1));
|
||||||
}
|
}
|
||||||
|
} else if (isSupportedAudioFile(filename)) {
|
||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
auto bundle = std::make_shared<Bundle>();
|
||||||
|
bundle->putString("file", processed_filepath);
|
||||||
|
auto loader = service::loader::findLoaderService();
|
||||||
|
if (loader) {
|
||||||
|
loader->start("one.tactility.mp3player", bundle);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
LOG_W(TAG, "Opening files of this type is not supported");
|
LOG_W(TAG, "Opening files of this type is not supported");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
|
||||||
|
#include <Tactility/Tactility.h>
|
||||||
|
#include <Tactility/mcp/McpSystem.h>
|
||||||
|
#include <Tactility/lvgl/Toolbar.h>
|
||||||
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
|
#include <tactility/log.h>
|
||||||
|
|
||||||
|
constexpr auto* TAG = "McpOverrideApp";
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <tactility/lvgl_icon_shared.h>
|
||||||
|
#include <esp_heap_caps.h>
|
||||||
|
|
||||||
|
namespace tt::app::mcpoverride {
|
||||||
|
|
||||||
|
|
||||||
|
class McpOverrideApp final : public App {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void onCreate(AppContext& app) override {
|
||||||
|
// Prepare global state
|
||||||
|
auto& state = mcp::getState();
|
||||||
|
state.overrideActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||||
|
LOG_I(TAG, "onShow: Starting MCP Override display canvas");
|
||||||
|
auto& state = mcp::getState();
|
||||||
|
|
||||||
|
lv_obj_remove_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_pad_row(parent, 0, LV_PART_MAIN);
|
||||||
|
|
||||||
|
// Standard toolbar so the user can navigate back
|
||||||
|
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||||
|
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||||
|
|
||||||
|
lv_obj_t* title_label = lv_label_create(toolbar);
|
||||||
|
lv_label_set_text(title_label, "MCP Override Screen");
|
||||||
|
|
||||||
|
// Create drawing canvas
|
||||||
|
state.drawArea = lv_canvas_create(parent);
|
||||||
|
lv_obj_set_width(state.drawArea, LV_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(state.drawArea, 1);
|
||||||
|
lv_obj_set_style_radius(state.drawArea, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_width(state.drawArea, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_pad_all(state.drawArea, 0, LV_PART_MAIN);
|
||||||
|
lv_obj_remove_flag(state.drawArea, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
// Get display metrics
|
||||||
|
lv_display_t* display = lv_obj_get_display(parent);
|
||||||
|
state.displayWidth = lv_display_get_horizontal_resolution(display);
|
||||||
|
state.displayHeight = lv_display_get_vertical_resolution(display);
|
||||||
|
|
||||||
|
lv_obj_update_layout(parent);
|
||||||
|
state.drawWidth = lv_obj_get_content_width(state.drawArea);
|
||||||
|
state.drawHeight = lv_obj_get_content_height(state.drawArea);
|
||||||
|
|
||||||
|
// Allocate framebuffer
|
||||||
|
size_t required_size = (size_t)state.drawWidth * state.drawHeight * sizeof(uint16_t);
|
||||||
|
if (state.framebuffer == nullptr || state.framebufferSize != required_size) {
|
||||||
|
if (state.framebuffer != nullptr) {
|
||||||
|
heap_caps_free(state.framebuffer);
|
||||||
|
state.framebuffer = nullptr;
|
||||||
|
}
|
||||||
|
state.framebuffer = (uint16_t*)heap_caps_malloc(required_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||||
|
if (state.framebuffer == nullptr) {
|
||||||
|
state.framebuffer = (uint16_t*)heap_caps_malloc(required_size, MALLOC_CAP_8BIT);
|
||||||
|
}
|
||||||
|
state.framebufferSize = state.framebuffer == nullptr ? 0 : required_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.framebuffer == nullptr) {
|
||||||
|
LOG_E(TAG, "Failed to allocate %u bytes framebuffer", (unsigned)required_size);
|
||||||
|
lv_obj_t* error = lv_label_create(state.drawArea);
|
||||||
|
lv_label_set_text(error, "Framebuffer allocation failed");
|
||||||
|
lv_obj_center(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_canvas_set_buffer(
|
||||||
|
state.drawArea,
|
||||||
|
state.framebuffer,
|
||||||
|
state.drawWidth,
|
||||||
|
state.drawHeight,
|
||||||
|
LV_COLOR_FORMAT_RGB565
|
||||||
|
);
|
||||||
|
|
||||||
|
// Initialize welcome/waiting screen if LLM hasn't written anything yet
|
||||||
|
if (!state.overrideActive) {
|
||||||
|
// Fill with a nice dark blue/slate color
|
||||||
|
for (size_t i = 0; i < (size_t)state.drawWidth * state.drawHeight; ++i) {
|
||||||
|
state.framebuffer[i] = 0x18E3;
|
||||||
|
}
|
||||||
|
state.drawColor = 1;
|
||||||
|
|
||||||
|
lv_obj_t* welcome_label = lv_label_create(state.drawArea);
|
||||||
|
lv_label_set_text(welcome_label, "Waiting for LLM...");
|
||||||
|
lv_obj_set_style_text_color(welcome_label, lv_color_white(), LV_PART_MAIN);
|
||||||
|
lv_obj_align(welcome_label, LV_ALIGN_CENTER, 0, -20);
|
||||||
|
|
||||||
|
lv_obj_t* desc_label = lv_label_create(state.drawArea);
|
||||||
|
lv_label_set_text_fmt(desc_label, "Display Resolution: %ux%u", state.drawWidth, state.drawHeight);
|
||||||
|
lv_obj_set_style_text_color(desc_label, lv_palette_lighten(LV_PALETTE_BLUE, 3), LV_PART_MAIN);
|
||||||
|
lv_obj_align(desc_label, LV_ALIGN_CENTER, 0, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onHide(AppContext& app) override {
|
||||||
|
LOG_I(TAG, "onHide: Tearing down MCP Override canvas");
|
||||||
|
auto& state = mcp::getState();
|
||||||
|
state.drawArea = nullptr;
|
||||||
|
if (state.framebuffer != nullptr) {
|
||||||
|
heap_caps_free(state.framebuffer);
|
||||||
|
state.framebuffer = nullptr;
|
||||||
|
state.framebufferSize = 0;
|
||||||
|
}
|
||||||
|
state.overrideActive = false;
|
||||||
|
|
||||||
|
// Stop any running tone or recording to prevent stuck state
|
||||||
|
state.audioRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void onDestroy(AppContext& app) override {
|
||||||
|
onHide(app);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const AppManifest manifest = {
|
||||||
|
.appId = "one.tactility.mcpscreen", // Keep the original appId for compatibility
|
||||||
|
.appName = "MCP Override Screen",
|
||||||
|
.appIcon = LVGL_ICON_SHARED_TOOLBAR,
|
||||||
|
.appCategory = Category::System,
|
||||||
|
.createApp = create<McpOverrideApp>
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
@@ -0,0 +1,196 @@
|
|||||||
|
#ifdef ESP_PLATFORM
|
||||||
|
|
||||||
|
#include <Tactility/Tactility.h>
|
||||||
|
#include <Tactility/settings/McpSettings.h>
|
||||||
|
#include <Tactility/settings/WebServerSettings.h>
|
||||||
|
#include <Tactility/service/webserver/WebServerService.h>
|
||||||
|
#include <Tactility/lvgl/Toolbar.h>
|
||||||
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
|
#include <tactility/log.h>
|
||||||
|
|
||||||
|
constexpr auto* TAG = "McpSettingsApp";
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <tactility/lvgl_icon_shared.h>
|
||||||
|
|
||||||
|
#include <esp_netif.h>
|
||||||
|
#include <esp_wifi.h>
|
||||||
|
|
||||||
|
namespace tt::app::mcpsettings {
|
||||||
|
|
||||||
|
|
||||||
|
class McpSettingsApp final : public App {
|
||||||
|
|
||||||
|
settings::mcp::McpSettings mcpSettings;
|
||||||
|
settings::mcp::McpSettings originalSettings;
|
||||||
|
settings::webserver::WebServerSettings wsSettings;
|
||||||
|
bool updated = false;
|
||||||
|
|
||||||
|
lv_obj_t* switchMcpEnabled = nullptr;
|
||||||
|
lv_obj_t* labelUrlValue = nullptr;
|
||||||
|
|
||||||
|
static void onMcpEnabledSwitch(lv_event_t* e) {
|
||||||
|
auto* app = static_cast<McpSettingsApp*>(lv_event_get_user_data(e));
|
||||||
|
bool enabled = lv_obj_has_state(app->switchMcpEnabled, LV_STATE_CHECKED);
|
||||||
|
getMainDispatcher().dispatch([app, enabled] {
|
||||||
|
app->mcpSettings.mcpEnabled = enabled;
|
||||||
|
app->updated = true;
|
||||||
|
if (lvgl::lock(100)) {
|
||||||
|
app->updateUrlDisplay();
|
||||||
|
lvgl::unlock();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateUrlDisplay() {
|
||||||
|
if (!labelUrlValue) return;
|
||||||
|
|
||||||
|
if (!mcpSettings.mcpEnabled) {
|
||||||
|
lv_label_set_text(labelUrlValue, "Disabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string url = "http://";
|
||||||
|
bool ip_added = false;
|
||||||
|
|
||||||
|
// Try getting station IP first (we are connected to home Wi-Fi)
|
||||||
|
esp_netif_t* sta_netif = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
|
||||||
|
if (sta_netif != nullptr) {
|
||||||
|
esp_netif_ip_info_t ip_info;
|
||||||
|
if (esp_netif_get_ip_info(sta_netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
|
||||||
|
char ip_str[16];
|
||||||
|
snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip));
|
||||||
|
url += ip_str;
|
||||||
|
ip_added = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no station IP, check if the AP interface has a valid IP address
|
||||||
|
if (!ip_added) {
|
||||||
|
esp_netif_t* ap_netif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
|
||||||
|
if (ap_netif != nullptr) {
|
||||||
|
esp_netif_ip_info_t ip_info;
|
||||||
|
if (esp_netif_get_ip_info(ap_netif, &ip_info) == ESP_OK && ip_info.ip.addr != 0) {
|
||||||
|
char ip_str[16];
|
||||||
|
snprintf(ip_str, sizeof(ip_str), IPSTR, IP2STR(&ip_info.ip));
|
||||||
|
url += ip_str;
|
||||||
|
ip_added = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback if no active IP address is detected on either interface
|
||||||
|
if (!ip_added) {
|
||||||
|
if (wsSettings.wifiMode == settings::webserver::WiFiMode::AccessPoint) {
|
||||||
|
url += "192.168.4.1";
|
||||||
|
} else {
|
||||||
|
url = "Connecting...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.starts_with("http://")) {
|
||||||
|
if (wsSettings.webServerPort != 80) {
|
||||||
|
url += ":" + std::to_string(wsSettings.webServerPort);
|
||||||
|
}
|
||||||
|
url += "/api/mcp";
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_label_set_text(labelUrlValue, url.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
void onCreate(AppContext& app) override {
|
||||||
|
mcpSettings = settings::mcp::loadOrGetDefault();
|
||||||
|
originalSettings = mcpSettings;
|
||||||
|
wsSettings = settings::webserver::loadOrGetDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||||
|
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
lv_obj_t* toolbar = lvgl::toolbar_create(parent, app);
|
||||||
|
|
||||||
|
// MCP Enable toggle on toolbar
|
||||||
|
switchMcpEnabled = lvgl::toolbar_add_switch_action(toolbar);
|
||||||
|
if (mcpSettings.mcpEnabled) {
|
||||||
|
lv_obj_add_state(switchMcpEnabled, LV_STATE_CHECKED);
|
||||||
|
}
|
||||||
|
lv_obj_add_event_cb(switchMcpEnabled, onMcpEnabledSwitch, LV_EVENT_VALUE_CHANGED, this);
|
||||||
|
|
||||||
|
auto* main_wrapper = lv_obj_create(parent);
|
||||||
|
lv_obj_set_flex_flow(main_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_width(main_wrapper, LV_PCT(100));
|
||||||
|
lv_obj_set_flex_grow(main_wrapper, 1);
|
||||||
|
|
||||||
|
// URL Display
|
||||||
|
auto* url_wrapper = lv_obj_create(main_wrapper);
|
||||||
|
lv_obj_set_size(url_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_style_pad_all(url_wrapper, 10, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_style_border_width(url_wrapper, 1, LV_STATE_DEFAULT);
|
||||||
|
lv_obj_set_flex_flow(url_wrapper, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_style_flex_cross_place(url_wrapper, LV_FLEX_ALIGN_START, 0);
|
||||||
|
|
||||||
|
auto* url_title = lv_label_create(url_wrapper);
|
||||||
|
lv_label_set_text(url_title, "MCP Endpoint URL:");
|
||||||
|
|
||||||
|
labelUrlValue = lv_label_create(url_wrapper);
|
||||||
|
if (lv_display_get_color_format(lv_obj_get_display(parent)) == LV_COLOR_FORMAT_L8) {
|
||||||
|
lv_obj_set_style_text_color(labelUrlValue, lv_theme_get_color_secondary(labelUrlValue), LV_PART_MAIN);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_style_text_color(labelUrlValue, lv_palette_main(LV_PALETTE_BLUE), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUrlDisplay();
|
||||||
|
|
||||||
|
// Info / Documentation text
|
||||||
|
auto* info_label = lv_label_create(main_wrapper);
|
||||||
|
lv_label_set_long_mode(info_label, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_width(info_label, LV_PCT(95));
|
||||||
|
if (lv_display_get_color_format(lv_obj_get_display(parent)) != LV_COLOR_FORMAT_L8) {
|
||||||
|
lv_obj_set_style_text_color(info_label, lv_palette_main(LV_PALETTE_GREY), 0);
|
||||||
|
}
|
||||||
|
lv_label_set_text(info_label,
|
||||||
|
"MCP (Model Context Protocol) Screen service allows LLMs to interact with the device "
|
||||||
|
"screen, audio, and tools directly.\n\n"
|
||||||
|
"Endpoints:\n"
|
||||||
|
"- POST /api/mcp (JSON-RPC tools)\n"
|
||||||
|
"- POST /api/screen/raw (big-endian RGB565 writes)\n\n"
|
||||||
|
"To show the LLM canvas, select 'MCP Screen' in Settings -> Display -> Screensaver. "
|
||||||
|
"The canvas also pops up automatically when an LLM sends a draw command.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void onHide(AppContext& app) override {
|
||||||
|
if (updated) {
|
||||||
|
const auto copy = mcpSettings;
|
||||||
|
const bool mcpStateChanged = (copy.mcpEnabled != originalSettings.mcpEnabled);
|
||||||
|
|
||||||
|
getMainDispatcher().dispatch([copy, mcpStateChanged]{
|
||||||
|
// Save to properties file
|
||||||
|
if (!settings::mcp::save(copy)) {
|
||||||
|
LOG_W(TAG, "Failed to persist MCP settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish WebServerSettingsChanged event so the HTTP server restarts/refreshes if needed
|
||||||
|
service::webserver::getPubsub()->publish(service::webserver::WebServerEvent::WebServerSettingsChanged);
|
||||||
|
|
||||||
|
if (mcpStateChanged) {
|
||||||
|
LOG_I(TAG, "MCP server state changed to %s", copy.mcpEnabled ? "enabled" : "disabled");
|
||||||
|
service::webserver::setWebServerEnabled(copy.mcpEnabled);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const AppManifest manifest = {
|
||||||
|
.appId = "McpSettings",
|
||||||
|
.appName = "MCP Screen",
|
||||||
|
.appIcon = LVGL_ICON_SHARED_SETTINGS,
|
||||||
|
.appCategory = Category::Settings,
|
||||||
|
.createApp = create<McpSettingsApp>
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // ESP_PLATFORM
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,13 @@
|
|||||||
#include "MatrixRainScreensaver.h"
|
#include "MatrixRainScreensaver.h"
|
||||||
#include "MystifyScreensaver.h"
|
#include "MystifyScreensaver.h"
|
||||||
#include "StackChanScreensaver.h"
|
#include "StackChanScreensaver.h"
|
||||||
|
#include "McpScreensaver.h"
|
||||||
|
|
||||||
#include <tactility/log.h>
|
|
||||||
#include <Tactility/CoreDefines.h>
|
#include <Tactility/CoreDefines.h>
|
||||||
#include <Tactility/hal/display/DisplayDevice.h>
|
#include <Tactility/hal/display/DisplayDevice.h>
|
||||||
|
#include <Tactility/hal/power/PowerDevice.h>
|
||||||
#include <Tactility/lvgl/LvglSync.h>
|
#include <Tactility/lvgl/LvglSync.h>
|
||||||
|
#include <Tactility/mcp/McpSystem.h>
|
||||||
#include <Tactility/service/ServiceContext.h>
|
#include <Tactility/service/ServiceContext.h>
|
||||||
#include <Tactility/service/ServiceManifest.h>
|
#include <Tactility/service/ServiceManifest.h>
|
||||||
#include <Tactility/service/ServiceRegistration.h>
|
#include <Tactility/service/ServiceRegistration.h>
|
||||||
@@ -28,6 +30,22 @@ static std::shared_ptr<hal::display::DisplayDevice> getDisplay() {
|
|||||||
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
return hal::findFirstDevice<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isDeviceCharging() {
|
||||||
|
bool charging = false;
|
||||||
|
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&charging](const auto& power) {
|
||||||
|
if (!power->supportsMetric(hal::power::PowerDevice::MetricType::IsCharging)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
hal::power::PowerDevice::MetricData data;
|
||||||
|
if (power->getMetric(hal::power::PowerDevice::MetricType::IsCharging, data) && data.valueAsBool) {
|
||||||
|
charging = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return charging;
|
||||||
|
}
|
||||||
|
|
||||||
void DisplayIdleService::stopScreensaverCb(lv_event_t* e) {
|
void DisplayIdleService::stopScreensaverCb(lv_event_t* e) {
|
||||||
auto* self = static_cast<DisplayIdleService*>(lv_event_get_user_data(e));
|
auto* self = static_cast<DisplayIdleService*>(lv_event_get_user_data(e));
|
||||||
lv_event_stop_bubbling(e);
|
lv_event_stop_bubbling(e);
|
||||||
@@ -103,6 +121,9 @@ void DisplayIdleService::activateScreensaver() {
|
|||||||
case settings::display::ScreensaverType::StackChan:
|
case settings::display::ScreensaverType::StackChan:
|
||||||
screensaver = std::make_unique<StackChanScreensaver>();
|
screensaver = std::make_unique<StackChanScreensaver>();
|
||||||
break;
|
break;
|
||||||
|
case settings::display::ScreensaverType::McpScreen:
|
||||||
|
screensaver = std::make_unique<McpScreensaver>();
|
||||||
|
break;
|
||||||
case settings::display::ScreensaverType::None:
|
case settings::display::ScreensaverType::None:
|
||||||
default:
|
default:
|
||||||
// Just black screen, no animated screensaver
|
// Just black screen, no animated screensaver
|
||||||
@@ -179,7 +200,11 @@ void DisplayIdleService::tick() {
|
|||||||
displayDimmed = false;
|
displayDimmed = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
bool charging_blocks = cachedDisplaySettings.disableScreensaverWhenCharging && isDeviceCharging();
|
||||||
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
if (!displayDimmed && inactive_ms >= cachedDisplaySettings.backlightTimeoutMs) {
|
||||||
|
if (charging_blocks) {
|
||||||
|
// Skip screensaver while charging
|
||||||
|
} else {
|
||||||
if (!lvgl::lock(100)) {
|
if (!lvgl::lock(100)) {
|
||||||
return; // Retry on next tick
|
return; // Retry on next tick
|
||||||
}
|
}
|
||||||
@@ -190,8 +215,13 @@ void DisplayIdleService::tick() {
|
|||||||
display->setBacklightDuty(0);
|
display->setBacklightDuty(0);
|
||||||
}
|
}
|
||||||
displayDimmed = true;
|
displayDimmed = true;
|
||||||
} else if (displayDimmed && (inactive_ms < kWakeActivityThresholdMs)) {
|
}
|
||||||
|
} else if (displayDimmed) {
|
||||||
|
if (inactive_ms < kWakeActivityThresholdMs) {
|
||||||
stopScreensaver();
|
stopScreensaver();
|
||||||
|
} else if (charging_blocks) {
|
||||||
|
stopScreensaver();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,6 +284,61 @@ bool DisplayIdleService::isScreensaverActive() const {
|
|||||||
return screensaverOverlay != nullptr;
|
return screensaverOverlay != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DisplayIdleService::startMcpScreensaver() {
|
||||||
|
if (!lvgl::lock(200)) {
|
||||||
|
LOG_W(TAG, "startMcpScreensaver: failed to acquire LVGL lock");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (screensaverOverlay != nullptr) {
|
||||||
|
// Screensaver already active — if drawArea is registered we're done,
|
||||||
|
// otherwise stop the current one so we can replace it with McpScreensaver.
|
||||||
|
const auto& mcpState = mcp::getState();
|
||||||
|
if (mcpState.drawArea != nullptr) {
|
||||||
|
lvgl::unlock();
|
||||||
|
return; // McpScreensaver already running
|
||||||
|
}
|
||||||
|
// Wrong screensaver type active — tear it down first
|
||||||
|
if (screensaver) {
|
||||||
|
screensaver->stop();
|
||||||
|
screensaver.reset();
|
||||||
|
}
|
||||||
|
lv_obj_delete(screensaverOverlay);
|
||||||
|
screensaverOverlay = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
screensaverActiveCounter = 0;
|
||||||
|
backlightOff = false;
|
||||||
|
|
||||||
|
// Ensure backlight is active if the display supports it
|
||||||
|
auto display = getDisplay();
|
||||||
|
if (display != nullptr && display->supportsBacklightDuty()) {
|
||||||
|
uint8_t duty = cachedDisplaySettings.backlightDuty;
|
||||||
|
if (duty == 0) duty = 255; // ensure visible if settings not loaded / default
|
||||||
|
display->setBacklightDuty(duty);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_coord_t screenW = lv_display_get_horizontal_resolution(nullptr);
|
||||||
|
lv_coord_t screenH = lv_display_get_vertical_resolution(nullptr);
|
||||||
|
|
||||||
|
lv_obj_t* top = lv_layer_top();
|
||||||
|
screensaverOverlay = lv_obj_create(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() {
|
void DisplayIdleService::reloadSettings() {
|
||||||
// Set flag for thread-safe reload - actual reload happens in tick()
|
// Set flag for thread-safe reload - actual reload happens in tick()
|
||||||
settingsReloadRequested.store(true, std::memory_order_release);
|
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
@@ -5,6 +5,8 @@
|
|||||||
#include <Tactility/service/webserver/AssetVersion.h>
|
#include <Tactility/service/webserver/AssetVersion.h>
|
||||||
#include <Tactility/service/ServiceManifest.h>
|
#include <Tactility/service/ServiceManifest.h>
|
||||||
#include <Tactility/settings/WebServerSettings.h>
|
#include <Tactility/settings/WebServerSettings.h>
|
||||||
|
#include <Tactility/settings/McpSettings.h>
|
||||||
|
#include <Tactility/mcp/McpSystem.h>
|
||||||
#include <Tactility/MountPoints.h>
|
#include <Tactility/MountPoints.h>
|
||||||
#include <Tactility/file/File.h>
|
#include <Tactility/file/File.h>
|
||||||
#include <Tactility/lvgl/Statusbar.h>
|
#include <Tactility/lvgl/Statusbar.h>
|
||||||
@@ -215,7 +217,8 @@ bool WebServerService::onStart(ServiceContext& service) {
|
|||||||
lock.lock();
|
lock.lock();
|
||||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||||
g_settingsCached = true;
|
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
|
// Subscribe to settings change events to refresh cache
|
||||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||||
@@ -265,7 +268,11 @@ void WebServerService::setEnabled(bool enabled) {
|
|||||||
startServer();
|
startServer();
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
stopServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,6 +521,11 @@ bool WebServerService::startServer() {
|
|||||||
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
LOG_I(TAG, "HTTP server started successfully on port %u", (unsigned)settings.webServerPort);
|
||||||
publish_event(this, WebServerEvent::WebServerStarted);
|
publish_event(this, WebServerEvent::WebServerStarted);
|
||||||
|
|
||||||
|
auto mcpSettings = settings::mcp::loadOrGetDefault();
|
||||||
|
if (mcpSettings.mcpEnabled) {
|
||||||
|
mcp::startVideoStreamServer();
|
||||||
|
}
|
||||||
|
|
||||||
// Show statusbar icon
|
// Show statusbar icon
|
||||||
if (statusbarIconId >= 0) {
|
if (statusbarIconId >= 0) {
|
||||||
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
lvgl::statusbar_icon_set_image(statusbarIconId, LVGL_ICON_STATUSBAR_CLOUD);
|
||||||
@@ -533,6 +545,8 @@ void WebServerService::stopServer() {
|
|||||||
httpServer->stop();
|
httpServer->stop();
|
||||||
httpServer.reset();
|
httpServer.reset();
|
||||||
|
|
||||||
|
mcp::stopVideoStreamServer();
|
||||||
|
|
||||||
// Stop AP mode WiFi if we started it
|
// Stop AP mode WiFi if we started it
|
||||||
if (apWifiInitialized || apNetif != nullptr) {
|
if (apWifiInitialized || apNetif != nullptr) {
|
||||||
stopApMode();
|
stopApMode();
|
||||||
@@ -1025,15 +1039,24 @@ esp_err_t WebServerService::handleApiGet(httpd_req_t* request) {
|
|||||||
return ESP_FAIL;
|
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) {
|
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;
|
bool authPassed = false;
|
||||||
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
esp_err_t authResult = validateRequestAuth(request, authPassed);
|
||||||
if (!authPassed) {
|
if (!authPassed) {
|
||||||
return authResult;
|
return authResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* uri = request->uri;
|
|
||||||
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
||||||
return handleApiAppsRun(request);
|
return handleApiAppsRun(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ constexpr auto* SETTINGS_KEY_BACKLIGHT_DUTY = "backlightDuty";
|
|||||||
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
constexpr auto* SETTINGS_KEY_TIMEOUT_ENABLED = "backlightTimeoutEnabled";
|
||||||
constexpr auto* SETTINGS_KEY_TIMEOUT_MS = "backlightTimeoutMs";
|
constexpr auto* SETTINGS_KEY_TIMEOUT_MS = "backlightTimeoutMs";
|
||||||
constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
||||||
|
constexpr auto* SETTINGS_KEY_DISABLE_WHEN_CHARGING = "disableScreensaverWhenCharging";
|
||||||
|
|
||||||
static Orientation getDefaultOrientation() {
|
static Orientation getDefaultOrientation() {
|
||||||
auto* display = lv_display_get_default();
|
auto* display = lv_display_get_default();
|
||||||
@@ -83,6 +84,8 @@ static std::string toString(ScreensaverType type) {
|
|||||||
return "MatrixRain";
|
return "MatrixRain";
|
||||||
case StackChan:
|
case StackChan:
|
||||||
return "StackChan";
|
return "StackChan";
|
||||||
|
case McpScreen:
|
||||||
|
return "McpScreen";
|
||||||
default:
|
default:
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
@@ -104,6 +107,9 @@ static bool fromString(const std::string& str, ScreensaverType& type) {
|
|||||||
} else if (str == "StackChan") {
|
} else if (str == "StackChan") {
|
||||||
type = ScreensaverType::StackChan;
|
type = ScreensaverType::StackChan;
|
||||||
return true;
|
return true;
|
||||||
|
} else if (str == "McpScreen") {
|
||||||
|
type = ScreensaverType::McpScreen;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -159,12 +165,19 @@ bool load(DisplaySettings& settings) {
|
|||||||
fromString(screensaver_entry->second, screensaver_type);
|
fromString(screensaver_entry->second, screensaver_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool disable_when_charging = false;
|
||||||
|
auto charging_entry = map.find(SETTINGS_KEY_DISABLE_WHEN_CHARGING);
|
||||||
|
if (charging_entry != map.end()) {
|
||||||
|
disable_when_charging = (charging_entry->second == "1" || charging_entry->second == "true" || charging_entry->second == "True");
|
||||||
|
}
|
||||||
|
|
||||||
settings.orientation = orientation;
|
settings.orientation = orientation;
|
||||||
settings.gammaCurve = gamma_curve;
|
settings.gammaCurve = gamma_curve;
|
||||||
settings.backlightDuty = backlight_duty;
|
settings.backlightDuty = backlight_duty;
|
||||||
settings.backlightTimeoutEnabled = timeout_enabled;
|
settings.backlightTimeoutEnabled = timeout_enabled;
|
||||||
settings.backlightTimeoutMs = timeout_ms;
|
settings.backlightTimeoutMs = timeout_ms;
|
||||||
settings.screensaverType = screensaver_type;
|
settings.screensaverType = screensaver_type;
|
||||||
|
settings.disableScreensaverWhenCharging = disable_when_charging;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -176,7 +189,8 @@ DisplaySettings getDefault() {
|
|||||||
.backlightDuty = 200,
|
.backlightDuty = 200,
|
||||||
.backlightTimeoutEnabled = false,
|
.backlightTimeoutEnabled = false,
|
||||||
.backlightTimeoutMs = 60000,
|
.backlightTimeoutMs = 60000,
|
||||||
.screensaverType = ScreensaverType::BouncingBalls
|
.screensaverType = ScreensaverType::BouncingBalls,
|
||||||
|
.disableScreensaverWhenCharging = false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +210,7 @@ bool save(const DisplaySettings& settings) {
|
|||||||
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
map[SETTINGS_KEY_TIMEOUT_ENABLED] = settings.backlightTimeoutEnabled ? "1" : "0";
|
||||||
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
map[SETTINGS_KEY_TIMEOUT_MS] = std::to_string(settings.backlightTimeoutMs);
|
||||||
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
map[SETTINGS_KEY_SCREENSAVER_TYPE] = toString(settings.screensaverType);
|
||||||
|
map[SETTINGS_KEY_DISABLE_WHEN_CHARGING] = settings.disableScreensaverWhenCharging ? "1" : "0";
|
||||||
auto settings_path = getSettingsFilePath();
|
auto settings_path = getSettingsFilePath();
|
||||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#include <Tactility/settings/McpSettings.h>
|
||||||
|
#include <Tactility/file/PropertiesFile.h>
|
||||||
|
#include <Tactility/file/File.h>
|
||||||
|
#include <tactility/log.h>
|
||||||
|
|
||||||
|
constexpr auto* TAG = "McpSettings";
|
||||||
|
#include <Tactility/Paths.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace tt::settings::mcp {
|
||||||
|
|
||||||
|
|
||||||
|
static std::string getSettingsFilePath() {
|
||||||
|
return getUserDataPath() + "/settings/mcp.properties";
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -81,3 +81,70 @@ TEST_CASE("parseManifestV2() should fail when the app id is invalid") {
|
|||||||
AppManifest manifest;
|
AppManifest manifest;
|
||||||
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
CHECK_EQ(parseManifestV2(properties, manifest), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseAppFlagsString() should parse various flag combinations") {
|
||||||
|
CHECK_EQ(parseAppFlagsString(""), 0);
|
||||||
|
CHECK_EQ(parseAppFlagsString("None"), 0);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar"), AppManifest::Flags::HideStatusBar);
|
||||||
|
CHECK_EQ(parseAppFlagsString("hidden"), AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar,Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString(" hidestatusbar , hidden "), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
CHECK_EQ(parseAppFlagsString("HideStatusBar, Hidden"), AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse V1 flags for fullscreen") {
|
||||||
|
TestFile file("test-manifest-v1-flags.properties");
|
||||||
|
file.writeData(
|
||||||
|
"[manifest]\n"
|
||||||
|
"version=0.1\n"
|
||||||
|
"[target]\n"
|
||||||
|
"sdk=0.0.0\n"
|
||||||
|
"platforms=esp32\n"
|
||||||
|
"[app]\n"
|
||||||
|
"id=one.tactility.sdktest\n"
|
||||||
|
"versionName=0.1.0\n"
|
||||||
|
"versionCode=1\n"
|
||||||
|
"name=SDK Test\n"
|
||||||
|
"flags=HideStatusBar\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse V2 flags for fullscreen") {
|
||||||
|
TestFile file("test-manifest-v2-flags.properties");
|
||||||
|
file.writeData(
|
||||||
|
"manifest.version=0.1\n"
|
||||||
|
"target.sdk=0.0.0\n"
|
||||||
|
"target.platforms=esp32\n"
|
||||||
|
"app.id=one.tactility.sdktest\n"
|
||||||
|
"app.version.name=0.1.0\n"
|
||||||
|
"app.version.code=1\n"
|
||||||
|
"app.name=SDK Test\n"
|
||||||
|
"app.flags=HideStatusBar\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags & AppManifest::Flags::HideStatusBar, AppManifest::Flags::HideStatusBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("parseManifest() should parse combined flags") {
|
||||||
|
TestFile file("test-manifest-v2-flags2.properties");
|
||||||
|
file.writeData(
|
||||||
|
"manifest.version=0.1\n"
|
||||||
|
"target.sdk=0.0.0\n"
|
||||||
|
"target.platforms=esp32\n"
|
||||||
|
"app.id=one.tactility.sdktest\n"
|
||||||
|
"app.version.name=0.1.0\n"
|
||||||
|
"app.version.code=1\n"
|
||||||
|
"app.name=SDK Test\n"
|
||||||
|
"app.flags=HideStatusBar,Hidden\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
AppManifest manifest;
|
||||||
|
CHECK_EQ(parseManifest(file.getPath(), manifest), true);
|
||||||
|
CHECK_EQ(manifest.appFlags, (AppManifest::Flags::HideStatusBar | AppManifest::Flags::Hidden));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user