9a307e522d
- old optimization bypassed audio-stream resampler (16k direct -> MCLK 4.096MHz vs 11.29MHz native) - brick game correct because it used audio_stream path - now MCP uses audio_stream_open_output/input + read/write matching native logger stack - falls back to direct I2S only if audio-stream device missing
78 lines
3.0 KiB
C++
78 lines
3.0 KiB
C++
#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
|