mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-01-14 01:07:30 +08:00
feat: update emote display (#1629)
This commit is contained in:
parent
906d819454
commit
1e8fefbede
@ -62,6 +62,8 @@ endfunction()
|
|||||||
set(BUILTIN_TEXT_FONT font_puhui_14_1)
|
set(BUILTIN_TEXT_FONT font_puhui_14_1)
|
||||||
set(BUILTIN_ICON_FONT font_awesome_14_1)
|
set(BUILTIN_ICON_FONT font_awesome_14_1)
|
||||||
|
|
||||||
|
set(EMOTE_RESOLUTION "320_240")
|
||||||
|
|
||||||
# Add board files according to BOARD_TYPE
|
# Add board files according to BOARD_TYPE
|
||||||
# Set default assets if the board uses partition table V2
|
# Set default assets if the board uses partition table V2
|
||||||
if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
|
if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
|
||||||
@ -90,11 +92,13 @@ elseif(CONFIG_BOARD_TYPE_ESP_BOX_3)
|
|||||||
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
||||||
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
||||||
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
||||||
|
set(EMOTE_RESOLUTION "320_240")
|
||||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX)
|
elseif(CONFIG_BOARD_TYPE_ESP_BOX)
|
||||||
set(BOARD_TYPE "esp-box")
|
set(BOARD_TYPE "esp-box")
|
||||||
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
||||||
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
||||||
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
||||||
|
set(EMOTE_RESOLUTION "320_240")
|
||||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX_LITE)
|
elseif(CONFIG_BOARD_TYPE_ESP_BOX_LITE)
|
||||||
set(BOARD_TYPE "esp-box-lite")
|
set(BOARD_TYPE "esp-box-lite")
|
||||||
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
|
||||||
@ -212,6 +216,8 @@ elseif(CONFIG_BOARD_TYPE_ECHOEAR)
|
|||||||
set(BUILTIN_TEXT_FONT font_puhui_20_4)
|
set(BUILTIN_TEXT_FONT font_puhui_20_4)
|
||||||
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
set(BUILTIN_ICON_FONT font_awesome_20_4)
|
||||||
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
|
||||||
|
set(EMOTE_RESOLUTION "360_360")
|
||||||
|
# set(EMOTE_EXTERNAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/boards/echoear/assets")
|
||||||
elseif(CONFIG_BOARD_TYPE_ESP_SENSAIRSHUTTLE)
|
elseif(CONFIG_BOARD_TYPE_ESP_SENSAIRSHUTTLE)
|
||||||
set(BOARD_TYPE "esp-sensairshuttle")
|
set(BOARD_TYPE "esp-sensairshuttle")
|
||||||
set(BUILTIN_TEXT_FONT font_puhui_basic_16_4)
|
set(BUILTIN_TEXT_FONT font_puhui_basic_16_4)
|
||||||
@ -928,6 +934,14 @@ if ("${size}" AND "${offset}")
|
|||||||
get_assets_local_file("${CONFIG_CUSTOM_ASSETS_FILE}" ASSETS_LOCAL_FILE)
|
get_assets_local_file("${CONFIG_CUSTOM_ASSETS_FILE}" ASSETS_LOCAL_FILE)
|
||||||
esptool_py_flash_to_partition(flash "assets" "${ASSETS_LOCAL_FILE}")
|
esptool_py_flash_to_partition(flash "assets" "${ASSETS_LOCAL_FILE}")
|
||||||
message(STATUS "Custom assets flash configured: ${ASSETS_LOCAL_FILE} -> assets partition")
|
message(STATUS "Custom assets flash configured: ${ASSETS_LOCAL_FILE} -> assets partition")
|
||||||
|
elseif(CONFIG_FLASH_EXPRESSION_ASSETS)
|
||||||
|
set(ASSETS_NAME "expression_assets")
|
||||||
|
set(ASSETS_PARTITION "assets")
|
||||||
|
set(ASSETS_FILE "${CMAKE_BINARY_DIR}/${ASSETS_NAME}.bin")
|
||||||
|
|
||||||
|
build_speaker_assets_bin("${ASSETS_PARTITION}" ${EMOTE_RESOLUTION} ${ASSETS_FILE} ${CONFIG_MMAP_FILE_NAME_LENGTH})
|
||||||
|
message(STATUS "Generated emote assets: ${ASSETS_FILE} -> ${ASSETS_PARTITION} partition")
|
||||||
|
esptool_py_flash_to_partition(flash "${ASSETS_PARTITION}" "${ASSETS_FILE}")
|
||||||
elseif(CONFIG_FLASH_NONE_ASSETS)
|
elseif(CONFIG_FLASH_NONE_ASSETS)
|
||||||
message(STATUS "Assets flashing disabled (FLASH_NONE_ASSETS)")
|
message(STATUS "Assets flashing disabled (FLASH_NONE_ASSETS)")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -8,7 +8,8 @@ config OTA_URL
|
|||||||
|
|
||||||
choice
|
choice
|
||||||
prompt "Flash Assets"
|
prompt "Flash Assets"
|
||||||
default FLASH_DEFAULT_ASSETS
|
default FLASH_DEFAULT_ASSETS if !USE_EMOTE_MESSAGE_STYLE
|
||||||
|
default FLASH_EXPRESSION_ASSETS if USE_EMOTE_MESSAGE_STYLE
|
||||||
help
|
help
|
||||||
Select the assets to flash.
|
Select the assets to flash.
|
||||||
|
|
||||||
@ -16,8 +17,12 @@ choice
|
|||||||
bool "Do not flash assets"
|
bool "Do not flash assets"
|
||||||
config FLASH_DEFAULT_ASSETS
|
config FLASH_DEFAULT_ASSETS
|
||||||
bool "Flash Default Assets"
|
bool "Flash Default Assets"
|
||||||
|
depends on !USE_EMOTE_MESSAGE_STYLE
|
||||||
config FLASH_CUSTOM_ASSETS
|
config FLASH_CUSTOM_ASSETS
|
||||||
bool "Flash Custom Assets"
|
bool "Flash Custom Assets"
|
||||||
|
config FLASH_EXPRESSION_ASSETS
|
||||||
|
bool "Flash Emote Assets"
|
||||||
|
depends on USE_EMOTE_MESSAGE_STYLE
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config CUSTOM_ASSETS_FILE
|
config CUSTOM_ASSETS_FILE
|
||||||
@ -585,7 +590,9 @@ choice DISPLAY_STYLE
|
|||||||
|
|
||||||
config USE_EMOTE_MESSAGE_STYLE
|
config USE_EMOTE_MESSAGE_STYLE
|
||||||
bool "Emote animation style"
|
bool "Emote animation style"
|
||||||
depends on BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ECHOEAR || BOARD_TYPE_LICHUANG_DEV_S3 || BOARD_TYPE_ESP_SENSAIRSHUTTLE
|
depends on BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_3 \
|
||||||
|
|| BOARD_TYPE_ECHOEAR || BOARD_TYPE_LICHUANG_DEV_S3 \
|
||||||
|
|| BOARD_TYPE_ESP_SENSAIRSHUTTLE
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
choice WAKE_WORD_TYPE
|
choice WAKE_WORD_TYPE
|
||||||
|
|||||||
390
main/assets.cc
390
main/assets.cc
@ -4,17 +4,19 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "lvgl_theme.h"
|
#include "lvgl_theme.h"
|
||||||
#include "emote_display.h"
|
#include "emote_display.h"
|
||||||
#ifdef HAVE_LVGL
|
#include "expression_emote.h"
|
||||||
|
#if HAVE_LVGL
|
||||||
#include "display/lcd_display.h"
|
#include "display/lcd_display.h"
|
||||||
|
#include <spi_flash_mmap.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <spi_flash_mmap.h>
|
|
||||||
#include <esp_timer.h>
|
#include <esp_timer.h>
|
||||||
#include <cbin_font.h>
|
#include <cbin_font.h>
|
||||||
|
|
||||||
|
|
||||||
#define TAG "Assets"
|
#define TAG "Assets"
|
||||||
|
#define PARTITION_LABEL "assets"
|
||||||
|
|
||||||
struct mmap_assets_table {
|
struct mmap_assets_table {
|
||||||
char asset_name[32]; /*!< Name of the asset */
|
char asset_name[32]; /*!< Name of the asset */
|
||||||
@ -24,19 +26,99 @@ struct mmap_assets_table {
|
|||||||
uint16_t asset_height; /*!< Height of the asset */
|
uint16_t asset_height; /*!< Height of the asset */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Assets::Assets() {
|
Assets::Assets() {
|
||||||
|
#if HAVE_LVGL
|
||||||
|
strategy_ = std::make_unique<Assets::LvglStrategy>();
|
||||||
|
#else
|
||||||
|
strategy_ = std::make_unique<Assets::EmoteStrategy>();
|
||||||
|
#endif
|
||||||
// Initialize the partition
|
// Initialize the partition
|
||||||
InitializePartition();
|
InitializePartition();
|
||||||
}
|
}
|
||||||
|
|
||||||
Assets::~Assets() {
|
Assets::~Assets() {
|
||||||
if (mmap_handle_ != 0) {
|
UnApplyPartition();
|
||||||
esp_partition_munmap(mmap_handle_);
|
}
|
||||||
|
|
||||||
|
bool Assets::FindPartition(Assets* assets) {
|
||||||
|
assets->partition_ = esp_partition_find_first(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, PARTITION_LABEL);
|
||||||
|
if (assets->partition_ == nullptr) {
|
||||||
|
ESP_LOGI(TAG, "No assets partition found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::Apply() {
|
||||||
|
return strategy_ ? strategy_->Apply(this) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::InitializePartition() {
|
||||||
|
return strategy_ ? strategy_->InitializePartition(this) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Assets::UnApplyPartition() {
|
||||||
|
if (strategy_) {
|
||||||
|
strategy_->UnApplyPartition(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Assets::CalculateChecksum(const char* data, uint32_t length) {
|
bool Assets::GetAssetData(const std::string& name, void*& ptr, size_t& size) {
|
||||||
|
return strategy_ ? strategy_->GetAssetData(this, name, ptr, size) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::LoadSrmodelsFromIndex(Assets* assets, cJSON* root) {
|
||||||
|
void* ptr = nullptr;
|
||||||
|
size_t size = 0;
|
||||||
|
bool need_delete_root = false;
|
||||||
|
|
||||||
|
// If root is not provided, parse index.json
|
||||||
|
if (root == nullptr) {
|
||||||
|
if (!assets->GetAssetData("index.json", ptr, size)) {
|
||||||
|
ESP_LOGE(TAG, "The index.json file is not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
root = cJSON_ParseWithLength(static_cast<char*>(ptr), size);
|
||||||
|
if (root == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "The index.json file is not valid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
need_delete_root = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* srmodels = cJSON_GetObjectItem(root, "srmodels");
|
||||||
|
if (cJSON_IsString(srmodels)) {
|
||||||
|
std::string srmodels_file = srmodels->valuestring;
|
||||||
|
if (assets->GetAssetData(srmodels_file, ptr, size)) {
|
||||||
|
if (assets->models_list_ != nullptr) {
|
||||||
|
esp_srmodel_deinit(assets->models_list_);
|
||||||
|
assets->models_list_ = nullptr;
|
||||||
|
}
|
||||||
|
assets->models_list_ = srmodel_load(static_cast<uint8_t*>(ptr));
|
||||||
|
if (assets->models_list_ != nullptr) {
|
||||||
|
auto& app = Application::GetInstance();
|
||||||
|
app.GetAudioService().SetModelsList(assets->models_list_);
|
||||||
|
if (need_delete_root) {
|
||||||
|
cJSON_Delete(root);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Failed to load srmodels.bin");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "The srmodels file %s is not found", srmodels_file.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (need_delete_root) {
|
||||||
|
cJSON_Delete(root);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if HAVE_LVGL
|
||||||
|
uint32_t Assets::LvglStrategy::CalculateChecksum(const char* data, uint32_t length) {
|
||||||
uint32_t checksum = 0;
|
uint32_t checksum = 0;
|
||||||
for (uint32_t i = 0; i < length; i++) {
|
for (uint32_t i = 0; i < length; i++) {
|
||||||
checksum += data[i];
|
checksum += data[i];
|
||||||
@ -44,40 +126,37 @@ uint32_t Assets::CalculateChecksum(const char* data, uint32_t length) {
|
|||||||
return checksum & 0xFFFF;
|
return checksum & 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::InitializePartition() {
|
bool Assets::LvglStrategy::InitializePartition(Assets* assets) {
|
||||||
partition_valid_ = false;
|
assets->partition_valid_ = false;
|
||||||
checksum_valid_ = false;
|
|
||||||
assets_.clear();
|
assets_.clear();
|
||||||
|
|
||||||
partition_ = esp_partition_find_first(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, "assets");
|
if (!Assets::FindPartition(assets)) {
|
||||||
if (partition_ == nullptr) {
|
|
||||||
ESP_LOGI(TAG, "No assets partition found");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int free_pages = spi_flash_mmap_get_free_pages(SPI_FLASH_MMAP_DATA);
|
int free_pages = spi_flash_mmap_get_free_pages(SPI_FLASH_MMAP_DATA);
|
||||||
uint32_t storage_size = free_pages * 64 * 1024;
|
uint32_t storage_size = free_pages * 64 * 1024;
|
||||||
ESP_LOGI(TAG, "The storage free size is %ld KB", storage_size / 1024);
|
ESP_LOGI(TAG, "The storage free size is %ld KB", storage_size / 1024);
|
||||||
ESP_LOGI(TAG, "The partition size is %ld KB", partition_->size / 1024);
|
ESP_LOGI(TAG, "The partition size is %ld KB", assets->partition_->size / 1024);
|
||||||
if (storage_size < partition_->size) {
|
if (storage_size < assets->partition_->size) {
|
||||||
ESP_LOGE(TAG, "The free size %ld KB is less than assets partition required %ld KB", storage_size / 1024, partition_->size / 1024);
|
ESP_LOGE(TAG, "The free size %ld KB is less than assets partition required %ld KB", storage_size / 1024, assets->partition_->size / 1024);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t err = esp_partition_mmap(partition_, 0, partition_->size, ESP_PARTITION_MMAP_DATA, (const void**)&mmap_root_, &mmap_handle_);
|
esp_err_t err = esp_partition_mmap(assets->partition_, 0, assets->partition_->size, ESP_PARTITION_MMAP_DATA, (const void**)&mmap_root_, &mmap_handle_);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to mmap assets partition: %s", esp_err_to_name(err));
|
ESP_LOGE(TAG, "Failed to mmap assets partition: %s", esp_err_to_name(err));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
partition_valid_ = true;
|
assets->partition_valid_ = true;
|
||||||
|
|
||||||
uint32_t stored_files = *(uint32_t*)(mmap_root_ + 0);
|
uint32_t stored_files = *(uint32_t*)(mmap_root_ + 0);
|
||||||
uint32_t stored_chksum = *(uint32_t*)(mmap_root_ + 4);
|
uint32_t stored_chksum = *(uint32_t*)(mmap_root_ + 4);
|
||||||
uint32_t stored_len = *(uint32_t*)(mmap_root_ + 8);
|
uint32_t stored_len = *(uint32_t*)(mmap_root_ + 8);
|
||||||
|
|
||||||
if (stored_len > partition_->size - 12) {
|
if (stored_len > assets->partition_->size - 12) {
|
||||||
ESP_LOGD(TAG, "The stored_len (0x%lx) is greater than the partition size (0x%lx) - 12", stored_len, partition_->size);
|
ESP_LOGD(TAG, "The stored_len (0x%lx) is greater than the partition size (0x%lx) - 12", stored_len, assets->partition_->size);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +183,37 @@ bool Assets::InitializePartition() {
|
|||||||
return checksum_valid_;
|
return checksum_valid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::Apply() {
|
void Assets::LvglStrategy::UnApplyPartition(Assets* assets) {
|
||||||
|
if (mmap_handle_ != 0) {
|
||||||
|
esp_partition_munmap(mmap_handle_);
|
||||||
|
mmap_handle_ = 0;
|
||||||
|
mmap_root_ = nullptr;
|
||||||
|
}
|
||||||
|
checksum_valid_ = false;
|
||||||
|
assets_.clear();
|
||||||
|
(void)assets; // Unused parameter
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::LvglStrategy::GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) {
|
||||||
|
auto asset = assets_.find(name);
|
||||||
|
if (asset == assets_.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto data = (const char*)(mmap_root_ + asset->second.offset);
|
||||||
|
if (data[0] != 'Z' || data[1] != 'Z') {
|
||||||
|
ESP_LOGE(TAG, "The asset %s is not valid with magic %02x%02x", name.c_str(), data[0], data[1]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr = static_cast<void*>(const_cast<char*>(data + 2));
|
||||||
|
size = asset->second.size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::LvglStrategy::Apply(Assets* assets) {
|
||||||
void* ptr = nullptr;
|
void* ptr = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (!GetAssetData("index.json", ptr, size)) {
|
if (!assets->GetAssetData("index.json", ptr, size)) {
|
||||||
ESP_LOGE(TAG, "The index.json file is not found");
|
ESP_LOGE(TAG, "The index.json file is not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -125,28 +231,9 @@ bool Assets::Apply() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* srmodels = cJSON_GetObjectItem(root, "srmodels");
|
|
||||||
if (cJSON_IsString(srmodels)) {
|
|
||||||
std::string srmodels_file = srmodels->valuestring;
|
|
||||||
if (GetAssetData(srmodels_file, ptr, size)) {
|
|
||||||
if (models_list_ != nullptr) {
|
|
||||||
esp_srmodel_deinit(models_list_);
|
|
||||||
models_list_ = nullptr;
|
|
||||||
}
|
|
||||||
models_list_ = srmodel_load(static_cast<uint8_t*>(ptr));
|
|
||||||
if (models_list_ != nullptr) {
|
|
||||||
auto& app = Application::GetInstance();
|
|
||||||
app.GetAudioService().SetModelsList(models_list_);
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Failed to load srmodels.bin");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "The srmodels file %s is not found", srmodels_file.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_LVGL
|
Assets::LoadSrmodelsFromIndex(assets, root);
|
||||||
|
|
||||||
auto& theme_manager = LvglThemeManager::GetInstance();
|
auto& theme_manager = LvglThemeManager::GetInstance();
|
||||||
auto light_theme = theme_manager.GetTheme("light");
|
auto light_theme = theme_manager.GetTheme("light");
|
||||||
auto dark_theme = theme_manager.GetTheme("dark");
|
auto dark_theme = theme_manager.GetTheme("dark");
|
||||||
@ -154,7 +241,7 @@ bool Assets::Apply() {
|
|||||||
cJSON* font = cJSON_GetObjectItem(root, "text_font");
|
cJSON* font = cJSON_GetObjectItem(root, "text_font");
|
||||||
if (cJSON_IsString(font)) {
|
if (cJSON_IsString(font)) {
|
||||||
std::string fonts_text_file = font->valuestring;
|
std::string fonts_text_file = font->valuestring;
|
||||||
if (GetAssetData(fonts_text_file, ptr, size)) {
|
if (assets->GetAssetData(fonts_text_file, ptr, size)) {
|
||||||
auto text_font = std::make_shared<LvglCBinFont>(ptr);
|
auto text_font = std::make_shared<LvglCBinFont>(ptr);
|
||||||
if (text_font->font() == nullptr) {
|
if (text_font->font() == nullptr) {
|
||||||
ESP_LOGE(TAG, "Failed to load fonts.bin");
|
ESP_LOGE(TAG, "Failed to load fonts.bin");
|
||||||
@ -182,7 +269,7 @@ bool Assets::Apply() {
|
|||||||
cJSON* file = cJSON_GetObjectItem(emoji, "file");
|
cJSON* file = cJSON_GetObjectItem(emoji, "file");
|
||||||
cJSON* eaf = cJSON_GetObjectItem(emoji, "eaf");
|
cJSON* eaf = cJSON_GetObjectItem(emoji, "eaf");
|
||||||
if (cJSON_IsString(name) && cJSON_IsString(file) && (NULL== eaf)) {
|
if (cJSON_IsString(name) && cJSON_IsString(file) && (NULL== eaf)) {
|
||||||
if (!GetAssetData(file->valuestring, ptr, size)) {
|
if (!assets->GetAssetData(file->valuestring, ptr, size)) {
|
||||||
ESP_LOGE(TAG, "Emoji %s image file %s is not found", name->valuestring, file->valuestring);
|
ESP_LOGE(TAG, "Emoji %s image file %s is not found", name->valuestring, file->valuestring);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -213,7 +300,7 @@ bool Assets::Apply() {
|
|||||||
light_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
|
light_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
|
||||||
}
|
}
|
||||||
if (cJSON_IsString(background_image)) {
|
if (cJSON_IsString(background_image)) {
|
||||||
if (!GetAssetData(background_image->valuestring, ptr, size)) {
|
if (!assets->GetAssetData(background_image->valuestring, ptr, size)) {
|
||||||
ESP_LOGE(TAG, "The background image file %s is not found", background_image->valuestring);
|
ESP_LOGE(TAG, "The background image file %s is not found", background_image->valuestring);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -234,7 +321,7 @@ bool Assets::Apply() {
|
|||||||
dark_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
|
dark_theme->set_chat_background_color(LvglTheme::ParseColor(background_color->valuestring));
|
||||||
}
|
}
|
||||||
if (cJSON_IsString(background_image)) {
|
if (cJSON_IsString(background_image)) {
|
||||||
if (!GetAssetData(background_image->valuestring, ptr, size)) {
|
if (!assets->GetAssetData(background_image->valuestring, ptr, size)) {
|
||||||
ESP_LOGE(TAG, "The background image file %s is not found", background_image->valuestring);
|
ESP_LOGE(TAG, "The background image file %s is not found", background_image->valuestring);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -262,137 +349,84 @@ bool Assets::Apply() {
|
|||||||
ESP_LOGI(TAG, "Set hide_subtitle to %s", hide ? "true" : "false");
|
ESP_LOGI(TAG, "Set hide_subtitle to %s", hide ? "true" : "false");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(CONFIG_USE_EMOTE_MESSAGE_STYLE)
|
|
||||||
auto &board = Board::GetInstance();
|
|
||||||
auto display = board.GetDisplay();
|
|
||||||
auto emote_display = dynamic_cast<emote::EmoteDisplay*>(display);
|
|
||||||
|
|
||||||
cJSON* font = cJSON_GetObjectItem(root, "text_font");
|
|
||||||
if (cJSON_IsString(font)) {
|
|
||||||
std::string fonts_text_file = font->valuestring;
|
|
||||||
if (GetAssetData(fonts_text_file, ptr, size)) {
|
|
||||||
auto text_font = std::make_shared<LvglCBinFont>(ptr);
|
|
||||||
if (text_font->font() == nullptr) {
|
|
||||||
ESP_LOGE(TAG, "Failed to load fonts.bin");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (emote_display) {
|
|
||||||
emote_display->AddTextFont(text_font);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "The font file %s is not found", fonts_text_file.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* emoji_collection = cJSON_GetObjectItem(root, "emoji_collection");
|
|
||||||
if (cJSON_IsArray(emoji_collection)) {
|
|
||||||
int emoji_count = cJSON_GetArraySize(emoji_collection);
|
|
||||||
if (emote_display) {
|
|
||||||
for (int i = 0; i < emoji_count; i++) {
|
|
||||||
cJSON* icon = cJSON_GetArrayItem(emoji_collection, i);
|
|
||||||
if (cJSON_IsObject(icon)) {
|
|
||||||
cJSON* name = cJSON_GetObjectItem(icon, "name");
|
|
||||||
cJSON* file = cJSON_GetObjectItem(icon, "file");
|
|
||||||
|
|
||||||
if (cJSON_IsString(name) && cJSON_IsString(file)) {
|
|
||||||
if (GetAssetData(file->valuestring, ptr, size)) {
|
|
||||||
cJSON* eaf = cJSON_GetObjectItem(icon, "eaf");
|
|
||||||
bool lack_value = false;
|
|
||||||
bool loop_value = false;
|
|
||||||
int fps_value = 0;
|
|
||||||
|
|
||||||
if (cJSON_IsObject(eaf)) {
|
|
||||||
cJSON* lack = cJSON_GetObjectItem(eaf, "lack");
|
|
||||||
cJSON* loop = cJSON_GetObjectItem(eaf, "loop");
|
|
||||||
cJSON* fps = cJSON_GetObjectItem(eaf, "fps");
|
|
||||||
|
|
||||||
lack_value = lack ? cJSON_IsTrue(lack) : false;
|
|
||||||
loop_value = loop ? cJSON_IsTrue(loop) : false;
|
|
||||||
fps_value = fps ? fps->valueint : 0;
|
|
||||||
|
|
||||||
emote_display->AddEmojiData(name->valuestring, ptr, size,
|
|
||||||
static_cast<uint8_t>(fps_value),
|
|
||||||
loop_value, lack_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Emoji \"%10s\" image file %s is not found", name->valuestring, file->valuestring);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* icon_collection = cJSON_GetObjectItem(root, "icon_collection");
|
|
||||||
if (cJSON_IsArray(icon_collection)) {
|
|
||||||
if (emote_display) {
|
|
||||||
int icon_count = cJSON_GetArraySize(icon_collection);
|
|
||||||
for (int i = 0; i < icon_count; i++) {
|
|
||||||
cJSON* icon = cJSON_GetArrayItem(icon_collection, i);
|
|
||||||
if (cJSON_IsObject(icon)) {
|
|
||||||
cJSON* name = cJSON_GetObjectItem(icon, "name");
|
|
||||||
cJSON* file = cJSON_GetObjectItem(icon, "file");
|
|
||||||
|
|
||||||
if (cJSON_IsString(name) && cJSON_IsString(file)) {
|
|
||||||
if (GetAssetData(file->valuestring, ptr, size)) {
|
|
||||||
emote_display->AddIconData(name->valuestring, ptr, size);
|
|
||||||
} else {
|
|
||||||
ESP_LOGE(TAG, "Icon \"%10s\" image file %s is not found", name->valuestring, file->valuestring);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* layout_json = cJSON_GetObjectItem(root, "layout");
|
|
||||||
if (cJSON_IsArray(layout_json)) {
|
|
||||||
int layout_count = cJSON_GetArraySize(layout_json);
|
|
||||||
|
|
||||||
for (int i = 0; i < layout_count; i++) {
|
|
||||||
cJSON* layout_item = cJSON_GetArrayItem(layout_json, i);
|
|
||||||
if (cJSON_IsObject(layout_item)) {
|
|
||||||
cJSON* name = cJSON_GetObjectItem(layout_item, "name");
|
|
||||||
cJSON* align = cJSON_GetObjectItem(layout_item, "align");
|
|
||||||
cJSON* x = cJSON_GetObjectItem(layout_item, "x");
|
|
||||||
cJSON* y = cJSON_GetObjectItem(layout_item, "y");
|
|
||||||
cJSON* width = cJSON_GetObjectItem(layout_item, "width");
|
|
||||||
cJSON* height = cJSON_GetObjectItem(layout_item, "height");
|
|
||||||
|
|
||||||
if (cJSON_IsString(name) && cJSON_IsString(align) && cJSON_IsNumber(x) && cJSON_IsNumber(y)) {
|
|
||||||
int width_val = cJSON_IsNumber(width) ? width->valueint : 0;
|
|
||||||
int height_val = cJSON_IsNumber(height) ? height->valueint : 0;
|
|
||||||
|
|
||||||
if (emote_display) {
|
|
||||||
emote_display->AddLayoutData(name->valuestring, align->valuestring,
|
|
||||||
x->valueint, y->valueint, width_val, height_val);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "Invalid layout item %d: missing required fields", i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif // HAVE_LVGL
|
||||||
|
|
||||||
|
bool Assets::EmoteStrategy::InitializePartition(Assets* assets) {
|
||||||
|
assets->partition_valid_ = false;
|
||||||
|
|
||||||
|
if (!Assets::FindPartition(assets)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t ret = ESP_ERR_INVALID_STATE;
|
||||||
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
auto* emote_display = dynamic_cast<emote::EmoteDisplay*>(display);
|
||||||
|
if (emote_display && emote_display->GetEmoteHandle() != nullptr) {
|
||||||
|
const emote_data_t data = {
|
||||||
|
.type = EMOTE_SOURCE_PARTITION,
|
||||||
|
.source = {
|
||||||
|
.partition_label = PARTITION_LABEL,
|
||||||
|
},
|
||||||
|
.flags = {
|
||||||
|
.mmap_enable = true, //must be true here!!!
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ret = emote_mount_assets(emote_display->GetEmoteHandle(), &data);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Emote display is not initialized");
|
||||||
|
}
|
||||||
|
assets->partition_valid_ = ((ret == ESP_OK) ? true : false);
|
||||||
|
return assets->partition_valid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Assets::EmoteStrategy::UnApplyPartition(Assets* assets) {
|
||||||
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
auto* emote_display = dynamic_cast<emote::EmoteDisplay*>(display);
|
||||||
|
if (emote_display && emote_display->GetEmoteHandle() != nullptr) {
|
||||||
|
emote_unmount_assets(emote_display->GetEmoteHandle());
|
||||||
|
}
|
||||||
|
(void)assets; // Unused parameter
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::EmoteStrategy::GetAssetData(Assets* assets, const std::string& name, void*& ptr, size_t& size) {
|
||||||
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
auto* emote_display = dynamic_cast<emote::EmoteDisplay*>(display);
|
||||||
|
if (emote_display && emote_display->GetEmoteHandle() != nullptr) {
|
||||||
|
const uint8_t* data = nullptr;
|
||||||
|
size_t data_size = 0;
|
||||||
|
if (ESP_OK == emote_get_asset_data_by_name(emote_display->GetEmoteHandle(), name.c_str(), &data, &data_size)) {
|
||||||
|
ptr = const_cast<void*>(static_cast<const void*>(data));
|
||||||
|
size = data_size;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ESP_LOGE(TAG, "Failed to get asset data by name: %s", name.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
(void)assets; // Unused parameter
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Assets::EmoteStrategy::Apply(Assets* assets) {
|
||||||
|
Assets::LoadSrmodelsFromIndex(assets);
|
||||||
|
|
||||||
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
|
auto* emote_display = dynamic_cast<emote::EmoteDisplay*>(display);
|
||||||
|
|
||||||
|
if (emote_display && emote_display->GetEmoteHandle() != nullptr) {
|
||||||
|
emote_load_assets(emote_display->GetEmoteHandle());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Assets::Download(std::string url, std::function<void(int progress, size_t speed)> progress_callback) {
|
bool Assets::Download(std::string url, std::function<void(int progress, size_t speed)> progress_callback) {
|
||||||
ESP_LOGI(TAG, "Downloading new version of assets from %s", url.c_str());
|
ESP_LOGI(TAG, "Downloading new version of assets from %s", url.c_str());
|
||||||
|
|
||||||
// 取消当前资源分区的内存映射
|
// 取消当前资源分区的内存映射
|
||||||
if (mmap_handle_ != 0) {
|
UnApplyPartition();
|
||||||
esp_partition_munmap(mmap_handle_);
|
|
||||||
mmap_handle_ = 0;
|
|
||||||
mmap_root_ = nullptr;
|
|
||||||
}
|
|
||||||
checksum_valid_ = false;
|
|
||||||
assets_.clear();
|
|
||||||
|
|
||||||
// 下载新的资源文件
|
// 下载新的资源文件
|
||||||
auto network = Board::GetInstance().GetNetwork();
|
auto network = Board::GetInstance().GetNetwork();
|
||||||
@ -514,19 +548,3 @@ bool Assets::Download(std::string url, std::function<void(int progress, size_t s
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Assets::GetAssetData(const std::string& name, void*& ptr, size_t& size) {
|
|
||||||
auto asset = assets_.find(name);
|
|
||||||
if (asset == assets_.end()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto data = (const char*)(mmap_root_ + asset->second.offset);
|
|
||||||
if (data[0] != 'Z' || data[1] != 'Z') {
|
|
||||||
ESP_LOGE(TAG, "The asset %s is not valid with magic %02x%02x", name.c_str(), data[0], data[1]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = static_cast<void*>(const_cast<char*>(data + 2));
|
|
||||||
size = asset->second.size;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
#ifndef ASSETS_H
|
#ifndef ASSETS_H
|
||||||
#define ASSETS_H
|
#define ASSETS_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <esp_partition.h>
|
#include <esp_partition.h>
|
||||||
#include <model_path.h>
|
#include <model_path.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#if HAVE_LVGL
|
||||||
|
#include <spi_flash_mmap.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct Asset {
|
struct Asset {
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -28,7 +33,6 @@ public:
|
|||||||
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
|
bool GetAssetData(const std::string& name, void*& ptr, size_t& size);
|
||||||
|
|
||||||
inline bool partition_valid() const { return partition_valid_; }
|
inline bool partition_valid() const { return partition_valid_; }
|
||||||
inline bool checksum_valid() const { return checksum_valid_; }
|
|
||||||
inline std::string default_assets_url() const { return default_assets_url_; }
|
inline std::string default_assets_url() const { return default_assets_url_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -37,16 +41,49 @@ private:
|
|||||||
Assets& operator=(const Assets&) = delete;
|
Assets& operator=(const Assets&) = delete;
|
||||||
|
|
||||||
bool InitializePartition();
|
bool InitializePartition();
|
||||||
uint32_t CalculateChecksum(const char* data, uint32_t length);
|
void UnApplyPartition();
|
||||||
|
static bool FindPartition(Assets* assets);
|
||||||
|
static bool LoadSrmodelsFromIndex(Assets* assets, cJSON* root = nullptr);
|
||||||
|
|
||||||
|
class AssetStrategy {
|
||||||
|
public:
|
||||||
|
virtual ~AssetStrategy() = default;
|
||||||
|
virtual bool Apply(Assets* assets) = 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) 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) 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;
|
const esp_partition_t* partition_ = nullptr;
|
||||||
esp_partition_mmap_handle_t mmap_handle_ = 0;
|
|
||||||
const char* mmap_root_ = nullptr;
|
|
||||||
bool partition_valid_ = false;
|
bool partition_valid_ = false;
|
||||||
bool checksum_valid_ = false;
|
|
||||||
std::string default_assets_url_;
|
std::string default_assets_url_;
|
||||||
srmodel_list_t* models_list_ = nullptr;
|
srmodel_list_t* models_list_ = nullptr;
|
||||||
std::map<std::string, Asset> assets_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -471,7 +471,7 @@ private:
|
|||||||
auto &app = Application::GetInstance();
|
auto &app = Application::GetInstance();
|
||||||
auto &board = (EchoEar &)Board::GetInstance();
|
auto &board = (EchoEar &)Board::GetInstance();
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Touch event, TP_PIN_NUM_INT: %d", gpio_get_level(TP_PIN_NUM_INT));
|
ESP_LOGD(TAG, "Touch event, TP_PIN_NUM_INT: %d", gpio_get_level(TP_PIN_NUM_INT));
|
||||||
touchpad->UpdateTouchPoint();
|
touchpad->UpdateTouchPoint();
|
||||||
auto touch_event = touchpad->CheckTouchEvent();
|
auto touch_event = touchpad->CheckTouchEvent();
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
"name": "echoear",
|
"name": "echoear",
|
||||||
"sdkconfig_append": [
|
"sdkconfig_append": [
|
||||||
"CONFIG_USE_EMOTE_MESSAGE_STYLE=y",
|
"CONFIG_USE_EMOTE_MESSAGE_STYLE=y",
|
||||||
"CONFIG_FLASH_CUSTOM_ASSETS=y",
|
"CONFIG_MMAP_FILE_NAME_LENGTH=32",
|
||||||
"CONFIG_CUSTOM_ASSETS_FILE=\"https://dl.espressif.com/AE/wn9_nihaoxiaozhi_tts-font_puhui_common_20_4-echoear.bin\""
|
"CONFIG_FLASH_EXPRESSION_ASSETS=y"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
[
|
|
||||||
{"emote": "happy", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "laughing", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "funny", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "loving", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "embarrassed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confident", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "delicious", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sad", "src": "Sad.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "crying", "src": "cry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sleepy", "src": "sleep.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "silly", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "angry", "src": "angry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "surprised", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "shocked", "src": "shocked.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "thinking", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "winking", "src": "neutral.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "relaxed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confused", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "neutral", "src": "winking.eaf", "loop": false, "fps": 20},
|
|
||||||
{"emote": "idle", "src": "neutral.eaf", "loop": false, "fps": 20}
|
|
||||||
]
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "eye_anim",
|
|
||||||
"align": "GFX_ALIGN_LEFT_MID",
|
|
||||||
"x": 10,
|
|
||||||
"y": 10
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "status_icon",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": -100,
|
|
||||||
"y": 38
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "toast_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 40,
|
|
||||||
"width": 160,
|
|
||||||
"height": 40
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clock_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 40,
|
|
||||||
"width": 60,
|
|
||||||
"height": 50
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "listen_anim",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 25
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
[
|
|
||||||
{"emote": "happy", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "laughing", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "funny", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "loving", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "embarrassed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confident", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "delicious", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sad", "src": "Sad.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "crying", "src": "cry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sleepy", "src": "sleep.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "silly", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "angry", "src": "angry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "surprised", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "shocked", "src": "shocked.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "thinking", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "winking", "src": "neutral.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "relaxed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confused", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "neutral", "src": "winking.eaf", "loop": false, "fps": 20},
|
|
||||||
{"emote": "idle", "src": "neutral.eaf", "loop": false, "fps": 20}
|
|
||||||
]
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "eye_anim",
|
|
||||||
"align": "GFX_ALIGN_LEFT_MID",
|
|
||||||
"x": 10,
|
|
||||||
"y": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "status_icon",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": -120,
|
|
||||||
"y": 18
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "toast_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 20,
|
|
||||||
"width": 200,
|
|
||||||
"height": 40
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clock_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 20,
|
|
||||||
"width": 200,
|
|
||||||
"height": 50
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "listen_anim",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#include "wifi_board.h"
|
#include "wifi_board.h"
|
||||||
#include "codecs/box_audio_codec.h"
|
#include "codecs/box_audio_codec.h"
|
||||||
#include "display/lcd_display.h"
|
#include "display/lcd_display.h"
|
||||||
|
#include "display/emote_display.h"
|
||||||
#include "esp_lcd_ili9341.h"
|
#include "esp_lcd_ili9341.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
@ -38,7 +39,7 @@ class EspBox3Board : public WifiBoard {
|
|||||||
private:
|
private:
|
||||||
i2c_master_bus_handle_t i2c_bus_;
|
i2c_master_bus_handle_t i2c_bus_;
|
||||||
Button boot_button_;
|
Button boot_button_;
|
||||||
LcdDisplay* display_;
|
Display* display_;
|
||||||
|
|
||||||
void InitializeI2c() {
|
void InitializeI2c() {
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
@ -125,8 +126,13 @@ private:
|
|||||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||||
esp_lcd_panel_disp_on_off(panel, true);
|
esp_lcd_panel_disp_on_off(panel, true);
|
||||||
|
|
||||||
|
#if CONFIG_USE_EMOTE_MESSAGE_STYLE
|
||||||
|
display_ = new emote::EmoteDisplay(panel, panel_io, DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||||
|
#else
|
||||||
display_ = new SpiLcdDisplay(panel_io, panel,
|
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
|
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
[
|
|
||||||
{"emote": "happy", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "laughing", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "funny", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "loving", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "embarrassed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confident", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "delicious", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sad", "src": "Sad.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "crying", "src": "cry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "sleepy", "src": "sleep.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "silly", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "angry", "src": "angry.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "surprised", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "shocked", "src": "shocked.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "thinking", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "winking", "src": "neutral.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "relaxed", "src": "Happy.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "confused", "src": "confused.eaf", "loop": true, "fps": 20},
|
|
||||||
{"emote": "neutral", "src": "winking.eaf", "loop": false, "fps": 20},
|
|
||||||
{"emote": "idle", "src": "neutral.eaf", "loop": false, "fps": 20}
|
|
||||||
]
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"name": "eye_anim",
|
|
||||||
"align": "GFX_ALIGN_LEFT_MID",
|
|
||||||
"x": 10,
|
|
||||||
"y": 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "status_icon",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": -120,
|
|
||||||
"y": 18
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "toast_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 20,
|
|
||||||
"width": 200,
|
|
||||||
"height": 40
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clock_label",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 20,
|
|
||||||
"width": 200,
|
|
||||||
"height": 50
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "listen_anim",
|
|
||||||
"align": "GFX_ALIGN_TOP_MID",
|
|
||||||
"x": 0,
|
|
||||||
"y": 5
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
@ -5,6 +5,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// Standard C headers
|
// Standard C headers
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -14,16 +15,18 @@
|
|||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_lcd_panel_io.h>
|
#include <esp_lcd_panel_io.h>
|
||||||
#include <esp_timer.h>
|
#include <esp_timer.h>
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
// FreeRTOS headers
|
// FreeRTOS headers
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
|
||||||
// Project headers
|
// Project headers
|
||||||
#include "assets.h"
|
|
||||||
#include "assets/lang_config.h"
|
#include "assets/lang_config.h"
|
||||||
|
#include "assets.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include "expression_emote.h"
|
||||||
|
|
||||||
LV_FONT_DECLARE(BUILTIN_TEXT_FONT);
|
LV_FONT_DECLARE(BUILTIN_TEXT_FONT);
|
||||||
|
|
||||||
@ -35,153 +38,32 @@ namespace emote {
|
|||||||
|
|
||||||
static const char* TAG = "EmoteDisplay";
|
static const char* TAG = "EmoteDisplay";
|
||||||
|
|
||||||
// UI Element Names - Centralized Management
|
|
||||||
#define UI_ELEMENT_EYE_ANIM "eye_anim"
|
|
||||||
#define UI_ELEMENT_TOAST_LABEL "toast_label"
|
|
||||||
#define UI_ELEMENT_CLOCK_LABEL "clock_label"
|
|
||||||
#define UI_ELEMENT_LISTEN_ANIM "listen_anim"
|
|
||||||
#define UI_ELEMENT_STATUS_ICON "status_icon"
|
|
||||||
|
|
||||||
// Icon Names - Centralized Management
|
|
||||||
#define ICON_MIC "icon_mic"
|
|
||||||
#define ICON_BATTERY "icon_Battery"
|
|
||||||
#define ICON_SPEAKER_ZZZ "icon_speaker_zzz"
|
|
||||||
#define ICON_WIFI_FAILED "icon_WiFi_failed"
|
|
||||||
#define ICON_WIFI_OK "icon_wifi"
|
|
||||||
#define ICON_LISTEN "listen"
|
|
||||||
|
|
||||||
using FlushIoReadyCallback = std::function<bool(esp_lcd_panel_io_handle_t, esp_lcd_panel_io_event_data_t*, void*)>;
|
|
||||||
using FlushCallback = std::function<void(gfx_handle_t, int, int, int, int, const void*)>;
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Global Variables
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
// UI element management
|
|
||||||
static gfx_obj_t* g_obj_label_toast = nullptr;
|
|
||||||
static gfx_obj_t* g_obj_label_clock = nullptr;
|
|
||||||
static gfx_obj_t* g_obj_anim_eye = nullptr;
|
|
||||||
static gfx_obj_t* g_obj_anim_listen = nullptr;
|
|
||||||
static gfx_obj_t* g_obj_img_status = nullptr;
|
|
||||||
|
|
||||||
// Track current icon to determine when to show time
|
|
||||||
static std::string g_current_icon_type = ICON_WIFI_FAILED;
|
|
||||||
static gfx_image_dsc_t g_icon_img_dsc;
|
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
class EmoteDisplay;
|
class EmoteDisplay;
|
||||||
class EmoteEngine;
|
|
||||||
|
|
||||||
enum class UIDisplayMode : uint8_t {
|
|
||||||
SHOW_LISTENING = 1, // Show g_obj_anim_listen
|
|
||||||
SHOW_TIME = 2, // Show g_obj_label_clock
|
|
||||||
SHOW_TIPS = 3 // Show g_obj_label_toast
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Helper Functions
|
// Helper Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// Function to convert align string to GFX_ALIGN enum value
|
static bool OnFlushIoReady(const esp_lcd_panel_io_handle_t panel_io,
|
||||||
char StringToGfxAlign(const std::string &align_str)
|
esp_lcd_panel_io_event_data_t* const edata, void* user_ctx)
|
||||||
{
|
{
|
||||||
static const std::unordered_map<std::string, char> align_map = {
|
emote_handle_t handle = static_cast<emote_handle_t>(user_ctx);
|
||||||
{"GFX_ALIGN_DEFAULT", GFX_ALIGN_DEFAULT},
|
if (handle) {
|
||||||
{"GFX_ALIGN_TOP_LEFT", GFX_ALIGN_TOP_LEFT},
|
emote_notify_flush_finished(handle);
|
||||||
{"GFX_ALIGN_TOP_MID", GFX_ALIGN_TOP_MID},
|
|
||||||
{"GFX_ALIGN_TOP_RIGHT", GFX_ALIGN_TOP_RIGHT},
|
|
||||||
{"GFX_ALIGN_LEFT_MID", GFX_ALIGN_LEFT_MID},
|
|
||||||
{"GFX_ALIGN_CENTER", GFX_ALIGN_CENTER},
|
|
||||||
{"GFX_ALIGN_RIGHT_MID", GFX_ALIGN_RIGHT_MID},
|
|
||||||
{"GFX_ALIGN_BOTTOM_LEFT", GFX_ALIGN_BOTTOM_LEFT},
|
|
||||||
{"GFX_ALIGN_BOTTOM_MID", GFX_ALIGN_BOTTOM_MID},
|
|
||||||
{"GFX_ALIGN_BOTTOM_RIGHT", GFX_ALIGN_BOTTOM_RIGHT},
|
|
||||||
{"GFX_ALIGN_OUT_TOP_LEFT", GFX_ALIGN_OUT_TOP_LEFT},
|
|
||||||
{"GFX_ALIGN_OUT_TOP_MID", GFX_ALIGN_OUT_TOP_MID},
|
|
||||||
{"GFX_ALIGN_OUT_TOP_RIGHT", GFX_ALIGN_OUT_TOP_RIGHT},
|
|
||||||
{"GFX_ALIGN_OUT_LEFT_TOP", GFX_ALIGN_OUT_LEFT_TOP},
|
|
||||||
{"GFX_ALIGN_OUT_LEFT_MID", GFX_ALIGN_OUT_LEFT_MID},
|
|
||||||
{"GFX_ALIGN_OUT_LEFT_BOTTOM", GFX_ALIGN_OUT_LEFT_BOTTOM},
|
|
||||||
{"GFX_ALIGN_OUT_RIGHT_TOP", GFX_ALIGN_OUT_RIGHT_TOP},
|
|
||||||
{"GFX_ALIGN_OUT_RIGHT_MID", GFX_ALIGN_OUT_RIGHT_MID},
|
|
||||||
{"GFX_ALIGN_OUT_RIGHT_BOTTOM", GFX_ALIGN_OUT_RIGHT_BOTTOM},
|
|
||||||
{"GFX_ALIGN_OUT_BOTTOM_LEFT", GFX_ALIGN_OUT_BOTTOM_LEFT},
|
|
||||||
{"GFX_ALIGN_OUT_BOTTOM_MID", GFX_ALIGN_OUT_BOTTOM_MID},
|
|
||||||
{"GFX_ALIGN_OUT_BOTTOM_RIGHT", GFX_ALIGN_OUT_BOTTOM_RIGHT}
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto it = align_map.find(align_str);
|
|
||||||
if (it != align_map.cend()) {
|
|
||||||
return it->second;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
ESP_LOGW(TAG, "Unknown align string: %s, using GFX_ALIGN_DEFAULT", align_str.c_str());
|
|
||||||
return GFX_ALIGN_DEFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// Flush callback for emote
|
||||||
// EmoteEngine Class Declaration
|
static void OnFlushCallback(int x_start, int y_start, int x_end, int y_end, const void* data, emote_handle_t handle)
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
class EmoteEngine {
|
|
||||||
public:
|
|
||||||
EmoteEngine(const esp_lcd_panel_handle_t panel, const esp_lcd_panel_io_handle_t panel_io,
|
|
||||||
const int width, const int height, EmoteDisplay* const display);
|
|
||||||
~EmoteEngine();
|
|
||||||
|
|
||||||
void SetEyes(const std::string &emoji_name, const bool repeat, const int fps, EmoteDisplay* const display);
|
|
||||||
void SetIcon(const std::string &icon_name, EmoteDisplay* const display);
|
|
||||||
|
|
||||||
void* GetEngineHandle() const
|
|
||||||
{
|
|
||||||
return engine_handle_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Callback functions (public to be accessible from static helper functions)
|
|
||||||
static bool OnFlushIoReady(const esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t* const edata, void* const user_ctx);
|
|
||||||
static void OnFlush(const gfx_handle_t handle, const int x_start, const int y_start, const int x_end, const int y_end, const void* const color_data);
|
|
||||||
|
|
||||||
private:
|
|
||||||
gfx_handle_t engine_handle_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// UI Management Functions
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
static void SetUIDisplayMode(const UIDisplayMode mode, EmoteDisplay* const display)
|
|
||||||
{
|
{
|
||||||
if (!display) {
|
esp_lcd_panel_handle_t panel = (esp_lcd_panel_handle_t)emote_get_user_data(handle);
|
||||||
ESP_LOGE(TAG, "SetUIDisplayMode: display is nullptr");
|
if (panel != nullptr) {
|
||||||
return;
|
esp_lcd_panel_draw_bitmap(panel, x_start, y_start, x_end, y_end, data);
|
||||||
}
|
|
||||||
|
|
||||||
gfx_obj_set_visible(g_obj_anim_listen, false);
|
|
||||||
gfx_obj_set_visible(g_obj_label_clock, false);
|
|
||||||
gfx_obj_set_visible(g_obj_label_toast, false);
|
|
||||||
|
|
||||||
// Show the selected control
|
|
||||||
switch (mode) {
|
|
||||||
case UIDisplayMode::SHOW_LISTENING: {
|
|
||||||
gfx_obj_set_visible(g_obj_anim_listen, true);
|
|
||||||
const AssetData emoji_data = display->GetIconData(ICON_LISTEN);
|
|
||||||
if (emoji_data.data) {
|
|
||||||
gfx_anim_set_src(g_obj_anim_listen, emoji_data.data, emoji_data.size);
|
|
||||||
gfx_anim_set_segment(g_obj_anim_listen, 0, 0xFFFF, 20, true);
|
|
||||||
gfx_anim_start(g_obj_anim_listen);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case UIDisplayMode::SHOW_TIME:
|
|
||||||
gfx_obj_set_visible(g_obj_label_clock, true);
|
|
||||||
break;
|
|
||||||
case UIDisplayMode::SHOW_TIPS:
|
|
||||||
gfx_obj_set_visible(g_obj_label_toast, true);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,193 +71,44 @@ static void SetUIDisplayMode(const UIDisplayMode mode, EmoteDisplay* const displ
|
|||||||
// Graphics Initialization Functions
|
// Graphics Initialization Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
static void InitializeGraphics(const esp_lcd_panel_handle_t panel, gfx_handle_t* const engine_handle,
|
static emote_handle_t InitializeEmote(const esp_lcd_panel_handle_t panel, const int width, const int height)
|
||||||
const int width, const int height)
|
|
||||||
{
|
{
|
||||||
if (!panel || !engine_handle) {
|
if (!panel) {
|
||||||
ESP_LOGE(TAG, "InitializeGraphics: Invalid parameters");
|
ESP_LOGE(TAG, "Invalid panel");
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx_core_config_t gfx_cfg = {
|
emote_config_t emote_cfg = {
|
||||||
.flush_cb = EmoteEngine::OnFlush,
|
|
||||||
.user_data = panel,
|
|
||||||
.flags = {
|
.flags = {
|
||||||
.swap = true,
|
.swap = true,
|
||||||
.double_buffer = true,
|
.double_buffer = true,
|
||||||
.buff_dma = true,
|
.buff_dma = false,
|
||||||
|
},
|
||||||
|
.gfx_emote = {
|
||||||
|
.h_res = width,
|
||||||
|
.v_res = height,
|
||||||
|
.fps = 30,
|
||||||
},
|
},
|
||||||
.h_res = static_cast<uint32_t>(width),
|
|
||||||
.v_res = static_cast<uint32_t>(height),
|
|
||||||
.fps = 30,
|
|
||||||
.buffers = {
|
.buffers = {
|
||||||
.buf1 = nullptr,
|
|
||||||
.buf2 = nullptr,
|
|
||||||
.buf_pixels = static_cast<size_t>(width * 16),
|
.buf_pixels = static_cast<size_t>(width * 16),
|
||||||
},
|
},
|
||||||
.task = GFX_EMOTE_INIT_CONFIG()
|
.task = {
|
||||||
|
.task_priority = 5,
|
||||||
|
.task_stack = 6 * 1024,
|
||||||
|
.task_affinity = 0,
|
||||||
|
.task_stack_in_ext = false,
|
||||||
|
},
|
||||||
|
.flush_cb = OnFlushCallback,
|
||||||
|
.user_data = (void*)panel,
|
||||||
};
|
};
|
||||||
|
|
||||||
gfx_cfg.task.task_stack_caps = MALLOC_CAP_DEFAULT;
|
emote_handle_t emote_handle = emote_init(&emote_cfg);
|
||||||
gfx_cfg.task.task_affinity = 0;
|
if (!emote_handle) {
|
||||||
gfx_cfg.task.task_priority = 5;
|
ESP_LOGE(TAG, "Failed to initialize emote");
|
||||||
gfx_cfg.task.task_stack = 8 * 1024;
|
return nullptr;
|
||||||
|
|
||||||
*engine_handle = gfx_emote_init(&gfx_cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetupUI(const gfx_handle_t engine_handle, EmoteDisplay* const display)
|
|
||||||
{
|
|
||||||
if (!display) {
|
|
||||||
ESP_LOGE(TAG, "SetupUI: display is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx_emote_set_bg_color(engine_handle, GFX_COLOR_HEX(0x000000));
|
return emote_handle;
|
||||||
|
|
||||||
g_obj_anim_eye = gfx_anim_create(engine_handle);
|
|
||||||
gfx_obj_align(g_obj_anim_eye, GFX_ALIGN_LEFT_MID, 10, 30);
|
|
||||||
gfx_anim_set_auto_mirror(g_obj_anim_eye, true);
|
|
||||||
gfx_obj_set_visible(g_obj_anim_eye, false);
|
|
||||||
|
|
||||||
g_obj_label_toast = gfx_label_create(engine_handle);
|
|
||||||
gfx_obj_align(g_obj_label_toast, GFX_ALIGN_TOP_MID, 0, 20);
|
|
||||||
gfx_obj_set_size(g_obj_label_toast, 200, 40);
|
|
||||||
gfx_label_set_text(g_obj_label_toast, Lang::Strings::INITIALIZING);
|
|
||||||
gfx_label_set_color(g_obj_label_toast, GFX_COLOR_HEX(0xFFFFFF));
|
|
||||||
gfx_label_set_text_align(g_obj_label_toast, GFX_TEXT_ALIGN_CENTER);
|
|
||||||
gfx_label_set_long_mode(g_obj_label_toast, GFX_LABEL_LONG_SCROLL);
|
|
||||||
gfx_label_set_scroll_speed(g_obj_label_toast, 20);
|
|
||||||
gfx_label_set_scroll_loop(g_obj_label_toast, true);
|
|
||||||
gfx_label_set_font(g_obj_label_toast, (gfx_font_t)&BUILTIN_TEXT_FONT);
|
|
||||||
|
|
||||||
g_obj_label_clock = gfx_label_create(engine_handle);
|
|
||||||
gfx_obj_align(g_obj_label_clock, GFX_ALIGN_TOP_MID, 0, 15);
|
|
||||||
gfx_obj_set_size(g_obj_label_clock, 200, 50);
|
|
||||||
gfx_label_set_text(g_obj_label_clock, "--:--");
|
|
||||||
gfx_label_set_color(g_obj_label_clock, GFX_COLOR_HEX(0xFFFFFF));
|
|
||||||
gfx_label_set_text_align(g_obj_label_clock, GFX_TEXT_ALIGN_CENTER);
|
|
||||||
gfx_label_set_font(g_obj_label_clock, (gfx_font_t)&BUILTIN_TEXT_FONT);
|
|
||||||
|
|
||||||
g_obj_anim_listen = gfx_anim_create(engine_handle);
|
|
||||||
gfx_obj_align(g_obj_anim_listen, GFX_ALIGN_TOP_MID, 0, 5);
|
|
||||||
gfx_anim_start(g_obj_anim_listen);
|
|
||||||
gfx_obj_set_visible(g_obj_anim_listen, false);
|
|
||||||
|
|
||||||
g_obj_img_status = gfx_img_create(engine_handle);
|
|
||||||
gfx_obj_align(g_obj_img_status, GFX_ALIGN_TOP_MID, -120, 18);
|
|
||||||
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, display);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void RegisterCallbacks(const esp_lcd_panel_io_handle_t panel_io, const gfx_handle_t engine_handle)
|
|
||||||
{
|
|
||||||
if (!panel_io) {
|
|
||||||
ESP_LOGE(TAG, "RegisterCallbacks: panel_io is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const esp_lcd_panel_io_callbacks_t cbs = {
|
|
||||||
.on_color_trans_done = EmoteEngine::OnFlushIoReady,
|
|
||||||
};
|
|
||||||
esp_lcd_panel_io_register_event_callbacks(panel_io, &cbs, engine_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// EmoteEngine Class Implementation
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
EmoteEngine::EmoteEngine(const esp_lcd_panel_handle_t panel, const esp_lcd_panel_io_handle_t panel_io,
|
|
||||||
const int width, const int height, EmoteDisplay* const display)
|
|
||||||
{
|
|
||||||
InitializeGraphics(panel, &engine_handle_, width, height);
|
|
||||||
|
|
||||||
if (display) {
|
|
||||||
gfx_emote_lock(engine_handle_);
|
|
||||||
SetupUI(engine_handle_, display);
|
|
||||||
gfx_emote_unlock(engine_handle_);
|
|
||||||
}
|
|
||||||
|
|
||||||
RegisterCallbacks(panel_io, engine_handle_);
|
|
||||||
}
|
|
||||||
|
|
||||||
EmoteEngine::~EmoteEngine()
|
|
||||||
{
|
|
||||||
if (engine_handle_) {
|
|
||||||
gfx_emote_deinit(engine_handle_);
|
|
||||||
engine_handle_ = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteEngine::SetEyes(const std::string &emoji_name, const bool repeat, const int fps, EmoteDisplay* const display)
|
|
||||||
{
|
|
||||||
if (!engine_handle_) {
|
|
||||||
ESP_LOGE(TAG, "SetEyes: engine_handle_ is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!display) {
|
|
||||||
ESP_LOGE(TAG, "SetEyes: display is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AssetData emoji_data = display->GetEmojiData(emoji_name);
|
|
||||||
if (emoji_data.data) {
|
|
||||||
DisplayLockGuard lock(display);
|
|
||||||
gfx_anim_set_src(g_obj_anim_eye, emoji_data.data, emoji_data.size);
|
|
||||||
gfx_anim_set_segment(g_obj_anim_eye, 0, 0xFFFF, fps, repeat);
|
|
||||||
gfx_obj_set_visible(g_obj_anim_eye, true);
|
|
||||||
gfx_anim_start(g_obj_anim_eye);
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "SetEyes: No emoji data found for %s", emoji_name.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteEngine::SetIcon(const std::string &icon_name, EmoteDisplay* const display)
|
|
||||||
{
|
|
||||||
if (!engine_handle_) {
|
|
||||||
ESP_LOGE(TAG, "SetIcon: engine_handle_ is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!display) {
|
|
||||||
ESP_LOGE(TAG, "SetIcon: display is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const AssetData icon_data = display->GetIconData(icon_name);
|
|
||||||
if (icon_data.data) {
|
|
||||||
DisplayLockGuard lock(display);
|
|
||||||
|
|
||||||
std::memcpy(&g_icon_img_dsc.header, icon_data.data, sizeof(gfx_image_header_t));
|
|
||||||
g_icon_img_dsc.data = static_cast<const uint8_t*>(icon_data.data) + sizeof(gfx_image_header_t);
|
|
||||||
g_icon_img_dsc.data_size = icon_data.size - sizeof(gfx_image_header_t);
|
|
||||||
|
|
||||||
gfx_img_set_src(g_obj_img_status, &g_icon_img_dsc);
|
|
||||||
} else {
|
|
||||||
ESP_LOGW(TAG, "SetIcon: No icon data found for %s", icon_name.c_str());
|
|
||||||
}
|
|
||||||
g_current_icon_type = icon_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool EmoteEngine::OnFlushIoReady(const esp_lcd_panel_io_handle_t panel_io,
|
|
||||||
esp_lcd_panel_io_event_data_t* const edata,
|
|
||||||
void* const user_ctx)
|
|
||||||
{
|
|
||||||
gfx_handle_t handle = static_cast<gfx_handle_t>(user_ctx);
|
|
||||||
if (handle) {
|
|
||||||
gfx_emote_flush_ready(handle, true);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteEngine::OnFlush(const gfx_handle_t handle, const int x_start, const int y_start,
|
|
||||||
const int x_end, const int y_end, const void* const color_data)
|
|
||||||
{
|
|
||||||
auto* const panel = static_cast<esp_lcd_panel_handle_t>(gfx_emote_get_user_data(handle));
|
|
||||||
if (panel) {
|
|
||||||
esp_lcd_panel_draw_bitmap(panel, x_start, y_start, x_end, y_end, color_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -385,131 +118,84 @@ void EmoteEngine::OnFlush(const gfx_handle_t handle, const int x_start, const in
|
|||||||
EmoteDisplay::EmoteDisplay(const esp_lcd_panel_handle_t panel, const esp_lcd_panel_io_handle_t panel_io,
|
EmoteDisplay::EmoteDisplay(const esp_lcd_panel_handle_t panel, const esp_lcd_panel_io_handle_t panel_io,
|
||||||
const int width, const int height)
|
const int width, const int height)
|
||||||
{
|
{
|
||||||
InitializeEngine(panel, panel_io, width, height);
|
emote_handle_ = InitializeEmote(panel, width, height);
|
||||||
|
|
||||||
|
const esp_lcd_panel_io_callbacks_t cbs = {
|
||||||
|
.on_color_trans_done = OnFlushIoReady,
|
||||||
|
};
|
||||||
|
esp_lcd_panel_io_register_event_callbacks(panel_io, &cbs, emote_handle_);
|
||||||
}
|
}
|
||||||
|
|
||||||
EmoteDisplay::~EmoteDisplay() = default;
|
EmoteDisplay::~EmoteDisplay()
|
||||||
|
{
|
||||||
|
if (emote_handle_) {
|
||||||
|
emote_deinit(emote_handle_);
|
||||||
|
emote_handle_ = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EmoteDisplay::SetEmotion(const char* const emotion)
|
void EmoteDisplay::SetEmotion(const char* const emotion)
|
||||||
{
|
{
|
||||||
if (!emotion) {
|
|
||||||
ESP_LOGE(TAG, "SetEmotion: emotion is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SetEmotion: %s", emotion);
|
ESP_LOGI(TAG, "SetEmotion: %s", emotion);
|
||||||
if (!engine_) {
|
if (emote_handle_ && emotion && strlen(emotion) > 0) {
|
||||||
return;
|
emote_set_anim_emoji(emote_handle_, emotion);
|
||||||
}
|
}
|
||||||
|
|
||||||
const AssetData emoji_data = GetEmojiData(emotion);
|
|
||||||
bool repeat = emoji_data.loop;
|
|
||||||
int fps = emoji_data.fps > 0 ? emoji_data.fps : 20;
|
|
||||||
|
|
||||||
if (std::strcmp(emotion, "idle") == 0 || std::strcmp(emotion, "neutral") == 0) {
|
|
||||||
repeat = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
engine_->SetEyes(emotion, repeat, fps, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::SetChatMessage(const char* const role, const char* const content)
|
void EmoteDisplay::SetChatMessage(const char* const role, const char* const content)
|
||||||
{
|
{
|
||||||
if (!engine_) {
|
ESP_LOGI(TAG, "SetChatMessage: %s, %s", role, content);
|
||||||
return;
|
if (emote_handle_ && content && strlen(content) > 0) {
|
||||||
}
|
if ((std::strcmp(role, "system") == 0) && std::strstr(content, "xiaozhi.me")) {
|
||||||
|
size_t len = strlen(content);
|
||||||
DisplayLockGuard lock(this);
|
char* new_content = new char[len + 1];
|
||||||
if (content && strlen(content) > 0) {
|
strcpy(new_content, content);
|
||||||
gfx_label_set_text(g_obj_label_toast, content);
|
std::replace(new_content, new_content + len, static_cast<char>(0x0A), static_cast<char>(0x20));
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, this);
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_SYS, new_content);
|
||||||
|
delete[] new_content;
|
||||||
|
} else {
|
||||||
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_SPEAK, content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::SetStatus(const char* const status)
|
void EmoteDisplay::SetStatus(const char* const status)
|
||||||
{
|
{
|
||||||
if (!status) {
|
ESP_LOGI(TAG, "SetStatus: %s", status);
|
||||||
ESP_LOGE(TAG, "SetStatus: status is nullptr");
|
if (emote_handle_ && status && strlen(status) > 0) {
|
||||||
return;
|
if (std::strcmp(status, Lang::Strings::LISTENING) == 0) {
|
||||||
}
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_LISTEN, NULL);
|
||||||
|
} else if (std::strcmp(status, Lang::Strings::STANDBY) == 0) {
|
||||||
if (!engine_) {
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_IDLE, NULL);
|
||||||
return;
|
} else if (std::strcmp(status, Lang::Strings::SPEAKING) == 0) {
|
||||||
}
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_SPEAK, NULL);
|
||||||
|
} else if (std::strcmp(status, Lang::Strings::ERROR) == 0) {
|
||||||
DisplayLockGuard lock(this);
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_SET, NULL);
|
||||||
|
}
|
||||||
if (std::strcmp(status, Lang::Strings::LISTENING) == 0) {
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_LISTENING, this);
|
|
||||||
engine_->SetEyes("happy", true, 20, this);
|
|
||||||
engine_->SetIcon(ICON_MIC, this);
|
|
||||||
} else if (std::strcmp(status, Lang::Strings::STANDBY) == 0) {
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIME, this);
|
|
||||||
engine_->SetIcon(ICON_BATTERY, this);
|
|
||||||
} else if (std::strcmp(status, Lang::Strings::SPEAKING) == 0) {
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, this);
|
|
||||||
engine_->SetIcon(ICON_SPEAKER_ZZZ, this);
|
|
||||||
} else if (std::strcmp(status, Lang::Strings::ERROR) == 0) {
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, this);
|
|
||||||
engine_->SetIcon(ICON_WIFI_FAILED, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::strcmp(status, Lang::Strings::CONNECTING) != 0) {
|
|
||||||
gfx_label_set_text(g_obj_label_toast, status);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::ShowNotification(const char* notification, int duration_ms)
|
void EmoteDisplay::ShowNotification(const char* notification, int duration_ms)
|
||||||
{
|
{
|
||||||
if (!notification || !engine_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ESP_LOGI(TAG, "ShowNotification: %s", notification);
|
ESP_LOGI(TAG, "ShowNotification: %s", notification);
|
||||||
|
if (emote_handle_ && notification && strlen(notification) > 0) {
|
||||||
DisplayLockGuard lock(this);
|
emote_set_event_msg(emote_handle_, EMOTE_MGR_EVT_SYS, notification);
|
||||||
gfx_label_set_text(g_obj_label_toast, notification);
|
}
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::UpdateStatusBar(bool update_all)
|
void EmoteDisplay::UpdateStatusBar(bool update_all)
|
||||||
{
|
{
|
||||||
if (!engine_) {
|
ESP_LOGD(TAG, "UpdateStatusBar: %s", update_all ? "true" : "false");
|
||||||
|
if (!emote_handle_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only display time when battery icon is shown
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
if (g_current_icon_type == ICON_BATTERY) {
|
|
||||||
time_t now;
|
|
||||||
struct tm timeinfo;
|
|
||||||
time(&now);
|
|
||||||
|
|
||||||
setenv("TZ", "GMT+0", 1);
|
|
||||||
tzset();
|
|
||||||
localtime_r(&now, &timeinfo);
|
|
||||||
|
|
||||||
char time_str[6];
|
|
||||||
snprintf(time_str, sizeof(time_str), "%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min);
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
gfx_label_set_text(g_obj_label_clock, time_str);
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIME, this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::SetPowerSaveMode(bool on)
|
void EmoteDisplay::SetPowerSaveMode(bool on)
|
||||||
{
|
{
|
||||||
if (!engine_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
ESP_LOGI(TAG, "SetPowerSaveMode: %s", on ? "ON" : "OFF");
|
ESP_LOGI(TAG, "SetPowerSaveMode: %s", on ? "ON" : "OFF");
|
||||||
if (on) {
|
if (!emote_handle_) {
|
||||||
gfx_anim_stop(g_obj_anim_eye);
|
return;
|
||||||
} else {
|
|
||||||
gfx_anim_start(g_obj_anim_eye);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,141 +203,47 @@ void EmoteDisplay::SetPreviewImage(const void* image)
|
|||||||
{
|
{
|
||||||
if (image) {
|
if (image) {
|
||||||
ESP_LOGI(TAG, "SetPreviewImage: Preview image not supported, using default icon");
|
ESP_LOGI(TAG, "SetPreviewImage: Preview image not supported, using default icon");
|
||||||
if (engine_) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::SetTheme(Theme* const theme)
|
void EmoteDisplay::SetTheme(Theme* const theme)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "SetTheme: %p", theme);
|
ESP_LOGI(TAG, "SetTheme: %p", theme);
|
||||||
|
|
||||||
}
|
|
||||||
void EmoteDisplay::AddEmojiData(const std::string &name, const void* const data, const size_t size,
|
|
||||||
uint8_t fps, bool loop, bool lack)
|
|
||||||
{
|
|
||||||
emoji_data_map_[name] = AssetData(data, size, fps, loop, lack);
|
|
||||||
ESP_LOGD(TAG, "Added emoji data: %s, size: %d, fps: %d, loop: %s, lack: %s",
|
|
||||||
name.c_str(), size, fps, loop ? "true" : "false", lack ? "true" : "false");
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
if (name == "happy") {
|
|
||||||
engine_->SetEyes("happy", loop, fps > 0 ? fps : 20, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteDisplay::AddIconData(const std::string &name, const void* const data, const size_t size)
|
|
||||||
{
|
|
||||||
icon_data_map_[name] = AssetData(data, size);
|
|
||||||
ESP_LOGD(TAG, "Added icon data: %s, size: %d", name.c_str(), size);
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
if (name == ICON_WIFI_FAILED) {
|
|
||||||
SetUIDisplayMode(UIDisplayMode::SHOW_TIPS, this);
|
|
||||||
engine_->SetIcon(ICON_WIFI_FAILED, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteDisplay::AddLayoutData(const std::string &name, const std::string &align_str,
|
|
||||||
const int x, const int y, const int width, const int height)
|
|
||||||
{
|
|
||||||
const char align_enum = StringToGfxAlign(align_str);
|
|
||||||
ESP_LOGI(TAG, "layout: %-12s | %-20s(%d) | %4d, %4d | %4dx%-4d",
|
|
||||||
name.c_str(), align_str.c_str(), align_enum, x, y, width, height);
|
|
||||||
|
|
||||||
struct UIElement {
|
|
||||||
gfx_obj_t* obj;
|
|
||||||
const char* name;
|
|
||||||
};
|
|
||||||
|
|
||||||
const UIElement elements[] = {
|
|
||||||
{g_obj_anim_eye, UI_ELEMENT_EYE_ANIM},
|
|
||||||
{g_obj_label_toast, UI_ELEMENT_TOAST_LABEL},
|
|
||||||
{g_obj_label_clock, UI_ELEMENT_CLOCK_LABEL},
|
|
||||||
{g_obj_anim_listen, UI_ELEMENT_LISTEN_ANIM},
|
|
||||||
{g_obj_img_status, UI_ELEMENT_STATUS_ICON}
|
|
||||||
};
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
for (const auto &element : elements) {
|
|
||||||
if (name == element.name && element.obj) {
|
|
||||||
gfx_obj_align(element.obj, align_enum, x, y);
|
|
||||||
if (width > 0 && height > 0) {
|
|
||||||
gfx_obj_set_size(element.obj, width, height);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGW(TAG, "AddLayoutData: UI element '%s' not found", name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteDisplay::AddTextFont(std::shared_ptr<LvglFont> text_font)
|
|
||||||
{
|
|
||||||
if (!text_font) {
|
|
||||||
ESP_LOGW(TAG, "AddTextFont: text_font is nullptr");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
text_font_ = text_font;
|
|
||||||
ESP_LOGD(TAG, "AddTextFont: Text font added successfully");
|
|
||||||
|
|
||||||
DisplayLockGuard lock(this);
|
|
||||||
if (g_obj_label_toast && text_font_) {
|
|
||||||
gfx_label_set_font(g_obj_label_toast, const_cast<void*>(static_cast<const void*>(text_font_->font())));
|
|
||||||
}
|
|
||||||
if (g_obj_label_clock && text_font_) {
|
|
||||||
gfx_label_set_font(g_obj_label_clock, const_cast<void*>(static_cast<const void*>(text_font_->font())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetData EmoteDisplay::GetEmojiData(const std::string &name) const
|
|
||||||
{
|
|
||||||
const auto it = emoji_data_map_.find(name);
|
|
||||||
if (it != emoji_data_map_.cend()) {
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
return AssetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetData EmoteDisplay::GetIconData(const std::string &name) const
|
|
||||||
{
|
|
||||||
const auto it = icon_data_map_.find(name);
|
|
||||||
if (it != icon_data_map_.cend()) {
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
return AssetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
EmoteEngine* EmoteDisplay::GetEngine() const
|
|
||||||
{
|
|
||||||
return engine_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
void* EmoteDisplay::GetEngineHandle() const
|
|
||||||
{
|
|
||||||
return engine_ ? engine_->GetEngineHandle() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmoteDisplay::InitializeEngine(const esp_lcd_panel_handle_t panel, const esp_lcd_panel_io_handle_t panel_io,
|
|
||||||
const int width, const int height)
|
|
||||||
{
|
|
||||||
engine_ = std::make_unique<EmoteEngine>(panel, panel_io, width, height, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmoteDisplay::Lock(const int timeout_ms)
|
bool EmoteDisplay::Lock(const int timeout_ms)
|
||||||
{
|
{
|
||||||
if (engine_ && engine_->GetEngineHandle()) {
|
(void)timeout_ms;
|
||||||
gfx_emote_lock(engine_->GetEngineHandle());
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteDisplay::Unlock()
|
void EmoteDisplay::Unlock()
|
||||||
{
|
{
|
||||||
if (engine_ && engine_->GetEngineHandle()) {
|
}
|
||||||
gfx_emote_unlock(engine_->GetEngineHandle());
|
|
||||||
|
bool EmoteDisplay::StopAnimDialog()
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "StopAnimDialog");
|
||||||
|
if (emote_handle_) {
|
||||||
|
return emote_stop_anim_dialog(emote_handle_);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EmoteDisplay::InsertAnimDialog(const char* emoji_name, uint32_t duration_ms)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "InsertAnimDialog: %s, %d", emoji_name, duration_ms);
|
||||||
|
if (emote_handle_ && emoji_name) {
|
||||||
|
return emote_insert_anim_dialog(emote_handle_, emoji_name, duration_ms);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmoteDisplay::RefreshAll()
|
||||||
|
{
|
||||||
|
if (emote_handle_) {
|
||||||
|
emote_notify_all_refresh(emote_handle_);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,59 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "lvgl_font.h"
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <esp_lcd_panel_io.h>
|
#include <esp_lcd_panel_io.h>
|
||||||
#include <esp_lcd_panel_ops.h>
|
#include <esp_lcd_panel_ops.h>
|
||||||
|
#include "expression_emote.h"
|
||||||
|
|
||||||
namespace emote {
|
namespace emote {
|
||||||
|
|
||||||
// Simple data structure for storing asset data without LVGL dependency
|
|
||||||
struct AssetData {
|
|
||||||
const void* data;
|
|
||||||
size_t size;
|
|
||||||
union {
|
|
||||||
uint8_t flags; // 1 byte for all animation flags
|
|
||||||
struct {
|
|
||||||
uint8_t fps : 6; // FPS (0-63) - 6 bits
|
|
||||||
uint8_t loop : 1; // Loop animation - 1 bit
|
|
||||||
uint8_t lack : 1; // Lack animation - 1 bit
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
AssetData() : data(nullptr), size(0), flags(0) {}
|
|
||||||
AssetData(const void* d, size_t s) : data(d), size(s), flags(0) {}
|
|
||||||
AssetData(const void* d, size_t s, uint8_t f, bool l, bool k)
|
|
||||||
: data(d), size(s)
|
|
||||||
{
|
|
||||||
fps = f > 63 ? 63 : f; // 限制 FPS 到 6 位范围
|
|
||||||
loop = l;
|
|
||||||
lack = k;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Layout element data structure
|
|
||||||
struct LayoutData {
|
|
||||||
char align; // Store as char instead of string
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
bool has_size;
|
|
||||||
|
|
||||||
LayoutData() : align(0), x(0), y(0), width(0), height(0), has_size(false) {}
|
|
||||||
LayoutData(char a, int x_pos, int y_pos, int w = 0, int h = 0)
|
|
||||||
: align(a), x(x_pos), y(y_pos), width(w), height(h), has_size(w > 0 && h > 0) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function to convert align string to GFX_ALIGN enum value
|
|
||||||
char StringToGfxAlign(const std::string &align_str);
|
|
||||||
|
|
||||||
class EmoteEngine;
|
|
||||||
|
|
||||||
class EmoteDisplay : public Display {
|
class EmoteDisplay : public Display {
|
||||||
public:
|
public:
|
||||||
EmoteDisplay(esp_lcd_panel_handle_t panel, esp_lcd_panel_io_handle_t panel_io, int width, int height);
|
EmoteDisplay(esp_lcd_panel_handle_t panel, esp_lcd_panel_io_handle_t panel_io, int width, int height);
|
||||||
@ -68,34 +23,19 @@ public:
|
|||||||
virtual void SetPowerSaveMode(bool on) override;
|
virtual void SetPowerSaveMode(bool on) override;
|
||||||
virtual void SetPreviewImage(const void* image);
|
virtual void SetPreviewImage(const void* image);
|
||||||
|
|
||||||
void AddEmojiData(const std::string &name, const void* data, size_t size, uint8_t fps = 0, bool loop = false, bool lack = false);
|
bool StopAnimDialog();
|
||||||
void AddIconData(const std::string &name, const void* data, size_t size);
|
bool InsertAnimDialog(const char* emoji_name, uint32_t duration_ms);
|
||||||
void AddLayoutData(const std::string &name, const std::string &align_str, int x, int y, int width = 0, int height = 0);
|
|
||||||
void AddTextFont(std::shared_ptr<LvglFont> text_font);
|
|
||||||
AssetData GetEmojiData(const std::string &name) const;
|
|
||||||
AssetData GetIconData(const std::string &name) const;
|
|
||||||
|
|
||||||
EmoteEngine* GetEngine() const;
|
void RefreshAll();
|
||||||
void* GetEngineHandle() const;
|
|
||||||
|
|
||||||
inline std::shared_ptr<LvglFont> text_font() const
|
// Get emote handle for internal use
|
||||||
{
|
emote_handle_t GetEmoteHandle() const { return emote_handle_; }
|
||||||
return text_font_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitializeEngine(esp_lcd_panel_handle_t panel, esp_lcd_panel_io_handle_t panel_io, int width, int height);
|
|
||||||
virtual bool Lock(int timeout_ms = 0) override;
|
virtual bool Lock(int timeout_ms = 0) override;
|
||||||
virtual void Unlock() override;
|
virtual void Unlock() override;
|
||||||
|
|
||||||
std::unique_ptr<EmoteEngine> engine_;
|
emote_handle_t emote_handle_ = nullptr;
|
||||||
|
|
||||||
// Font management
|
|
||||||
std::shared_ptr<LvglFont> text_font_ = nullptr;
|
|
||||||
|
|
||||||
// Non-LVGL asset data storage
|
|
||||||
std::map<std::string, AssetData> emoji_data_map_;
|
|
||||||
std::map<std::string, AssetData> icon_data_map_;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ dependencies:
|
|||||||
esp_lvgl_port: ~2.6.0
|
esp_lvgl_port: ~2.6.0
|
||||||
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
|
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
|
||||||
espressif2022/image_player: ^1.1.1
|
espressif2022/image_player: ^1.1.1
|
||||||
espressif2022/esp_emote_gfx: ==2.0.0
|
espressif2022/esp_emote_expression: ^0.1.0
|
||||||
espressif/adc_mic: ^0.2.1
|
espressif/adc_mic: ^0.2.1
|
||||||
espressif/esp_mmap_assets: '>=1.2'
|
espressif/esp_mmap_assets: '>=1.2'
|
||||||
txp666/otto-emoji-gif-component:
|
txp666/otto-emoji-gif-component:
|
||||||
|
|||||||
@ -15,8 +15,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import argparse
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_dir(directory):
|
def ensure_dir(directory):
|
||||||
@ -31,7 +29,7 @@ def get_file_path(base_dir, filename):
|
|||||||
return os.path.join(base_dir, f"{filename}.bin" if not filename.startswith("emojis_") else filename)
|
return os.path.join(base_dir, f"{filename}.bin" if not filename.startswith("emojis_") else filename)
|
||||||
|
|
||||||
|
|
||||||
def build_assets(wakenet_model, text_font, emoji_collection, target_board, build_dir, final_dir):
|
def build_assets(wakenet_model, text_font, emoji_collection, build_dir, final_dir):
|
||||||
"""Build assets.bin using build.py with given parameters"""
|
"""Build assets.bin using build.py with given parameters"""
|
||||||
|
|
||||||
# Prepare arguments for build.py
|
# Prepare arguments for build.py
|
||||||
@ -48,15 +46,8 @@ def build_assets(wakenet_model, text_font, emoji_collection, target_board, build
|
|||||||
if emoji_collection != "none":
|
if emoji_collection != "none":
|
||||||
emoji_path = os.path.join("../../components/xiaozhi-fonts/build", emoji_collection)
|
emoji_path = os.path.join("../../components/xiaozhi-fonts/build", emoji_collection)
|
||||||
cmd.extend(["--emoji_collection", emoji_path])
|
cmd.extend(["--emoji_collection", emoji_path])
|
||||||
|
|
||||||
if target_board != "none":
|
|
||||||
res_path = os.path.join("../../managed_components/espressif2022__esp_emote_gfx/emoji_large", "")
|
|
||||||
cmd.extend(["--res_path", res_path])
|
|
||||||
|
|
||||||
target_board_path = os.path.join("../../main/boards/", f"{target_board}")
|
|
||||||
cmd.extend(["--target_board", target_board_path])
|
|
||||||
|
|
||||||
print(f"\n正在构建: {wakenet_model}-{text_font}-{emoji_collection}-{target_board}")
|
print(f"\n正在构建: {wakenet_model}-{text_font}-{emoji_collection}")
|
||||||
print(f"执行命令: {' '.join(cmd)}")
|
print(f"执行命令: {' '.join(cmd)}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -64,10 +55,7 @@ def build_assets(wakenet_model, text_font, emoji_collection, target_board, build
|
|||||||
result = subprocess.run(cmd, check=True, cwd=os.path.dirname(__file__))
|
result = subprocess.run(cmd, check=True, cwd=os.path.dirname(__file__))
|
||||||
|
|
||||||
# Generate output filename
|
# Generate output filename
|
||||||
if(target_board != "none"):
|
output_name = f"{wakenet_model}-{text_font}-{emoji_collection}.bin"
|
||||||
output_name = f"{wakenet_model}-{text_font}-{target_board}.bin"
|
|
||||||
else:
|
|
||||||
output_name = f"{wakenet_model}-{text_font}-{emoji_collection}.bin"
|
|
||||||
|
|
||||||
# Copy generated assets.bin to final directory with new name
|
# Copy generated assets.bin to final directory with new name
|
||||||
src_path = os.path.join(build_dir, "assets.bin")
|
src_path = os.path.join(build_dir, "assets.bin")
|
||||||
@ -90,15 +78,6 @@ def build_assets(wakenet_model, text_font, emoji_collection, target_board, build
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Parse command line arguments
|
|
||||||
parser = argparse.ArgumentParser(description='构建多个 SPIFFS assets 分区')
|
|
||||||
parser.add_argument('--mode',
|
|
||||||
choices=['emoji_collections', 'emoji_target_boards'],
|
|
||||||
default='emoji_collections',
|
|
||||||
help='选择运行模式: emoji_collections 或 emoji_target_boards (默认: emoji_collections)')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
wakenet_models = [
|
wakenet_models = [
|
||||||
"none",
|
"none",
|
||||||
@ -119,11 +98,6 @@ def main():
|
|||||||
"emojis_32",
|
"emojis_32",
|
||||||
"emojis_64",
|
"emojis_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
emoji_target_boards = [
|
|
||||||
"esp-box-3",
|
|
||||||
"echoear",
|
|
||||||
]
|
|
||||||
|
|
||||||
# Get script directory
|
# Get script directory
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
@ -137,33 +111,20 @@ def main():
|
|||||||
ensure_dir(final_dir)
|
ensure_dir(final_dir)
|
||||||
|
|
||||||
print("开始构建多个 SPIFFS assets 分区...")
|
print("开始构建多个 SPIFFS assets 分区...")
|
||||||
print(f"运行模式: {args.mode}")
|
|
||||||
print(f"输出目录: {final_dir}")
|
print(f"输出目录: {final_dir}")
|
||||||
|
|
||||||
|
# Calculate total combinations
|
||||||
|
total_combinations = len(wakenet_models) * len(text_fonts) * len(emoji_collections)
|
||||||
|
|
||||||
# Track successful builds
|
# Track successful builds
|
||||||
successful_builds = 0
|
successful_builds = 0
|
||||||
|
|
||||||
if args.mode == 'emoji_collections':
|
# Build all combinations with emoji_collections
|
||||||
# Calculate total combinations for emoji_collections mode
|
for wakenet_model in wakenet_models:
|
||||||
total_combinations = len(wakenet_models) * len(text_fonts) * len(emoji_collections)
|
for text_font in text_fonts:
|
||||||
|
for emoji_collection in emoji_collections:
|
||||||
# Build all combinations with emoji_collections
|
if build_assets(wakenet_model, text_font, emoji_collection, build_dir, final_dir):
|
||||||
for wakenet_model in wakenet_models:
|
successful_builds += 1
|
||||||
for text_font in text_fonts:
|
|
||||||
for emoji_collection in emoji_collections:
|
|
||||||
if build_assets(wakenet_model, text_font, emoji_collection, "none", build_dir, final_dir):
|
|
||||||
successful_builds += 1
|
|
||||||
|
|
||||||
elif args.mode == 'emoji_target_boards':
|
|
||||||
# Calculate total combinations for emoji_target_boards mode
|
|
||||||
total_combinations = len(wakenet_models) * len(text_fonts) * len(emoji_target_boards)
|
|
||||||
|
|
||||||
# Build all combinations with emoji_target_boards
|
|
||||||
for wakenet_model in wakenet_models:
|
|
||||||
for text_font in text_fonts:
|
|
||||||
for emoji_target_board in emoji_target_boards:
|
|
||||||
if build_assets(wakenet_model, text_font, "none", emoji_target_board, build_dir, final_dir):
|
|
||||||
successful_builds += 1
|
|
||||||
|
|
||||||
print(f"\n构建完成!")
|
print(f"\n构建完成!")
|
||||||
print(f"成功构建: {successful_builds}/{total_combinations}")
|
print(f"成功构建: {successful_builds}/{total_combinations}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user