mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-07-21 02:05:52 +00:00
* feat: migrate firmware to xiaozhi-fonts 2.0.0 * fix: restart scrolling subtitles on text change * docs: add AGENTS.md for project overview, architecture, rules, and commands - Introduced AGENTS.md to document the XiaoZhi voice-assistant firmware architecture, required rules for development, board configuration process, and validation steps. - Included detailed sections on project structure, commands for building and testing, and authoritative documentation references. * feat: finalize glyph push protocol * fix: remove stale emoji font include * build: use xiaozhi-fonts 2.0.0 * fix: decouple custom fonts from glyph push * refactor: improve wake word invocation handling - Introduced BeginWakeWordInvoke method to streamline the wake word processing flow. - Updated HandleWakeWordDetectedEvent to utilize the new method, ensuring proper state transitions and scheduling. - Enhanced error handling to prevent the device from getting stuck in the connecting state. - Refactored audio channel management to improve responsiveness during wake word detection. --------- Co-authored-by: Xiaoxia <terrence.huang@tenclass.com>
107 lines
3.2 KiB
C++
107 lines
3.2 KiB
C++
#ifndef ASSETS_H
|
|
#define ASSETS_H
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include <esp_partition.h>
|
|
#include <cJSON.h>
|
|
#include <model_path.h>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#if HAVE_LVGL
|
|
#include <spi_flash_mmap.h>
|
|
#endif
|
|
|
|
struct Asset {
|
|
size_t size;
|
|
size_t offset;
|
|
};
|
|
|
|
struct TextFontCapability {
|
|
bool glyph_push = false;
|
|
std::string bundle;
|
|
std::string charset;
|
|
int size = 0;
|
|
int bpp = 0;
|
|
};
|
|
|
|
class Assets {
|
|
public:
|
|
static Assets& GetInstance() {
|
|
static Assets instance;
|
|
return instance;
|
|
}
|
|
~Assets();
|
|
|
|
bool Download(std::string url,
|
|
std::function<void(int progress, size_t speed)> progress_callback);
|
|
bool Apply(bool refresh_display_theme = true);
|
|
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
|
|
|
|
inline bool partition_valid() const { return partition_valid_; }
|
|
inline std::string default_assets_url() const { return default_assets_url_; }
|
|
inline TextFontCapability text_font_capability() const { return text_font_capability_; }
|
|
|
|
private:
|
|
Assets();
|
|
Assets(const Assets&) = delete;
|
|
Assets& operator=(const Assets&) = delete;
|
|
|
|
bool InitializePartition();
|
|
void UnApplyPartition();
|
|
static bool FindPartition(Assets* assets);
|
|
static bool LoadSrmodelsFromIndex(Assets* assets, cJSON* root = nullptr);
|
|
void UseBuiltInTextFontCapability();
|
|
void DisableTextFontGlyphPush();
|
|
|
|
class AssetStrategy {
|
|
public:
|
|
virtual ~AssetStrategy() = default;
|
|
virtual bool Apply(Assets* assets, bool refresh_display_theme = true) = 0;
|
|
virtual bool InitializePartition(Assets* assets) = 0;
|
|
virtual void UnApplyPartition(Assets* assets) = 0;
|
|
virtual bool GetAssetData(Assets* assets, const std::string& name, void*& ptr,
|
|
size_t& size) = 0;
|
|
};
|
|
|
|
class LvglStrategy : public AssetStrategy {
|
|
public:
|
|
bool Apply(Assets* assets, bool refresh_display_theme = true) override;
|
|
bool InitializePartition(Assets* assets) override;
|
|
void UnApplyPartition(Assets* assets) override;
|
|
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr,
|
|
size_t& size) override;
|
|
|
|
private:
|
|
static uint32_t CalculateChecksum(const char* data, uint32_t length);
|
|
std::map<std::string, Asset> assets_;
|
|
esp_partition_mmap_handle_t mmap_handle_ = 0;
|
|
const char* mmap_root_ = nullptr;
|
|
bool checksum_valid_ = false;
|
|
};
|
|
|
|
class EmoteStrategy : public AssetStrategy {
|
|
public:
|
|
bool Apply(Assets* assets, bool refresh_display_theme = true) override;
|
|
bool InitializePartition(Assets* assets) override;
|
|
void UnApplyPartition(Assets* assets) override;
|
|
bool GetAssetData(Assets* assets, const std::string& name, void*& ptr,
|
|
size_t& size) override;
|
|
};
|
|
|
|
// Strategy instance
|
|
std::unique_ptr<AssetStrategy> strategy_;
|
|
|
|
protected:
|
|
const esp_partition_t* partition_ = nullptr;
|
|
bool partition_valid_ = false;
|
|
std::string default_assets_url_;
|
|
TextFontCapability text_font_capability_;
|
|
srmodel_list_t* models_list_ = nullptr;
|
|
};
|
|
|
|
#endif
|