Compare commits
10 Commits
c8ee763f3d
...
89e8baf517
| Author | SHA1 | Date | |
|---|---|---|---|
| 89e8baf517 | |||
| 2060095028 | |||
| 620d56e19a | |||
| a0583e3a30 | |||
| 054d1286b2 | |||
| 85da419a98 | |||
| 87c82f5314 | |||
| 4b7f82c38f | |||
| 6d55f0b200 | |||
| 61fc67cf4c |
@@ -63,3 +63,7 @@ Strong success criteria let you loop independently. Weak criteria ("make it work
|
||||
---
|
||||
|
||||
**These guidelines are working if:** fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
|
||||
|
||||
For current-firmware merges, board customization retention, ESP-IDF build/flash,
|
||||
and external-app compatibility verification, also follow
|
||||
`.claude/skills/tactility-firmware-development/SKILL.md`.
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
---
|
||||
name: tactility-firmware-development
|
||||
description: Use when merging current Tactility firmware, preserving local ES3C28P/ES3C35P customizations, building/flashing ESP32 firmware, or validating external apps against it.
|
||||
---
|
||||
|
||||
# Tactility firmware development
|
||||
|
||||
## Scope and success criteria
|
||||
|
||||
Use this skill for firmware upgrades, especially when upstream changes the app
|
||||
loader, dashboard API, SDK export, or device model. Before editing, record the
|
||||
active branch, `git status --short`, selected `Devices/<id>`, serial port, and
|
||||
the expected device identity. Preserve user work and local board
|
||||
customizations; do not reset or overwrite a dirty tree.
|
||||
|
||||
Success is not merely a successful flash: the board must boot, mount storage,
|
||||
return `/api/sysinfo`, expose required internal apps, and accept an external
|
||||
app rebuilt against this exact firmware.
|
||||
|
||||
## Upgrade and customization audit
|
||||
|
||||
1. Fetch and compare the intended upstream branch before merging. Treat
|
||||
`upstream/main` as distinct from experimental release/IDF branches unless
|
||||
the task explicitly asks for one of those branches.
|
||||
2. Merge without discarding local work (for example, `git merge --autostash
|
||||
upstream/main` after inspecting status). Resolve conflicts by preserving
|
||||
required ES3C28P and ES3C35P device definitions, partition selection,
|
||||
display/font customizations, and product features.
|
||||
3. Compare the pre-upgrade customization commit against the resulting worktree.
|
||||
Check new app registrations, CMake/source inclusion, settings pages,
|
||||
web-server endpoints, and board-specific `sdkconfig` entries—not just files
|
||||
that happen to conflict.
|
||||
4. Commit the resulting firmware customization as a focused, reviewable
|
||||
commit after `git diff --check`.
|
||||
|
||||
## Multi-binary external-app compatibility
|
||||
|
||||
Upstream app packaging changed to `bin/<platform>/<binary>.elf`. The old
|
||||
`elf/<platform>.elf` archive layout produces a loader `Not executable` error.
|
||||
|
||||
- Manifest v0.2: `bin/esp32s3/app.elf`
|
||||
- Manifest v0.3: `bin/esp32s3/<app.0.binary>.elf`
|
||||
|
||||
When this change arrives, update the companion app tool and rebuild every app
|
||||
from a fresh SDK exported from this firmware. Do not attempt to repair a
|
||||
packaged ELF on the SD card: its layout and ABI must both be regenerated.
|
||||
|
||||
## Build and flash
|
||||
|
||||
Use the installed IDF 5.5 environment; host virtual environments can corrupt
|
||||
both Python dependencies and IDF tooling:
|
||||
|
||||
```zsh
|
||||
unset VIRTUAL_ENV PYTHONPATH PYTHONHOME
|
||||
export IDF_PYTHON_ENV_PATH=/Users/adolforeyna/.espressif/python_env/idf5.5_py3.9_env
|
||||
source /Users/adolforeyna/esp/esp-idf/export.sh
|
||||
|
||||
# Select/check the intended board before this step.
|
||||
python device.py <device-id>
|
||||
idf.py build
|
||||
idf.py -p /dev/cu.usbmodemXXXX flash
|
||||
```
|
||||
|
||||
`Tactility/CMakeLists.txt` uses a non-configure-dependent source glob. After
|
||||
adding a new `.c`/`.cpp` file, run `idf.py reconfigure build`; otherwise a
|
||||
linker error for a newly referenced symbol may only mean CMake has not
|
||||
discovered the source file yet.
|
||||
|
||||
## Boot and feature acceptance
|
||||
|
||||
Capture serial at 115200 after flash or reset. Confirm the board name, SD-card
|
||||
mount, HTTP-server start, Wi-Fi address, and any feature-specific startup logs.
|
||||
Then query the resolved device:
|
||||
|
||||
```zsh
|
||||
curl -fsS http://<ip>/api/sysinfo
|
||||
curl -fsS http://<ip>/api/apps
|
||||
```
|
||||
|
||||
For MCP settings, verify the `McpSettings` internal app appears in `/api/apps`.
|
||||
When enabled, verify MCP stream startup logs. For a feature restored from an
|
||||
older customization, validate its registration path and persisted settings,
|
||||
not only its source files.
|
||||
|
||||
## External-app acceptance gate
|
||||
|
||||
Use the companion app skill's exact-firmware wrapper:
|
||||
|
||||
```zsh
|
||||
cd /path/to/tactility_apps
|
||||
scripts/build_current_firmware_app.sh Apps/MyApp --firmware /path/to/tactility
|
||||
```
|
||||
|
||||
Inspect the resulting tar member path, install through port-80 dashboard API,
|
||||
launch it, and read serial. Required evidence is the loader's `Loading
|
||||
.../bin/...`, an ELF entry address, `Task started`, and app-specific startup
|
||||
logs. HTTP 200 or a package simply appearing in `/api/apps` is insufficient.
|
||||
|
||||
## Host simulator (buildsim) + web viewer
|
||||
|
||||
The POSIX simulator runs the real firmware (LVGL, services, web server) on
|
||||
macOS/Linux with an SDL backend. macOS has no visible window (upstream
|
||||
`.github/workflows/build-simulator.yml`: "macOS simulator currently fails due
|
||||
to main thread requirement for rendering" — AppKit menu init must happen on
|
||||
the process main thread, but FreeRTOS-POSIX parks main in `sigwait` and runs
|
||||
everything on pthreads). The supported loop is **headless + web viewer**:
|
||||
screenshots render server-side regardless of any window.
|
||||
|
||||
Code locations:
|
||||
|
||||
- `Devices/simulator/Source/module.cpp` — display resolution + `SIM_DISPLAY_W/H`
|
||||
- `Devices/simulator/Source/drivers/sdl_display.{h,cpp}` — SDL backend
|
||||
- `Devices/simulator/Source/drivers/sdl_input.{h,cpp}` — pointer/key state +
|
||||
web touch-injection override
|
||||
- `Tactility/Source/service/webserver/WebServerService.cpp` — `/sim` viewer,
|
||||
`/sim/api/*` aliases, `POST /api/sim/touch`, `GET /api/screenshot?fast=`
|
||||
- `Tactility/Private/Tactility/service/webserver/WebServerService.h` — handler decls
|
||||
|
||||
### Build and run
|
||||
|
||||
```zsh
|
||||
# one-time host deps (outside any ESP-IDF env)
|
||||
mkdir -p /tmp/simbin && ln -sf "$(which python3)" /tmp/simbin/python
|
||||
pip3 install --break-system-packages lark pyyaml # devicetree compiler
|
||||
|
||||
cd /path/to/tactility
|
||||
export PATH="/tmp/simbin:$PATH"
|
||||
env -u ESP_IDF_VERSION -u IDF_PATH cmake -S . -B buildsim -DCMAKE_BUILD_TYPE=Release
|
||||
env -u ESP_IDF_VERSION -u IDF_PATH cmake --build buildsim --target Tactility -j "$(sysctl -n hw.ncpu)"
|
||||
|
||||
# POSIX SDK for host apps (arm64)
|
||||
env -u ESP_IDF_VERSION -u IDF_PATH cmake --build buildsim --target TactilityKernel lvgl minitar minmea \
|
||||
app-module crypt-module gps-module http-module lvgl-module lvgl-window-manager-module service-module
|
||||
env -u ESP_IDF_VERSION -u IDF_PATH python3 Buildscripts/release-sdk-posix.py /tmp/sim-sdk
|
||||
|
||||
# release + headless run (MUST run from the firmware root: release-simulator.sh
|
||||
# uses relative version.txt / Data paths)
|
||||
sh Buildscripts/release-simulator.sh buildsim /tmp/simrun
|
||||
(cd /tmp/simrun && SIM_DISPLAY_W=480 SIM_DISPLAY_H=320 SDL_VIDEODRIVER=dummy \
|
||||
nohup ./Tactility > /tmp/sim_web.log 2>&1 &)
|
||||
curl -s --max-time 5 http://127.0.0.1/api/sysinfo | head -c 120
|
||||
```
|
||||
|
||||
Display resolution: `SIM_DISPLAY_W/H` env (default **480x320 landscape**,
|
||||
matching on-device screenshots). ES3C35P panel is 320x480 portrait in DTS but
|
||||
presents 480x320 landscape; ES3C28P is 320x240. The chosen geometry is logged
|
||||
as `Simulator Sim display WxH`. `SDL_VIDEODRIVER=dummy` is expected to log one
|
||||
`SdlDisplay Failed to create SDL window: Couldn't find matching render
|
||||
driver` line — LVGL still renders and screenshots work.
|
||||
|
||||
### Web viewer, touch, screenshots
|
||||
|
||||
- `GET /sim` → 301 to `/sim/` (trailing slash required so the page's relative
|
||||
`api/` URLs resolve under `/sim/`). Viewer polls `api/screenshot?fast=1`
|
||||
every 500 ms, footer shows live `naturalWidth×naturalHeight`, click/tap
|
||||
POSTs `api/sim/touch?x=&y=`.
|
||||
- `POST /api/sim/touch?x=123&y=456[&down=0|1]` (also `/sim/api/sim/touch` via
|
||||
alias). Coordinates are LVGL logical pixels. `down=1` (default) presses and
|
||||
**auto-releases after 1500 ms** (`SIM_TOUCH_HOLD_MS` in `sdl_input.cpp`),
|
||||
long enough for LVGL indev polls to register a click. Simulator-only: 404 on
|
||||
ESP32 (`#ifndef ESP_PLATFORM`).
|
||||
- `GET /api/screenshot?fast=1` (default): `lv_snapshot_take` (RGB888) → in-place
|
||||
BGR→RGB swap → `lodepng_encode24` **to memory** → chunked HTTP. No filesystem
|
||||
touch, ~8 ms/shot. `?fast=0` keeps the legacy `webscreenshotN.png` file path
|
||||
(slot scan + accumulation — avoid for viewer loops).
|
||||
- lodepng include in `.cpp`: `#define LODEPNG_NO_COMPILE_CPP` before
|
||||
`#include "src/libs/lodepng/lodepng.h"`, otherwise its C++ `std::vector`
|
||||
overloads collide with the C declarations (`conflicting types for 'encode'`).
|
||||
- MCP includes and `settings::mcp` reads are `#ifdef ESP_PLATFORM`-gated; the
|
||||
sim has no `McpSystem`.
|
||||
|
||||
### Tailscale viewer
|
||||
|
||||
```zsh
|
||||
tailscale serve --bg --set-path=/simagent http://127.0.0.1:80/
|
||||
# open: https://<node>/simagent/sim/
|
||||
```
|
||||
|
||||
The serve target must be `/` (not `/sim`): the page resolves `api/` against
|
||||
its own directory, so at `/simagent/sim/` fetches go to `/simagent/sim/api/…`,
|
||||
which tailscale strips to `/sim/api/…` and the firmware's `/sim/api/*`
|
||||
aliases (GET+POST, registered in `startServer()`) handle. Absolute `/api/…`
|
||||
URLs would 404 at the edge (no `/api` mount there).
|
||||
|
||||
### Simulator pitfalls
|
||||
|
||||
- **Rebuild ≠ redeploy.** `cmake --build buildsim` updates `buildsim/` only.
|
||||
Re-run `release-simulator.sh`, restart the process, then retest. A stale
|
||||
`/tmp/simrun/Tactility` serves old handlers with new logs nowhere to be found.
|
||||
- **C array `sizeof` decay.** A helper like
|
||||
`f(HttpServerRequest*, char uri[256])` sees `sizeof(uri) == 8`, truncating
|
||||
`get_uri` output to 7 chars (`/api/sy`, `/sim/ap` 404s). Pass the size
|
||||
explicitly: `f(request, buf, sizeof(buf))`.
|
||||
- **Log truncation.** `LOG_QUEUE_MESSAGE_MAX_LENGTH` is 256 (`TactilityKernel/
|
||||
private/tactility/log_queue.h`), including color/timestamp prefix. Long URIs
|
||||
and messages truncate — don't over-interpret a short path in the log.
|
||||
- **Auth.** The viewer and API handlers enforce `validateRequestAuth` like any
|
||||
other endpoint; failures surface as 401/404, not viewer bugs.
|
||||
@@ -17,7 +17,7 @@ apOpenNetwork=0
|
||||
apChannel=1
|
||||
|
||||
# Web Server Settings
|
||||
webServerEnabled=0
|
||||
webServerEnabled=1
|
||||
webServerPort=80
|
||||
|
||||
# HTTP Basic Authentication (optional)
|
||||
|
||||
@@ -23,3 +23,4 @@ storage.userDataLocation=SD
|
||||
# Launcher clock and full-screen wallpaper
|
||||
sdkconfig.CONFIG_LV_FONT_MONTSERRAT_48=y
|
||||
sdkconfig.CONFIG_LV_CACHE_DEF_SIZE=1048576
|
||||
sdkconfig.CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
compatible = "everest,es8311";
|
||||
reg = <0x18>;
|
||||
i2s = <&i2s0>;
|
||||
input-gain-percent = <100>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ display.shape=rectangle
|
||||
display.dpi=165
|
||||
|
||||
lvgl.colorDepth=16
|
||||
lvgl.fontSize=16
|
||||
|
||||
storage.userDataLocation=SD
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
compatible = "everest,es8311";
|
||||
reg = <0x18>;
|
||||
i2s = <&i2s0>;
|
||||
input-gain-percent = <100>;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,34 @@ constexpr size_t KEY_QUEUE_CAPACITY = 32;
|
||||
|
||||
SdlPointerState pointer_state = { 0, 0, false };
|
||||
|
||||
} // namespace
|
||||
|
||||
// Web touch-injection override (headless sim viewer). Guarded by tick count so
|
||||
// a press auto-releases even if the viewer never sends the release event.
|
||||
// File-scope (not anonymous namespace): the extern "C" setters below must be
|
||||
// visible to the linker for WebServerService's touch endpoint.
|
||||
bool touch_override_active = false;
|
||||
SdlPointerState touch_override = { 0, 0, false };
|
||||
uint32_t touch_override_until_tick = 0;
|
||||
#define SIM_TOUCH_HOLD_MS 1500
|
||||
|
||||
extern "C" void sdl_input_set_touch_override(int32_t x, int32_t y, bool pressed) {
|
||||
touch_override.x = x;
|
||||
touch_override.y = y;
|
||||
touch_override.pressed = pressed;
|
||||
touch_override_active = pressed;
|
||||
if (pressed) {
|
||||
touch_override_until_tick = SDL_GetTicks() + SIM_TOUCH_HOLD_MS;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void sdl_input_clear_touch_override(void) {
|
||||
touch_override_active = false;
|
||||
touch_override.pressed = false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
uint32_t key_queue[KEY_QUEUE_CAPACITY];
|
||||
size_t key_queue_head = 0;
|
||||
size_t key_queue_count = 0;
|
||||
@@ -70,7 +98,7 @@ uint32_t keycode_to_key(SDL_Keycode sdl_key, bool shift) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void sdl_input_pump() {
|
||||
if (!text_input_started) {
|
||||
@@ -125,6 +153,17 @@ void sdl_input_pump() {
|
||||
}
|
||||
|
||||
void sdl_input_get_pointer_state(SdlPointerState* out_state) {
|
||||
if (touch_override_active) {
|
||||
// Auto-release: viewer sends press only; LVGL needs press then release
|
||||
// to register a click. Hold long enough for several indev polls.
|
||||
if ((int32_t)(SDL_GetTicks() - touch_override_until_tick) >= 0) {
|
||||
touch_override_active = false;
|
||||
touch_override.pressed = false;
|
||||
} else {
|
||||
*out_state = touch_override;
|
||||
return;
|
||||
}
|
||||
}
|
||||
*out_state = pointer_state;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,16 @@ bool sdl_input_pop_key(uint32_t* out_key);
|
||||
*/
|
||||
bool sdl_input_has_queued_key(void);
|
||||
|
||||
/**
|
||||
* @brief Web-injected touch override (for headless sim viewer without SDL window).
|
||||
* When active, sdl_pointer_get_touched_points() reports this state instead of
|
||||
* the SDL mouse state. Coordinates are in LVGL logical pixels (e.g. 640x480).
|
||||
* Pass pressed=false to release. Auto-releases after SIM_TOUCH_HOLD_MS unless
|
||||
* refreshed (tap = press, wait, release handled by the web viewer).
|
||||
*/
|
||||
void sdl_input_set_touch_override(int32_t x, int32_t y, bool pressed);
|
||||
void sdl_input_clear_touch_override(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -29,7 +29,28 @@ static Driver* const simulator_drivers[] = {
|
||||
// These devices have no real bus to attach to (SDL has no notion of one), but every non-root
|
||||
// device is still expected to have a parent (see Device::parent) - they're parented to root once
|
||||
// it's available below.
|
||||
static const SdlDisplayConfig sdl_display_config = { 640, 480 };
|
||||
// Display resolution is overridable at runtime via SIM_DISPLAY_W/H env vars
|
||||
// so the sim can match real hardware (e.g. ES3C35P 3.5" = 320x480 portrait,
|
||||
// ES3C28P 2.8" = 320x240 landscape). Defaults to 640x480.
|
||||
static uint16_t sim_display_width(void) {
|
||||
const char* w = getenv("SIM_DISPLAY_W");
|
||||
if (w != nullptr) {
|
||||
long v = atol(w);
|
||||
if (v >= 120 && v <= 2048) return (uint16_t)v;
|
||||
}
|
||||
return 480;
|
||||
}
|
||||
|
||||
static uint16_t sim_display_height(void) {
|
||||
const char* h = getenv("SIM_DISPLAY_H");
|
||||
if (h != nullptr) {
|
||||
long v = atol(h);
|
||||
if (v >= 120 && v <= 2048) return (uint16_t)v;
|
||||
}
|
||||
return 320;
|
||||
}
|
||||
|
||||
static SdlDisplayConfig sdl_display_config = { 480, 320 };
|
||||
static Device sdl_display_device {};
|
||||
static Device sdl_pointer_device {};
|
||||
static Device sdl_keyboard_device {};
|
||||
@@ -81,6 +102,10 @@ static void on_root_started(Device* device, DeviceEvent event, void* context) {
|
||||
return;
|
||||
}
|
||||
|
||||
sdl_display_config.horizontal_resolution = sim_display_width();
|
||||
sdl_display_config.vertical_resolution = sim_display_height();
|
||||
LOG_I(TAG, "Sim display %dx%d (SIM_DISPLAY_W/H override, default 480x320 landscape)",
|
||||
sdl_display_config.horizontal_resolution, sdl_display_config.vertical_resolution);
|
||||
construct_add_start(&sdl_display_device, device, "display0", &sdl_display_config, "tactility,sdl-display");
|
||||
construct_add_start(&sdl_pointer_device, device, "pointer0", nullptr, "tactility,sdl-pointer");
|
||||
construct_add_start(&sdl_keyboard_device, device, "keyboard0", nullptr, "tactility,sdl-keyboard");
|
||||
|
||||
@@ -9,3 +9,7 @@ properties:
|
||||
type: phandle
|
||||
required: true
|
||||
description: "I2S controller device that carries audio data"
|
||||
input-gain-percent:
|
||||
type: int
|
||||
default: 100
|
||||
description: "Extra digital gain multiplier applied by audio_stream on top of the ES8311's own 42dB hardware ADC gain, as an integer percentage (100 = 1.0x / no extra boost). For quiet MEMS mic capsules that are still quiet even at max hardware gain."
|
||||
|
||||
@@ -25,6 +25,14 @@ struct Es8311Config {
|
||||
uint8_t address;
|
||||
/** I2S controller device that carries audio data */
|
||||
struct Device* i2s_device;
|
||||
/**
|
||||
* Extra fixed digital gain multiplier applied by audio_stream on top of the ES8311's
|
||||
* own hardware ADC gain (0..42dB), as an integer percentage (100 = 1.0x / no extra boost).
|
||||
* Small MEMS mic capsules can still sound quiet even near max hardware gain; this is for
|
||||
* boards where 42dB hardware gain alone isn't enough. devicetree has no float property type,
|
||||
* hence the x100 integer encoding.
|
||||
*/
|
||||
uint16_t input_gain_percent;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -31,6 +31,7 @@ struct Es8311Data {
|
||||
bool is_open = false;
|
||||
AudioCodecDirection open_direction = AUDIO_CODEC_DIR_BOTH;
|
||||
esp_codec_dev_sample_info_t open_sample_info = {};
|
||||
float input_gain = 1.0f;
|
||||
};
|
||||
|
||||
#define GET_CONFIG(device) (static_cast<const Es8311Config*>((device)->config))
|
||||
@@ -144,8 +145,8 @@ error_t set_volume(Device* device, AudioCodecDirection direction, float volume_p
|
||||
}
|
||||
|
||||
if (direction == AUDIO_CODEC_DIR_INPUT) {
|
||||
// ES8311 ADC gain range is roughly 0..24 dB; map 0..100% linearly onto it.
|
||||
float db = (volume_percent / 100.0f) * 24.0f;
|
||||
// ES8311 ADC gain supports 0..42dB (0,6,12,18,24,30,36,42) in 6dB steps
|
||||
float db = (volume_percent / 100.0f) * 42.0f;
|
||||
return (esp_codec_dev_set_in_gain(data->codec_device, db) == ESP_CODEC_DEV_OK) ? ERROR_NONE : ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
@@ -172,7 +173,8 @@ error_t get_volume(Device* device, AudioCodecDirection direction, float* volume_
|
||||
if (esp_codec_dev_get_in_gain(data->codec_device, &db) != ESP_CODEC_DEV_OK) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
*volume_percent = (db / 24.0f) * 100.0f;
|
||||
*volume_percent = (db / 42.0f) * 100.0f;
|
||||
if (*volume_percent > 100.0f) *volume_percent = 100.0f;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@@ -235,6 +237,12 @@ error_t get_capabilities(Device* device, AudioCodecDirection* supported_directio
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t get_input_gain_multiplier(Device* device, float* gain) {
|
||||
auto* data = GET_DATA(device);
|
||||
*gain = data->input_gain;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
static const struct AudioCodecApi API = {
|
||||
.open = open,
|
||||
.close = close,
|
||||
@@ -247,7 +255,7 @@ static const struct AudioCodecApi API = {
|
||||
.get_native_sample_rate = get_native_sample_rate,
|
||||
.get_native_channels = get_native_channels,
|
||||
.get_capabilities = get_capabilities,
|
||||
.get_input_gain_multiplier = nullptr,
|
||||
.get_input_gain_multiplier = get_input_gain_multiplier,
|
||||
};
|
||||
|
||||
// endregion
|
||||
@@ -257,6 +265,11 @@ static const struct AudioCodecApi API = {
|
||||
error_t start_device(Device* device) {
|
||||
const auto* config = GET_CONFIG(device);
|
||||
|
||||
if (config->input_gain_percent > 2000) {
|
||||
LOG_E(TAG, "Invalid input_gain_percent %u (must be 0..2000)", config->input_gain_percent);
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
auto* i2c_controller = device_get_parent(device);
|
||||
if (i2c_controller == nullptr || device_get_type(i2c_controller) != &I2C_CONTROLLER_TYPE) {
|
||||
LOG_E(TAG, "Parent is not an I2C controller");
|
||||
@@ -270,6 +283,8 @@ error_t start_device(Device* device) {
|
||||
}
|
||||
|
||||
auto* data = new Es8311Data();
|
||||
data->input_gain = (float) config->input_gain_percent / 100.0f;
|
||||
if (config->input_gain_percent == 0) data->input_gain = 1.0f; // 0 means unset
|
||||
|
||||
data->ctrl_if = audio_codec_adapter_new_i2c_ctrl(i2c_controller, config->address);
|
||||
data->data_if = audio_codec_adapter_new_i2s_data(i2s_controller);
|
||||
|
||||
@@ -32,8 +32,10 @@ constexpr size_t APP_INSTANCE_ID_THREAD_SLOT_INDEX = 1;
|
||||
// Matches TactilityKernel's Thread wrapper's THREAD_PRIORITY_NORMAL.
|
||||
constexpr UBaseType_t APP_TASK_PRIORITY = 4;
|
||||
|
||||
// Used when an app's manifest doesn't request a specific stack depth (0). 8192 bytes' worth.
|
||||
constexpr size_t APP_DEFAULT_STACK_DEPTH = 8192 / sizeof(StackType_t);
|
||||
// Used when an app's manifest doesn't request a specific stack depth (0). 12288 bytes' worth.
|
||||
// Existing window-manager app manifests request at least 2400 words (9600 bytes); use a
|
||||
// conservative default above that baseline so a zero-depth app task cannot exhaust its stack.
|
||||
constexpr size_t APP_DEFAULT_STACK_DEPTH = 12288 / sizeof(StackType_t);
|
||||
|
||||
// Task control blocks must stay in internal RAM; only the stack itself may live in external memory.
|
||||
constexpr MemoryPolicy APP_TASK_TCB_POLICY = { MEMORY_CAPABILITY_INTERNAL, 0, 0 };
|
||||
|
||||
@@ -14,6 +14,15 @@ enum LvglFontSize {
|
||||
FONT_SIZE_LARGE,
|
||||
};
|
||||
|
||||
enum LvglFontScale {
|
||||
FONT_SCALE_SMALL,
|
||||
FONT_SCALE_DEFAULT,
|
||||
FONT_SCALE_LARGE,
|
||||
};
|
||||
|
||||
void lvgl_set_text_font_scale(enum LvglFontScale font_scale);
|
||||
enum LvglFontScale lvgl_get_text_font_scale(void);
|
||||
|
||||
const lv_font_t* lvgl_get_shared_icon_font(void);
|
||||
uint32_t lvgl_get_shared_icon_font_height(void);
|
||||
|
||||
|
||||
@@ -13,8 +13,30 @@ extern const lv_font_t TT_LVGL_LAUNCHER_FONT_ICON_SYMBOL;
|
||||
extern const lv_font_t TT_LVGL_STATUSBAR_FONT_ICON_SYMBOL;
|
||||
extern const lv_font_t TT_LVGL_SHARED_FONT_ICON_SYMBOL;
|
||||
|
||||
static enum LvglFontScale text_font_scale = FONT_SCALE_DEFAULT;
|
||||
|
||||
void lvgl_set_text_font_scale(enum LvglFontScale font_scale) {
|
||||
check(font_scale >= FONT_SCALE_SMALL && font_scale <= FONT_SCALE_LARGE);
|
||||
text_font_scale = font_scale;
|
||||
}
|
||||
|
||||
enum LvglFontScale lvgl_get_text_font_scale(void) {
|
||||
return text_font_scale;
|
||||
}
|
||||
|
||||
static enum LvglFontSize resolve_text_font_size(enum LvglFontSize font_size) {
|
||||
int resolved = (int)font_size + (int)text_font_scale - (int)FONT_SCALE_DEFAULT;
|
||||
if (resolved < FONT_SIZE_SMALL) {
|
||||
return FONT_SIZE_SMALL;
|
||||
}
|
||||
if (resolved > FONT_SIZE_LARGE) {
|
||||
return FONT_SIZE_LARGE;
|
||||
}
|
||||
return (enum LvglFontSize)resolved;
|
||||
}
|
||||
|
||||
uint32_t lvgl_get_text_font_height(enum LvglFontSize font_size) {
|
||||
switch (font_size) {
|
||||
switch (resolve_text_font_size(font_size)) {
|
||||
case FONT_SIZE_SMALL: return TT_LVGL_TEXT_FONT_SMALL_SIZE;
|
||||
case FONT_SIZE_DEFAULT: return TT_LVGL_TEXT_FONT_DEFAULT_SIZE;
|
||||
case FONT_SIZE_LARGE: return TT_LVGL_TEXT_FONT_LARGE_SIZE;
|
||||
@@ -22,7 +44,7 @@ uint32_t lvgl_get_text_font_height(enum LvglFontSize font_size) {
|
||||
}
|
||||
}
|
||||
const lv_font_t* lvgl_get_text_font(enum LvglFontSize font_size) {
|
||||
switch (font_size) {
|
||||
switch (resolve_text_font_size(font_size)) {
|
||||
case FONT_SIZE_SMALL: return &TT_LVGL_TEXT_FONT_SMALL_SYMBOL;
|
||||
case FONT_SIZE_DEFAULT: return &TT_LVGL_TEXT_FONT_DEFAULT_SYMBOL;
|
||||
case FONT_SIZE_LARGE: return &TT_LVGL_TEXT_FONT_LARGE_SYMBOL;
|
||||
|
||||
@@ -26,6 +26,8 @@ const struct ModuleSymbol lvgl_module_symbols[] = {
|
||||
DEFINE_MODULE_SYMBOL(lvgl_module),
|
||||
DEFINE_MODULE_SYMBOL(lvgl_module_configure),
|
||||
// lvgl_fonts
|
||||
DEFINE_MODULE_SYMBOL(lvgl_set_text_font_scale),
|
||||
DEFINE_MODULE_SYMBOL(lvgl_get_text_font_scale),
|
||||
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font),
|
||||
DEFINE_MODULE_SYMBOL(lvgl_get_shared_icon_font_height),
|
||||
DEFINE_MODULE_SYMBOL(lvgl_get_text_font),
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace tt::settings::display {
|
||||
enum class FontSize;
|
||||
}
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -12,6 +16,9 @@ static constexpr auto* PATH_PREFIX = "A:/";
|
||||
|
||||
bool isStarted();
|
||||
|
||||
/** Applies the selected semantic text size to the LVGL theme and future widgets. */
|
||||
void applyFontSize(settings::display::FontSize fontSize);
|
||||
|
||||
void start();
|
||||
|
||||
void stop();
|
||||
|
||||
@@ -18,16 +18,34 @@ enum class ScreensaverType {
|
||||
Mystify,
|
||||
MatrixRain,
|
||||
StackChan,
|
||||
McpScreen,
|
||||
BibleVerse, // Launch the Bible Verse app (if installed)
|
||||
Count // Sentinel for bounds checking - must be last
|
||||
};
|
||||
|
||||
enum class FontSize {
|
||||
Small,
|
||||
Default,
|
||||
Large,
|
||||
Count
|
||||
};
|
||||
|
||||
struct DisplaySettings {
|
||||
Orientation orientation;
|
||||
FontSize fontSize = FontSize::Default;
|
||||
uint8_t gammaCurve;
|
||||
uint8_t backlightDuty;
|
||||
bool backlightTimeoutEnabled;
|
||||
uint32_t backlightTimeoutMs; // 0 = Never
|
||||
ScreensaverType screensaverType = ScreensaverType::BouncingBalls;
|
||||
// Night dim: when enabled and the local hour falls inside
|
||||
// [nightDimStartHour, nightDimEndHour), the screensaver runs at
|
||||
// nightDimDuty instead of backlightDuty. A start == end window
|
||||
// means the whole day.
|
||||
bool nightDimEnabled = false;
|
||||
uint8_t nightDimStartHour = 22;
|
||||
uint8_t nightDimEndHour = 7;
|
||||
uint8_t nightDimDuty = 20;
|
||||
};
|
||||
|
||||
/** 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
|
||||
@@ -6,7 +6,7 @@ namespace tt::settings {
|
||||
|
||||
struct SystemSettings {
|
||||
Language language = Language::en_US;
|
||||
bool timeFormat24h = true;
|
||||
bool timeFormat24h = false;
|
||||
std::string dateFormat = std::string("DD/MM/YYYY"); // MM/DD/YYYY, DD/MM/YYYY, YYYY-MM-DD, YYYY/MM/DD
|
||||
};
|
||||
|
||||
|
||||
@@ -7,5 +7,6 @@ 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
|
||||
|
||||
@@ -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
@@ -5,6 +5,8 @@
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
#include <Tactility/Timer.h>
|
||||
|
||||
#include <app/instance.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
@@ -29,9 +31,15 @@ class DisplayIdleService final : public Service {
|
||||
// Active screensaver instance
|
||||
std::unique_ptr<Screensaver> screensaver;
|
||||
|
||||
// Screensaver auto-off: turn off backlight after 5 minutes of screensaver
|
||||
// App launched as screensaver (Bible Verse): instance id, 0 when none.
|
||||
// A separate flag (not just the id) tracks intent, so a user-closed app
|
||||
// doesn't look like an active screensaver and vice versa.
|
||||
AppInstanceId screensaverAppInstanceId = 0;
|
||||
bool screensaverAppActive = false;
|
||||
|
||||
// Screensaver auto-off: turn off backlight after 30 minutes of screensaver
|
||||
static constexpr uint32_t TICK_INTERVAL_MS = 50;
|
||||
static constexpr uint32_t SCREENSAVER_AUTO_OFF_MS = 5 * 60 * 1000; // 5 minutes
|
||||
static constexpr uint32_t SCREENSAVER_AUTO_OFF_MS = 30 * 60 * 1000; // 30 minutes
|
||||
static constexpr int SCREENSAVER_AUTO_OFF_TICKS = SCREENSAVER_AUTO_OFF_MS / TICK_INTERVAL_MS;
|
||||
int screensaverActiveCounter = 0;
|
||||
bool backlightOff = false;
|
||||
@@ -63,6 +71,7 @@ public:
|
||||
* arbitrary threads while the timer is running.
|
||||
*/
|
||||
void stopScreensaver();
|
||||
void startMcpScreensaver();
|
||||
|
||||
/**
|
||||
* Check if the screensaver is currently active.
|
||||
|
||||
@@ -81,6 +81,12 @@ private:
|
||||
static error_t handleApiAppsInstall(struct HttpServerRequest* request, void* user_ctx);
|
||||
static error_t handleApiWifi(struct HttpServerRequest* request, void* user_ctx);
|
||||
static error_t handleApiScreenshot(struct HttpServerRequest* request, void* user_ctx);
|
||||
static error_t handleApiSimTouch(struct HttpServerRequest* request, void* user_ctx);
|
||||
static error_t handleSimViewer(struct HttpServerRequest* request, void* user_ctx);
|
||||
#ifdef ESP_PLATFORM
|
||||
static error_t handleApiMcp(struct HttpServerRequest* request, void* user_ctx);
|
||||
static error_t handleApiScreenRaw(struct HttpServerRequest* request, void* user_ctx);
|
||||
#endif
|
||||
|
||||
// Dynamic asset serving
|
||||
static error_t handleAssets(struct HttpServerRequest* request, void* user_ctx);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -334,7 +339,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.apphub",
|
||||
.name = "App Hub",
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = {APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain)}
|
||||
.location = {APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain)},
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::apphub
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -245,7 +245,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.btmanage",
|
||||
.name = "Bluetooth",
|
||||
.category = APP_CATEGORY_SETTINGS,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::btmanage
|
||||
|
||||
@@ -228,7 +228,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.chat",
|
||||
.name = "Chat",
|
||||
.category = APP_CATEGORY_USER,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::chat
|
||||
|
||||
@@ -230,7 +230,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.development",
|
||||
.name = "Development",
|
||||
.category = APP_CATEGORY_SETTINGS,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // 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>
|
||||
@@ -41,6 +42,10 @@ struct Context {
|
||||
lv_obj_t* timeoutSwitch = nullptr;
|
||||
lv_obj_t* timeoutDropdown = nullptr;
|
||||
lv_obj_t* screensaverDropdown = nullptr;
|
||||
lv_obj_t* nightDimSwitch = nullptr;
|
||||
lv_obj_t* nightDimStartDropdown = nullptr;
|
||||
lv_obj_t* nightDimEndDropdown = nullptr;
|
||||
lv_obj_t* nightDimDutySlider = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,6 +95,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));
|
||||
@@ -115,8 +135,8 @@ void onTimeoutChanged(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 idx = lv_dropdown_get_selected(dropdown);
|
||||
// Map dropdown index to ms: 0=15s,1=30s,2=1m,3=2m,4=5m,5=Never
|
||||
static const uint32_t values_ms[] = {15000, 30000, 60000, 120000, 300000, 0};
|
||||
// Map dropdown index to ms: 0=15s,1=30s,2=1m,3=2m,4=5m,5=15m,6=30m,7=Never
|
||||
static const uint32_t values_ms[] = {15000, 30000, 60000, 120000, 300000, 900000, 1800000, 0};
|
||||
if (idx < (sizeof(values_ms)/sizeof(values_ms[0]))) {
|
||||
ctx->displaySettings.backlightTimeoutMs = values_ms[idx];
|
||||
ctx->displaySettingsUpdated = true;
|
||||
@@ -138,6 +158,82 @@ void onScreensaverChanged(lv_event_t* event) {
|
||||
}
|
||||
}
|
||||
|
||||
static void setNightDimControlsEnabled(Context* ctx, bool enabled) {
|
||||
if (ctx->nightDimStartDropdown != nullptr) {
|
||||
if (enabled) {
|
||||
lv_obj_clear_state(ctx->nightDimStartDropdown, LV_STATE_DISABLED);
|
||||
} else {
|
||||
lv_obj_add_state(ctx->nightDimStartDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
if (ctx->nightDimEndDropdown != nullptr) {
|
||||
if (enabled) {
|
||||
lv_obj_clear_state(ctx->nightDimEndDropdown, LV_STATE_DISABLED);
|
||||
} else {
|
||||
lv_obj_add_state(ctx->nightDimEndDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
if (ctx->nightDimDutySlider != nullptr) {
|
||||
if (enabled) {
|
||||
lv_obj_clear_state(ctx->nightDimDutySlider, LV_STATE_DISABLED);
|
||||
} else {
|
||||
lv_obj_add_state(ctx->nightDimDutySlider, LV_STATE_DISABLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const char* hourOptions() {
|
||||
// 00..23, one per line
|
||||
static const char* options =
|
||||
"00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n"
|
||||
"12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
|
||||
return options;
|
||||
}
|
||||
|
||||
void onNightDimSwitch(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));
|
||||
bool enabled = lv_obj_has_state(sw, LV_STATE_CHECKED);
|
||||
ctx->displaySettings.nightDimEnabled = enabled;
|
||||
ctx->displaySettingsUpdated = true;
|
||||
setNightDimControlsEnabled(ctx, enabled);
|
||||
}
|
||||
|
||||
void onNightDimStartChanged(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 idx = lv_dropdown_get_selected(dropdown);
|
||||
if (idx > 23) {
|
||||
return;
|
||||
}
|
||||
ctx->displaySettings.nightDimStartHour = static_cast<uint8_t>(idx);
|
||||
ctx->displaySettingsUpdated = true;
|
||||
}
|
||||
|
||||
void onNightDimEndChanged(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 idx = lv_dropdown_get_selected(dropdown);
|
||||
if (idx > 23) {
|
||||
return;
|
||||
}
|
||||
ctx->displaySettings.nightDimEndHour = static_cast<uint8_t>(idx);
|
||||
ctx->displaySettingsUpdated = true;
|
||||
}
|
||||
|
||||
void onNightDimDutyChanged(lv_event_t* event) {
|
||||
auto* ctx = static_cast<Context*>(lv_event_get_user_data(event));
|
||||
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
int32_t value = lv_slider_get_value(slider);
|
||||
if (value < 0) {
|
||||
value = 0;
|
||||
} else if (value > 255) {
|
||||
value = 255;
|
||||
}
|
||||
ctx->displaySettings.nightDimDuty = static_cast<uint8_t>(value);
|
||||
ctx->displaySettingsUpdated = true;
|
||||
}
|
||||
|
||||
void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
auto* ctx = static_cast<Context*>(userData);
|
||||
|
||||
@@ -208,6 +304,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
|
||||
@@ -240,7 +353,7 @@ void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
lv_obj_align(timeout_value_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
ctx->timeoutDropdown = lv_dropdown_create(timeout_select_wrapper);
|
||||
lv_dropdown_set_options(ctx->timeoutDropdown, "15 seconds\n30 seconds\n1 minute\n2 minutes\n5 minutes\nNever");
|
||||
lv_dropdown_set_options(ctx->timeoutDropdown, "15 seconds\n30 seconds\n1 minute\n2 minutes\n5 minutes\n15 minutes\n30 minutes\nNever");
|
||||
lv_obj_align(ctx->timeoutDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(ctx->timeoutDropdown, onTimeoutChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
// Initialize dropdown selection from settings
|
||||
@@ -255,8 +368,12 @@ void createWidgets(lv_obj_t* parent, void* userData) {
|
||||
idx = 3;
|
||||
else if (ms == 300000)
|
||||
idx = 4;
|
||||
else if (ms == 0)
|
||||
else if (ms == 900000)
|
||||
idx = 5;
|
||||
else if (ms == 1800000)
|
||||
idx = 6;
|
||||
else if (ms == 0)
|
||||
idx = 7;
|
||||
lv_dropdown_set_selected(ctx->timeoutDropdown, idx);
|
||||
if (!ctx->displaySettings.backlightTimeoutEnabled) {
|
||||
lv_obj_add_state(ctx->timeoutDropdown, LV_STATE_DISABLED);
|
||||
@@ -274,13 +391,78 @@ 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\nBible Verse");
|
||||
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));
|
||||
if (!ctx->displaySettings.backlightTimeoutEnabled) {
|
||||
lv_obj_add_state(ctx->screensaverDropdown, LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
// Night dim: dim the backlight while the screensaver is up, during a time window
|
||||
auto* night_dim_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(night_dim_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(night_dim_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(night_dim_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* night_dim_label = lv_label_create(night_dim_wrapper);
|
||||
lv_label_set_text(night_dim_label, "Night dim");
|
||||
lv_obj_align(night_dim_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
ctx->nightDimSwitch = lv_switch_create(night_dim_wrapper);
|
||||
if (ctx->displaySettings.nightDimEnabled) {
|
||||
lv_obj_add_state(ctx->nightDimSwitch, LV_STATE_CHECKED);
|
||||
}
|
||||
lv_obj_align(ctx->nightDimSwitch, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(ctx->nightDimSwitch, onNightDimSwitch, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
|
||||
auto* night_dim_start_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(night_dim_start_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(night_dim_start_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(night_dim_start_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* night_dim_start_label = lv_label_create(night_dim_start_wrapper);
|
||||
lv_label_set_text(night_dim_start_label, "Dim from");
|
||||
lv_obj_align(night_dim_start_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
ctx->nightDimStartDropdown = lv_dropdown_create(night_dim_start_wrapper);
|
||||
lv_dropdown_set_options(ctx->nightDimStartDropdown, hourOptions());
|
||||
lv_obj_align(ctx->nightDimStartDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(ctx->nightDimStartDropdown, onNightDimStartChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
lv_dropdown_set_selected(ctx->nightDimStartDropdown, ctx->displaySettings.nightDimStartHour > 23 ? 0 : ctx->displaySettings.nightDimStartHour);
|
||||
|
||||
auto* night_dim_end_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(night_dim_end_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(night_dim_end_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(night_dim_end_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* night_dim_end_label = lv_label_create(night_dim_end_wrapper);
|
||||
lv_label_set_text(night_dim_end_label, "Dim until");
|
||||
lv_obj_align(night_dim_end_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
ctx->nightDimEndDropdown = lv_dropdown_create(night_dim_end_wrapper);
|
||||
lv_dropdown_set_options(ctx->nightDimEndDropdown, hourOptions());
|
||||
lv_obj_align(ctx->nightDimEndDropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(ctx->nightDimEndDropdown, onNightDimEndChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
lv_dropdown_set_selected(ctx->nightDimEndDropdown, ctx->displaySettings.nightDimEndHour > 23 ? 0 : ctx->displaySettings.nightDimEndHour);
|
||||
|
||||
auto* night_dim_duty_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(night_dim_duty_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(night_dim_duty_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(night_dim_duty_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* night_dim_duty_label = lv_label_create(night_dim_duty_wrapper);
|
||||
lv_label_set_text(night_dim_duty_label, "Dim brightness");
|
||||
lv_obj_align(night_dim_duty_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
ctx->nightDimDutySlider = lv_slider_create(night_dim_duty_wrapper);
|
||||
lv_obj_set_width(ctx->nightDimDutySlider, LV_PCT(50));
|
||||
lv_obj_align(ctx->nightDimDutySlider, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_slider_set_range(ctx->nightDimDutySlider, 0, 255);
|
||||
lv_slider_set_value(ctx->nightDimDutySlider, ctx->displaySettings.nightDimDuty, LV_ANIM_OFF);
|
||||
lv_obj_add_event_cb(ctx->nightDimDutySlider, onNightDimDutyChanged, LV_EVENT_VALUE_CHANGED, ctx);
|
||||
|
||||
setNightDimControlsEnabled(ctx, ctx->displaySettings.nightDimEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,4 +26,12 @@ bool isSupportedTextFile(const std::string& filename) {
|
||||
filename_lower.ends_with(".properties");
|
||||
}
|
||||
|
||||
bool isSupportedAudioFile(const std::string& filename) {
|
||||
std::string filename_lower = string::lowercase(filename);
|
||||
return filename_lower.ends_with(".mp3") ||
|
||||
filename_lower.ends_with(".wav") ||
|
||||
filename_lower.ends_with(".ogg") ||
|
||||
filename_lower.ends_with(".flac");
|
||||
}
|
||||
|
||||
} // namespace tt::app::filebrowser
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <app/event.h>
|
||||
#include <app/execute.h>
|
||||
#include <app/install.h>
|
||||
#include <app/start.h>
|
||||
#include <app/stream.h>
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
@@ -204,6 +205,15 @@ void View::viewFile(const std::string& path, const std::string& filename) {
|
||||
// Remove forward slash, because we need a relative path
|
||||
notes::start(file_path.substr(1));
|
||||
}
|
||||
} else if (isSupportedAudioFile(filename)) {
|
||||
// External MP3 player reads argv as key=value pairs (see
|
||||
// CurrentAppCompat tt_app_start_with_bundle): file=<path>
|
||||
std::string file_arg = "file=" + file_path;
|
||||
const char* argv[] = { file_arg.c_str() };
|
||||
uint32_t instance_id = 0;
|
||||
if (app_start("one.tactility.mp3player", 1, argv, &instance_id) != ERROR_NONE) {
|
||||
LOG_W(TAG, "Failed to start MP3 player for %s", file_path.c_str());
|
||||
}
|
||||
} else if (isExecutablePath(file_path)) {
|
||||
runFile(file_path);
|
||||
} else {
|
||||
|
||||
@@ -426,7 +426,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.i2cscanner",
|
||||
.name = "I2C Scanner",
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
uint32_t start() {
|
||||
|
||||
@@ -182,7 +182,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.localesettings",
|
||||
.name = "Region & Language",
|
||||
.category = APP_CATEGORY_SETTINGS,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::localesettings
|
||||
|
||||
@@ -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 = APP_MANIFEST_FLAG_HIDDEN, .stack = { .depth = 8192, .desired_memory_capability = 0 } };
|
||||
}
|
||||
#endif
|
||||
@@ -276,7 +276,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.notes",
|
||||
.name = "Notes",
|
||||
.category = APP_CATEGORY_USER,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::notes
|
||||
|
||||
@@ -278,7 +278,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.power",
|
||||
.name = "Power",
|
||||
.category = APP_CATEGORY_SETTINGS,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -290,7 +290,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.screenshot",
|
||||
.name = "Screenshot",
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -457,7 +457,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.systeminfo",
|
||||
.name = "System Info",
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -215,7 +215,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.timedatesettings",
|
||||
.name = "Time & Date",
|
||||
.category = APP_CATEGORY_SETTINGS,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
} // namespace tt::app::timedatesettings
|
||||
|
||||
@@ -424,7 +424,8 @@ extern const ::AppManifest manifest = {
|
||||
.id = "tactility.webserversettings",
|
||||
.name = "Web Server",
|
||||
.category = APP_CATEGORY_SYSTEM,
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) }
|
||||
.location = { APP_LOCATION_MEMORY, reinterpret_cast<void*>(appMain) },
|
||||
.flags = APP_MANIFEST_FLAG_HIDDEN
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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,15 @@
|
||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/mcp/McpSystem.h>
|
||||
|
||||
#include <app/manager.h>
|
||||
#include <app/start.h>
|
||||
|
||||
#include "BouncingBallsScreensaver.h"
|
||||
#include "MatrixRainScreensaver.h"
|
||||
#include "MystifyScreensaver.h"
|
||||
#include "McpScreensaver.h"
|
||||
#include "Screensaver.h"
|
||||
#include "StackChanScreensaver.h"
|
||||
|
||||
@@ -59,6 +64,34 @@ static bool hasDisplayWithBacklight() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effective backlight duty for the screensaver: the dimmed night level when
|
||||
* night dim is enabled and the local hour is inside the configured window,
|
||||
* otherwise the regular duty. A start == end window covers the whole day.
|
||||
*/
|
||||
static uint8_t screensaverBacklightDuty(const settings::display::DisplaySettings& displaySettings) {
|
||||
if (!displaySettings.nightDimEnabled) {
|
||||
return displaySettings.backlightDuty;
|
||||
}
|
||||
const std::time_t now = std::time(nullptr);
|
||||
std::tm local_time {};
|
||||
if (localtime_r(&now, &local_time) == nullptr || local_time.tm_year < 125) {
|
||||
return displaySettings.backlightDuty;
|
||||
}
|
||||
const uint8_t hour = static_cast<uint8_t>(local_time.tm_hour);
|
||||
const uint8_t start = displaySettings.nightDimStartHour;
|
||||
const uint8_t end = displaySettings.nightDimEndHour;
|
||||
bool in_window;
|
||||
if (start == end) {
|
||||
in_window = true;
|
||||
} else if (start < end) {
|
||||
in_window = hour >= start && hour < end;
|
||||
} else {
|
||||
in_window = hour >= start || hour < end;
|
||||
}
|
||||
return in_window ? displaySettings.nightDimDuty : displaySettings.backlightDuty;
|
||||
}
|
||||
|
||||
void DisplayIdleService::stopScreensaver() {
|
||||
if (!lvgl_try_lock(100)) {
|
||||
// Lock failed - keep flag set to retry on next tick
|
||||
@@ -77,6 +110,17 @@ void DisplayIdleService::stopScreensaver() {
|
||||
screensaverOverlay = nullptr;
|
||||
}
|
||||
lvgl_unlock();
|
||||
|
||||
// Stop an app launched as screensaver (e.g. Bible Verse): on wake the
|
||||
// device returns to the launcher. Stopping is safe when the user already
|
||||
// closed it (unknown ids report STOPPED / stop is a no-op for them).
|
||||
if (screensaverAppActive) {
|
||||
screensaverAppActive = false;
|
||||
if (screensaverAppInstanceId != 0) {
|
||||
app_manager_stop(screensaverAppInstanceId);
|
||||
screensaverAppInstanceId = 0;
|
||||
}
|
||||
}
|
||||
stopScreensaverRequested.store(false, std::memory_order_relaxed);
|
||||
|
||||
// Reset auto-off state
|
||||
@@ -92,14 +136,31 @@ void DisplayIdleService::stopScreensaver() {
|
||||
}
|
||||
|
||||
void DisplayIdleService::activateScreensaver() {
|
||||
lv_obj_t* top = lv_layer_top();
|
||||
|
||||
if (screensaverOverlay != nullptr) return;
|
||||
|
||||
// Reset auto-off counter when starting screensaver
|
||||
screensaverActiveCounter = 0;
|
||||
backlightOff = false;
|
||||
|
||||
// Bible Verse screensaver: launch the app instead of drawing an overlay.
|
||||
// Falls back to a plain black overlay when the app is not installed.
|
||||
if (cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::BibleVerse) {
|
||||
constexpr auto* BIBLE_VERSE_APP_ID = "one.tactility.bibleverse";
|
||||
AppManifest manifest {};
|
||||
AppInstanceId instance_id = 0;
|
||||
if (app_manager_find_manifest(BIBLE_VERSE_APP_ID, &manifest) == ERROR_NONE
|
||||
&& app_start(BIBLE_VERSE_APP_ID, 0, nullptr, &instance_id) == ERROR_NONE) {
|
||||
LOG_I(TAG, "Bible Verse screensaver: launched instance %u", (unsigned)instance_id);
|
||||
screensaverAppInstanceId = instance_id;
|
||||
screensaverAppActive = true;
|
||||
setBacklightBrightness(screensaverBacklightDuty(cachedDisplaySettings));
|
||||
return;
|
||||
}
|
||||
LOG_W(TAG, "Bible Verse app not installed, falling back to black screen");
|
||||
}
|
||||
|
||||
lv_obj_t* top = lv_layer_top();
|
||||
|
||||
if (screensaverOverlay != nullptr) return;
|
||||
|
||||
lv_coord_t screenW = lv_display_get_horizontal_resolution(nullptr);
|
||||
lv_coord_t screenH = lv_display_get_vertical_resolution(nullptr);
|
||||
|
||||
@@ -127,6 +188,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
|
||||
@@ -137,6 +201,8 @@ void DisplayIdleService::activateScreensaver() {
|
||||
if (screensaver) {
|
||||
screensaver->start(screensaverOverlay, screenW, screenH);
|
||||
}
|
||||
|
||||
setBacklightBrightness(screensaverBacklightDuty(cachedDisplaySettings));
|
||||
}
|
||||
|
||||
void DisplayIdleService::updateScreensaver() {
|
||||
@@ -166,8 +232,8 @@ void DisplayIdleService::tick() {
|
||||
inactive_ms = lv_display_get_inactive_time(nullptr);
|
||||
|
||||
// Only update if not stopping (prevents lag on touch)
|
||||
if (displayDimmed && screensaverOverlay && !stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
// Check if screensaver should auto-off after 5 minutes
|
||||
if (displayDimmed && (screensaverOverlay || screensaverAppActive) && !stopScreensaverRequested.load(std::memory_order_acquire)) {
|
||||
// Check if screensaver should auto-off after 30 minutes
|
||||
if (!backlightOff) {
|
||||
screensaverActiveCounter++;
|
||||
if (screensaverActiveCounter >= SCREENSAVER_AUTO_OFF_TICKS) {
|
||||
@@ -176,6 +242,13 @@ void DisplayIdleService::tick() {
|
||||
screensaver->stop();
|
||||
screensaver.reset();
|
||||
}
|
||||
if (screensaverAppActive) {
|
||||
screensaverAppActive = false;
|
||||
if (screensaverAppInstanceId != 0) {
|
||||
app_manager_stop(screensaverAppInstanceId);
|
||||
screensaverAppInstanceId = 0;
|
||||
}
|
||||
}
|
||||
setBacklightBrightness(0);
|
||||
backlightOff = true;
|
||||
} else {
|
||||
@@ -211,6 +284,10 @@ void DisplayIdleService::tick() {
|
||||
}
|
||||
displayDimmed = true;
|
||||
} else if (displayDimmed && (inactive_ms < kWakeActivityThresholdMs)) {
|
||||
// The Bible Verse app keeps LVGL timers running (minute-advance),
|
||||
// so plain inactivity never drops while it is up. Taps still
|
||||
// register as activity: stop the verse app to return to launcher.
|
||||
// If the user already closed it, stopScreensaver() is a safe no-op.
|
||||
stopScreensaver();
|
||||
}
|
||||
}
|
||||
@@ -247,6 +324,13 @@ void DisplayIdleService::onStop(ServiceContext& service) {
|
||||
LOG_W(TAG, "Failed to stop screensaver during shutdown - potential resource leak");
|
||||
}
|
||||
}
|
||||
if (screensaverAppActive) {
|
||||
screensaverAppActive = false;
|
||||
if (screensaverAppInstanceId != 0) {
|
||||
app_manager_stop(screensaverAppInstanceId);
|
||||
screensaverAppInstanceId = 0;
|
||||
}
|
||||
}
|
||||
screensaver.reset();
|
||||
}
|
||||
|
||||
@@ -259,8 +343,19 @@ void DisplayIdleService::startScreensaver() {
|
||||
// Note: This is safe because we hold the LVGL lock which serializes with tick()
|
||||
cachedDisplaySettings = settings::display::loadOrGetDefault();
|
||||
|
||||
// The Bible Verse path launches an app task (not an overlay), which must
|
||||
// not run under the LVGL lock: drop it before activating.
|
||||
const bool launches_app =
|
||||
cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::BibleVerse;
|
||||
if (launches_app) {
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
activateScreensaver();
|
||||
lvgl_unlock();
|
||||
|
||||
if (!launches_app) {
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
// Turn off backlight for "None" screensaver
|
||||
if (hasDisplayWithBacklight() && cachedDisplaySettings.screensaverType == settings::display::ScreensaverType::None) {
|
||||
@@ -270,7 +365,50 @@ void DisplayIdleService::startScreensaver() {
|
||||
}
|
||||
|
||||
bool DisplayIdleService::isScreensaverActive() const {
|
||||
return screensaverOverlay != nullptr;
|
||||
return screensaverOverlay != nullptr || screensaverAppActive;
|
||||
}
|
||||
|
||||
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 : screensaverBacklightDuty(cachedDisplaySettings));
|
||||
|
||||
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() {
|
||||
|
||||
@@ -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
@@ -26,12 +26,26 @@
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
#include <lv_screenshot.h>
|
||||
// lodepng.h enables its C++ overloads (std::vector/std::string) when compiled
|
||||
// as C++; save_png.c compiles it as C. WebServerService.cpp is C++, so opt out
|
||||
// of the C++ wrapper to get the same C API save_png.c uses.
|
||||
#define LODEPNG_NO_COMPILE_CPP
|
||||
#include "src/libs/lodepng/lodepng.h"
|
||||
#endif
|
||||
|
||||
#include "app/install.h"
|
||||
#include "app/manager.h"
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
// Simulator touch injection backend (Devices/simulator sdl-pointer driver).
|
||||
// Declared extern "C" here instead of including the device header: Tactility
|
||||
// must not depend upward on a device implementation.
|
||||
extern "C" void sdl_input_set_touch_override(int32_t x, int32_t y, bool pressed);
|
||||
#endif
|
||||
|
||||
#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 +227,11 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
#ifdef ESP_PLATFORM
|
||||
serverEnabled = g_cachedSettings.webServerEnabled || settings::mcp::loadOrGetDefault().mcpEnabled;
|
||||
#else
|
||||
serverEnabled = g_cachedSettings.webServerEnabled;
|
||||
#endif
|
||||
}
|
||||
// Subscribe to settings change events to refresh cache
|
||||
settingsEventSubscription = pubsub->subscribe([](WebServerEvent event) {
|
||||
@@ -222,6 +240,14 @@ bool WebServerService::onStart(ServiceContext& service) {
|
||||
lock.lock();
|
||||
g_cachedSettings = settings::webserver::loadOrGetDefault();
|
||||
g_settingsCached = true;
|
||||
#ifdef ESP_PLATFORM
|
||||
const bool enabled = g_cachedSettings.webServerEnabled || settings::mcp::loadOrGetDefault().mcpEnabled;
|
||||
#else
|
||||
const bool enabled = g_cachedSettings.webServerEnabled;
|
||||
#endif
|
||||
if (g_webServerInstance.load() != nullptr) {
|
||||
g_webServerInstance.load()->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -481,6 +507,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/*",
|
||||
@@ -500,6 +541,23 @@ bool WebServerService::startServer() {
|
||||
.callback = handleApiPut,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
#ifndef ESP_PLATFORM
|
||||
// Simulator viewer aliases: the /sim page resolves api/ against its
|
||||
// own directory (/sim/api/...), so mirror the viewer-needed handlers
|
||||
// here. Same callbacks, auth enforced inside each handler.
|
||||
{
|
||||
.uri = "/sim/api/*",
|
||||
.method = HTTP_METHOD_GET,
|
||||
.callback = handleApiGet,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
{
|
||||
.uri = "/sim/api/*",
|
||||
.method = HTTP_METHOD_POST,
|
||||
.callback = handleApiPost,
|
||||
.user_ctx = ctx
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.uri = "/*", // Catch-all for dynamic assets
|
||||
.method = HTTP_METHOD_GET,
|
||||
@@ -528,6 +586,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 +608,9 @@ void WebServerService::stopServer() {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
mcp::stopVideoStreamServer();
|
||||
#endif
|
||||
http_server_free(httpServer);
|
||||
httpServer = nullptr;
|
||||
|
||||
@@ -1008,9 +1075,17 @@ error_t WebServerService::handleAdminPost(HttpServerRequest* request, void* user
|
||||
|
||||
// API GET dispatcher - returns JSON system information
|
||||
// Note: /api/sysinfo is intentionally public for monitoring use cases
|
||||
// The /sim/api/* alias routes (sim viewer page) strip the /sim prefix here
|
||||
// so both /api/... and /sim/api/... share one dispatch table.
|
||||
static const char* api_path_suffix(HttpServerRequest* request, char* uri, size_t uri_size) {
|
||||
http_server_request_get_uri(request, uri, uri_size);
|
||||
if (strncmp(uri, "/sim/api/", 9) == 0) return uri + 4; // -> /api/...
|
||||
return uri;
|
||||
}
|
||||
|
||||
error_t WebServerService::handleApiGet(HttpServerRequest* request, void* user_ctx) {
|
||||
char uri[256];
|
||||
http_server_request_get_uri(request, uri, sizeof(uri));
|
||||
char uri_buf[256];
|
||||
const char* uri = api_path_suffix(request, uri_buf, sizeof(uri_buf));
|
||||
|
||||
// Public endpoint: sysinfo (basic device info for monitoring)
|
||||
if (strncmp(uri, "/api/sysinfo", 12) == 0) {
|
||||
@@ -1028,6 +1103,9 @@ error_t WebServerService::handleApiGet(HttpServerRequest* request, void* user_ct
|
||||
if (strncmp(uri, "/api/apps", 9) == 0) {
|
||||
return handleApiApps(request, user_ctx);
|
||||
}
|
||||
if (strncmp(uri, "/api/sim/touch", 14) == 0) {
|
||||
return handleApiSimTouch(request, user_ctx);
|
||||
}
|
||||
if (strncmp(uri, "/api/wifi", 9) == 0) {
|
||||
return handleApiWifi(request, user_ctx);
|
||||
}
|
||||
@@ -1048,11 +1126,14 @@ error_t WebServerService::handleApiPost(HttpServerRequest* request, void* user_c
|
||||
return authResult;
|
||||
}
|
||||
|
||||
char uri[256];
|
||||
http_server_request_get_uri(request, uri, sizeof(uri));
|
||||
char uri_buf[256];
|
||||
const char* uri = api_path_suffix(request, uri_buf, sizeof(uri_buf));
|
||||
if (strncmp(uri, "/api/apps/run", 13) == 0) {
|
||||
return handleApiAppsRun(request, user_ctx);
|
||||
}
|
||||
if (strncmp(uri, "/api/sim/touch", 14) == 0) {
|
||||
return handleApiSimTouch(request, user_ctx);
|
||||
}
|
||||
if (strncmp(uri, "/api/apps/uninstall", 19) == 0) {
|
||||
return handleApiAppsUninstall(request, user_ctx);
|
||||
}
|
||||
@@ -1488,11 +1569,76 @@ error_t WebServerService::handleApiWifi(HttpServerRequest* request, void*) {
|
||||
}
|
||||
|
||||
// GET /api/screenshot - Capture and return screenshot as PNG
|
||||
// Screenshots are saved to SD card root (if available) or /data with incrementing numbers
|
||||
// Fast path (no query or ?fast=1): snapshot LVGL to a memory buffer, PNG-encode
|
||||
// to memory with lodepng, stream directly. No filesystem touch, no slot scan.
|
||||
// Legacy path (?fast=0): previous save-to-webscreenshotN.png behavior.
|
||||
error_t WebServerService::handleApiScreenshot(HttpServerRequest* request, void*) {
|
||||
LOG_I(TAG, "GET /api/screenshot");
|
||||
|
||||
#if TT_FEATURE_SCREENSHOT_ENABLED
|
||||
std::string sfast;
|
||||
bool fast = true;
|
||||
if (getQueryParam(request, "fast", sfast)) fast = (sfast != "0");
|
||||
|
||||
if (fast) {
|
||||
// Hold the LVGL lock across snapshot + encode: both must see a stable
|
||||
// framebuffer. lv_snapshot_take renders synchronously under the lock.
|
||||
if (!lvgl_try_lock(pdMS_TO_TICKS(500))) {
|
||||
LOG_E(TAG, "Could not acquire LVGL lock within 500ms");
|
||||
http_server_request_send_error(request, 500, "could not acquire LVGL lock");
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
lv_draw_buf_t* snapshot = lv_snapshot_take(lv_scr_act(), LV_COLOR_FORMAT_RGB888);
|
||||
if (snapshot == nullptr) {
|
||||
lvgl_unlock();
|
||||
LOG_E(TAG, "lv_snapshot_take failed");
|
||||
http_server_request_send_error(request, 500, "snapshot failed");
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
// lodepng wants RGB triplets; snapshot is RGB888 = 3 bytes/px already,
|
||||
// but in BGR order on little-endian — swap R and B in place.
|
||||
uint32_t px_count = snapshot->header.w * snapshot->header.h;
|
||||
uint8_t* px = snapshot->data;
|
||||
for (uint32_t i = 0; i < px_count; i++) {
|
||||
uint8_t tmp = px[0];
|
||||
px[0] = px[2];
|
||||
px[2] = tmp;
|
||||
px += 3;
|
||||
}
|
||||
unsigned char* png = nullptr;
|
||||
size_t png_size = 0;
|
||||
unsigned enc_err = lodepng_encode24(&png, &png_size, snapshot->data,
|
||||
snapshot->header.w, snapshot->header.h);
|
||||
uint32_t w = snapshot->header.w, h = snapshot->header.h;
|
||||
lv_draw_buf_destroy(snapshot);
|
||||
lvgl_unlock();
|
||||
if (enc_err != 0 || png == nullptr) {
|
||||
LOG_E(TAG, "lodepng_encode24 failed: %u", enc_err);
|
||||
http_server_request_send_error(request, 500, "png encode failed");
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
LOG_I(TAG, "Screenshot %lux%lu %d bytes (memory path)", (unsigned long)w, (unsigned long)h, (int)png_size);
|
||||
http_server_request_set_content_type(request, "image/png");
|
||||
error_t result = ERROR_NONE;
|
||||
if (http_server_request_send_chunk_start(request) != ERROR_NONE) {
|
||||
result = ERROR_UNDEFINED;
|
||||
} else {
|
||||
size_t sent = 0;
|
||||
while (sent < png_size) {
|
||||
size_t n = png_size - sent > 8192 ? 8192 : png_size - sent;
|
||||
if (http_server_request_send_chunk(request, png + sent, n) != ERROR_NONE) {
|
||||
result = ERROR_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
sent += n;
|
||||
}
|
||||
http_server_request_send_chunk_end(request);
|
||||
}
|
||||
free(png);
|
||||
LOG_I(TAG, "[200] /api/screenshot fast %d bytes", (int)png_size);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Determine save location: prefer SD card root if mounted, otherwise /data
|
||||
std::string save_path = getDataPath();
|
||||
|
||||
@@ -1734,6 +1880,83 @@ error_t WebServerService::handleReboot(HttpServerRequest* request, void*) {
|
||||
return ERROR_NONE; // Unreachable on ESP_PLATFORM, but satisfies function signature
|
||||
}
|
||||
|
||||
// POST /api/sim/touch?x=123&y=456[&down=0|1] - inject touch into simulator.
|
||||
// Simulator-only: on ESP32 there is no sdl-pointer backend, so this 404s.
|
||||
// x/y are LVGL logical pixels (see viewer footer for current WxH).
|
||||
// down=1 (default) presses and auto-releases after ~1.5s (long enough for LVGL
|
||||
// indev polls to register a click); down=0 releases immediately.
|
||||
error_t WebServerService::handleApiSimTouch(HttpServerRequest* request, void*) {
|
||||
#ifdef ESP_PLATFORM
|
||||
http_server_request_send_error(request, 404, "simulator only");
|
||||
return ERROR_UNDEFINED;
|
||||
#else
|
||||
std::string sx, sy, sdown;
|
||||
int x = -1, y = -1;
|
||||
if (getQueryParam(request, "x", sx)) x = atoi(sx.c_str());
|
||||
if (getQueryParam(request, "y", sy)) y = atoi(sy.c_str());
|
||||
bool down = true;
|
||||
if (getQueryParam(request, "down", sdown)) down = (sdown != "0");
|
||||
if (x < 0 || y < 0 || x > 4096 || y > 4096) {
|
||||
http_server_request_send_error(request, 400, "x and y params required (0..4096)");
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
sdl_input_set_touch_override((int32_t)x, (int32_t)y, down);
|
||||
LOG_I(TAG, "[200] /api/sim/touch x=%d y=%d down=%d", x, y, (int)down);
|
||||
http_server_request_send_string(request, "ok");
|
||||
return ERROR_NONE;
|
||||
#endif
|
||||
}
|
||||
|
||||
// GET /sim - live simulator viewer: MJPEG-style screenshot refresh + click-to-touch.
|
||||
error_t WebServerService::handleSimViewer(HttpServerRequest* request, void*) {
|
||||
bool authPassed = false;
|
||||
error_t authResult = validateRequestAuth(request, authPassed);
|
||||
if (!authPassed) {
|
||||
return authResult;
|
||||
}
|
||||
http_server_request_set_content_type(request, "text/html");
|
||||
// NOTE: the page resolves api/ against its own directory (new URL(u,base)).
|
||||
// Locally that is /sim -> /sim/api/...; behind tailscale
|
||||
// (--set-path=/simagent -> /) it is /simagent/sim -> /simagent/api/...
|
||||
// Both need handler aliases, registered in startServer() below:
|
||||
// /sim/api/* mirrors /api/* (screenshot, sim/touch). The page itself must
|
||||
// therefore be served with a trailing-slash-insensitive /sim match so the
|
||||
// browser treats /sim as a directory (see handleAssets /sim route).
|
||||
static const char* page =
|
||||
"<!doctype html><html><head><meta charset=utf-8><meta name=viewport "
|
||||
"content='width=device-width,initial-scale=1'>"
|
||||
"<title>Tactility Sim</title><style>"
|
||||
"body{margin:0;background:#111;color:#eee;font-family:sans-serif;"
|
||||
"display:flex;flex-direction:column;align-items:center;gap:8px;padding:12px}"
|
||||
"img{width:min(96vw,720px);image-rendering:pixelated;border:1px solid #333;"
|
||||
"border-radius:8px;touch-action:none;cursor:crosshair;background:#000}"
|
||||
".bar{display:flex;gap:8px;align-items:center;font-size:13px;color:#aaa}"
|
||||
"button{background:#313244;color:#fff;border:0;border-radius:8px;padding:6px 12px}"
|
||||
"</style></head><body>"
|
||||
"<div class=bar><b>Tactility Sim</b><span id=st>live</span>"
|
||||
"<button onclick='snap()'>refresh</button></div>"
|
||||
"<img id=scr alt='sim screen'>"
|
||||
"<div class=bar>click/tap the screen to touch · <span id=res></span> logical</div>"
|
||||
"<script>"
|
||||
"const img=document.getElementById('scr'),st=document.getElementById('st'),"
|
||||
"res=document.getElementById('res');"
|
||||
"const base=new URL('.',location.href).href;"
|
||||
"const api=u=>new URL(u,base).href;"
|
||||
"function snap(){img.src=api('api/screenshot?fast=1')+'&ts='+Date.now();}"
|
||||
"setInterval(snap,500);snap();"
|
||||
"img.addEventListener('error',()=>{st.textContent='reconnecting…';});"
|
||||
"img.addEventListener('load',()=>{st.textContent='live';"
|
||||
"res.textContent=img.naturalWidth+'x'+img.naturalHeight;});"
|
||||
"img.addEventListener('pointerdown',e=>{"
|
||||
"const r=img.getBoundingClientRect();"
|
||||
"const x=Math.round((e.clientX-r.left)/r.width*img.naturalWidth);"
|
||||
"const y=Math.round((e.clientY-r.top)/r.height*img.naturalHeight);"
|
||||
"fetch(api('api/sim/touch')+'?x='+x+'&y='+y,{method:'POST'});});"
|
||||
"</script></body></html>";
|
||||
http_server_request_send_string(request, page);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t WebServerService::handleAssets(HttpServerRequest* request, void*) {
|
||||
// Auth check for UI access control
|
||||
bool authPassed = false;
|
||||
@@ -1746,6 +1969,32 @@ error_t WebServerService::handleAssets(HttpServerRequest* request, void*) {
|
||||
http_server_request_get_uri(request, uri, sizeof(uri));
|
||||
LOG_I(TAG, "GET %s", uri);
|
||||
|
||||
// Simulator live viewer (no auth bypass: checked inside handler).
|
||||
// Served with redirect-to-slash so relative api/ URLs resolve under /sim/
|
||||
// (browsers treat /sim as a file, /sim/ as a directory for URL purposes).
|
||||
// NOTE: /sim/api/* does NOT need special-casing here: the /sim/api/*
|
||||
// handler aliases registered in startServer() route straight into
|
||||
// handleApiGet/handleApiPost, which strip the /sim prefix via
|
||||
// api_path_suffix(). This block only serves the viewer page itself.
|
||||
if (strncmp(uri, "/sim", 4) == 0 && (uri[4] == '\0' || uri[4] == '?' || uri[4] == '/')) {
|
||||
// Redirect bare /sim -> /sim/ so relative api/ resolves correctly.
|
||||
if (uri[4] == '\0' || uri[4] == '?') {
|
||||
std::string loc = "/sim/";
|
||||
const char* q = strchr(uri, '?');
|
||||
if (q != nullptr) { loc += q; }
|
||||
http_server_request_set_header(request, "Location", loc.c_str());
|
||||
http_server_request_send_error(request, 301, "see /sim/");
|
||||
return ERROR_NONE;
|
||||
}
|
||||
if (strncmp(uri, "/sim/api/", 9) == 0) {
|
||||
// Should have matched the /sim/api/* alias in startServer(); if we
|
||||
// get here the method has no alias (e.g. PUT) — 404 it.
|
||||
http_server_request_send_error(request, 404, "not found");
|
||||
return ERROR_UNDEFINED;
|
||||
}
|
||||
return handleSimViewer(request, nullptr);
|
||||
}
|
||||
|
||||
// Special case: serve favicon from system assets
|
||||
if (strcmp(uri, "/favicon.ico") == 0) {
|
||||
std::string faviconPathStr = std::string(file::MOUNT_POINT_SYSTEM) + "/spinner.png";
|
||||
|
||||
@@ -117,7 +117,7 @@ bool save(const AudioSettings& settings) {
|
||||
map[SETTINGS_KEY_OUTPUT_VOLUME] = toString(settings.outputVolume);
|
||||
|
||||
std::string settings_path;
|
||||
if (getSettingsFilePath(settings_path)) {
|
||||
if (!getSettingsFilePath(settings_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,16 @@ 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";
|
||||
constexpr auto* SETTINGS_KEY_TIMEOUT_MS = "backlightTimeoutMs";
|
||||
constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
||||
constexpr auto* SETTINGS_KEY_NIGHT_DIM_ENABLED = "nightDimEnabled";
|
||||
constexpr auto* SETTINGS_KEY_NIGHT_DIM_START_HOUR = "nightDimStartHour";
|
||||
constexpr auto* SETTINGS_KEY_NIGHT_DIM_END_HOUR = "nightDimEndHour";
|
||||
constexpr auto* SETTINGS_KEY_NIGHT_DIM_DUTY = "nightDimDuty";
|
||||
|
||||
static Orientation getDefaultOrientation() {
|
||||
auto* display = lv_display_get_default();
|
||||
@@ -73,6 +78,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 +119,10 @@ static std::string toString(ScreensaverType type) {
|
||||
return "MatrixRain";
|
||||
case StackChan:
|
||||
return "StackChan";
|
||||
case McpScreen:
|
||||
return "McpScreen";
|
||||
case BibleVerse:
|
||||
return "BibleVerse";
|
||||
default:
|
||||
std::unreachable();
|
||||
}
|
||||
@@ -107,6 +144,12 @@ 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 if (str == "BibleVerse") {
|
||||
type = ScreensaverType::BibleVerse;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -129,6 +172,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()) {
|
||||
@@ -162,12 +211,41 @@ bool load(DisplaySettings& settings) {
|
||||
fromString(screensaver_entry->second, screensaver_type);
|
||||
}
|
||||
|
||||
auto night_dim_enabled_entry = map.find(SETTINGS_KEY_NIGHT_DIM_ENABLED);
|
||||
bool night_dim_enabled = false;
|
||||
if (night_dim_enabled_entry != map.end()) {
|
||||
night_dim_enabled = (night_dim_enabled_entry->second == "1" || night_dim_enabled_entry->second == "true" || night_dim_enabled_entry->second == "True");
|
||||
}
|
||||
|
||||
auto night_dim_start_entry = map.find(SETTINGS_KEY_NIGHT_DIM_START_HOUR);
|
||||
int night_dim_start_hour = 22;
|
||||
if (night_dim_start_entry != map.end()) {
|
||||
night_dim_start_hour = atoi(night_dim_start_entry->second.c_str());
|
||||
}
|
||||
|
||||
auto night_dim_end_entry = map.find(SETTINGS_KEY_NIGHT_DIM_END_HOUR);
|
||||
int night_dim_end_hour = 7;
|
||||
if (night_dim_end_entry != map.end()) {
|
||||
night_dim_end_hour = atoi(night_dim_end_entry->second.c_str());
|
||||
}
|
||||
|
||||
auto night_dim_duty_entry = map.find(SETTINGS_KEY_NIGHT_DIM_DUTY);
|
||||
int night_dim_duty = 20;
|
||||
if (night_dim_duty_entry != map.end()) {
|
||||
night_dim_duty = atoi(night_dim_duty_entry->second.c_str());
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
settings.fontSize = font_size;
|
||||
settings.gammaCurve = gamma_curve;
|
||||
settings.backlightDuty = backlight_duty;
|
||||
settings.backlightTimeoutEnabled = timeout_enabled;
|
||||
settings.backlightTimeoutMs = timeout_ms;
|
||||
settings.screensaverType = screensaver_type;
|
||||
settings.nightDimEnabled = night_dim_enabled;
|
||||
settings.nightDimStartHour = static_cast<uint8_t>(night_dim_start_hour < 0 ? 0 : (night_dim_start_hour > 23 ? 23 : night_dim_start_hour));
|
||||
settings.nightDimEndHour = static_cast<uint8_t>(night_dim_end_hour < 0 ? 0 : (night_dim_end_hour > 23 ? 23 : night_dim_end_hour));
|
||||
settings.nightDimDuty = static_cast<uint8_t>(night_dim_duty < 0 ? 0 : (night_dim_duty > 255 ? 255 : night_dim_duty));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -175,11 +253,16 @@ bool load(DisplaySettings& settings) {
|
||||
DisplaySettings getDefault() {
|
||||
return DisplaySettings {
|
||||
.orientation = getDefaultOrientation(),
|
||||
.fontSize = FontSize::Default,
|
||||
.gammaCurve = 1,
|
||||
.backlightDuty = 200,
|
||||
.backlightTimeoutEnabled = false,
|
||||
.backlightTimeoutMs = 60000,
|
||||
.screensaverType = ScreensaverType::BouncingBalls
|
||||
.screensaverType = ScreensaverType::BouncingBalls,
|
||||
.nightDimEnabled = false,
|
||||
.nightDimStartHour = 22,
|
||||
.nightDimEndHour = 7,
|
||||
.nightDimDuty = 20
|
||||
};
|
||||
}
|
||||
|
||||
@@ -196,9 +279,14 @@ 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);
|
||||
map[SETTINGS_KEY_NIGHT_DIM_ENABLED] = settings.nightDimEnabled ? "1" : "0";
|
||||
map[SETTINGS_KEY_NIGHT_DIM_START_HOUR] = std::to_string(settings.nightDimStartHour);
|
||||
map[SETTINGS_KEY_NIGHT_DIM_END_HOUR] = std::to_string(settings.nightDimEndHour);
|
||||
map[SETTINGS_KEY_NIGHT_DIM_DUTY] = std::to_string(settings.nightDimDuty);
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
return false;
|
||||
|
||||
@@ -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")
|
||||
: true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
McpSettings getDefault() {
|
||||
return McpSettings{
|
||||
.mcpEnabled = true
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
@@ -44,7 +44,7 @@ static bool loadSystemSettingsFromFile(SystemSettings& properties) {
|
||||
}
|
||||
|
||||
auto time_format_entry = map.find("timeFormat24h");
|
||||
bool time_format_24h = time_format_entry == map.end() ? true : (time_format_entry->second == "true");
|
||||
bool time_format_24h = time_format_entry == map.end() ? false : (time_format_entry->second == "true");
|
||||
properties.timeFormat24h = time_format_24h;
|
||||
|
||||
// Load date format
|
||||
|
||||
@@ -164,7 +164,7 @@ bool load(WebServerSettings& settings) {
|
||||
// Web server settings
|
||||
settings.webServerEnabled = (webserver_enabled != map.end())
|
||||
? (webserver_enabled->second == "1" || webserver_enabled->second == "true")
|
||||
: false;
|
||||
: true;
|
||||
|
||||
settings.webServerPort = (webserver_port != map.end())
|
||||
? static_cast<uint16_t>(parseInt(webserver_port->second, 1, 65535, 80))
|
||||
@@ -206,7 +206,7 @@ WebServerSettings getDefault() {
|
||||
.apPassword = "", // Empty - will be auto-generated on first use (unless apOpenNetwork)
|
||||
.apOpenNetwork = false, // Default to secured network
|
||||
.apChannel = 1,
|
||||
.webServerEnabled = false, // Default WebServer OFF for security
|
||||
.webServerEnabled = true, // Default WebServer ON (simplified family UI: no toggle exposed)
|
||||
.webServerPort = 80,
|
||||
.webServerAuthEnabled = false, // Auth disabled by default
|
||||
.webServerUsername = "", // Empty - will be generated if auth is enabled
|
||||
|
||||
@@ -75,7 +75,7 @@ std::string getTimeZoneName() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return "Europe/Amsterdam";
|
||||
return "America/New_York";
|
||||
}
|
||||
|
||||
bool hasTimeZone() {
|
||||
@@ -105,13 +105,13 @@ std::string getTimeZoneCode() {
|
||||
}
|
||||
}
|
||||
}
|
||||
return "CET-1CEST,M3.5.0,M10.5.0/3"; // Default: Europe/Amsterdam
|
||||
return "EST5EDT,M3.2.0,M11.1.0"; // Default: America/New_York
|
||||
}
|
||||
|
||||
bool isTimeFormat24Hour() {
|
||||
SystemSettings properties;
|
||||
if (!loadSystemSettings(properties)) {
|
||||
return true;
|
||||
return false;
|
||||
} else {
|
||||
return properties.timeFormat24h;
|
||||
}
|
||||
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/bin/zsh
|
||||
# Build and flash LCDWIKI ES3C28P / ES3C35P firmware.
|
||||
#
|
||||
# Usage:
|
||||
# ./flash-es3c.sh 35p [port] [--build-only]
|
||||
# ./flash-es3c.sh 28p [port] [--build-only]
|
||||
#
|
||||
# If port is omitted, the single /dev/cu.usbmodem* device is used.
|
||||
# Each board keeps its own build dir (build-es3c28p / build-es3c35p),
|
||||
# so switching boards only rewrites sdkconfig via device.py.
|
||||
set -eu -o pipefail
|
||||
|
||||
FIRMWARE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$FIRMWARE_DIR"
|
||||
SCRIPT_NAME="$(basename "$0")"
|
||||
|
||||
usage() {
|
||||
echo "Usage: ${SCRIPT_NAME} <28p|35p> [port] [--build-only]"
|
||||
echo " port defaults to the single /dev/cu.usbmodem* device"
|
||||
}
|
||||
|
||||
if (( $# == 0 )); then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
28p|es3c28p) DEVICE_ID="es3c28p" ;;
|
||||
35p|es3c35p) DEVICE_ID="es3c35p" ;;
|
||||
-h|--help|help) usage; exit 0 ;;
|
||||
*) echo "Unknown device '$1' (expected 28p or 35p)"; usage; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
|
||||
PORT=""
|
||||
BUILD_ONLY=0
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--build-only) BUILD_ONLY=1 ;;
|
||||
*) PORT="$arg" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if (( ! BUILD_ONLY )) && [[ -z "$PORT" ]]; then
|
||||
candidates=(/dev/cu.usbmodem*(N))
|
||||
if (( ${#candidates} == 0 )); then
|
||||
echo "No /dev/cu.usbmodem* device found. Connect the board or pass the port explicitly."
|
||||
exit 1
|
||||
fi
|
||||
if (( ${#candidates} > 1 )); then
|
||||
echo "Multiple USB modem devices found:"
|
||||
printf ' %s\n' "${candidates[@]}"
|
||||
echo "Unplug one board or pass the port explicitly."
|
||||
exit 1
|
||||
fi
|
||||
PORT="${candidates[1]}"
|
||||
fi
|
||||
|
||||
# IDF 5.5 environment (host venvs corrupt IDF tooling, so pin the IDF python env)
|
||||
unset VIRTUAL_ENV PYTHONPATH PYTHONHOME
|
||||
export IDF_PYTHON_ENV_PATH=/Users/adolforeyna/.espressif/python_env/idf5.5_py3.9_env
|
||||
source /Users/adolforeyna/esp/esp-idf/export.sh
|
||||
|
||||
BUILD_DIR="build-${DEVICE_ID}"
|
||||
"$IDF_PYTHON_ENV_PATH/bin/python" device.py "$DEVICE_ID"
|
||||
idf.py -B "$BUILD_DIR" reconfigure build
|
||||
|
||||
if (( BUILD_ONLY )); then
|
||||
echo "Build done (${BUILD_DIR}/Tactility.bin). Skipping flash (--build-only)."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "=== Confirming board on ${PORT} ==="
|
||||
"$IDF_PYTHON_ENV_PATH/bin/python" -m esptool --chip esp32s3 -p "$PORT" chip_id | grep -E "Chip is|MAC:"
|
||||
|
||||
idf.py -B "$BUILD_DIR" -p "$PORT" -b 460800 flash
|
||||
echo "Flashed ${DEVICE_ID} on ${PORT}."
|
||||
Reference in New Issue
Block a user