add iot command for theme switch (#364)

This commit is contained in:
ZhouKe
2025-03-18 21:00:54 +08:00
committed by GitHub
parent 13fd170a89
commit 61cc1a236b
7 changed files with 401 additions and 67 deletions
+1 -7
View File
@@ -216,13 +216,7 @@ config USE_WECHAT_MESSAGE_STYLE
bool "使用微信聊天界面风格"
default n
help
使用微信聊天界面风格
config USE_DARK_MODE
bool "使用深色模式"
default n
help
使用深色模式
使用微信聊天界面风格
config USE_AUDIO_PROCESSOR
bool "启用音频降噪、增益处理"
@@ -155,6 +155,7 @@ private:
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
thing_manager.AddThing(iot::CreateThing("Backlight"));
}
thing_manager.AddThing(iot::CreateThing("Screen"));
}
public:
@@ -122,7 +122,11 @@ private:
{
.text_font = &font_puhui_20_4,
.icon_font = &font_awesome_20_4,
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
.emoji_font = font_emoji_32_init(),
#else
.emoji_font = font_emoji_64_init(),
#endif
});
}
@@ -131,6 +135,7 @@ private:
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
thing_manager.AddThing(iot::CreateThing("Backlight"));
thing_manager.AddThing(iot::CreateThing("Screen"));
}
public:
+2
View File
@@ -25,6 +25,8 @@ public:
virtual void SetEmotion(const char* emotion);
virtual void SetChatMessage(const char* role, const char* content);
virtual void SetIcon(const char* icon);
virtual void SetTheme(const std::string& theme_name){}
virtual std::string GetTheme() { return "light"; }
inline int width() const { return width_; }
inline int height() const { return height_; }
File diff suppressed because it is too large Load Diff
+4
View File
@@ -38,6 +38,10 @@ public:
#if CONFIG_USE_WECHAT_MESSAGE_STYLE
virtual void SetChatMessage(const char* role, const char* content) override;
#endif
// Add theme switching function
virtual void SetTheme(const std::string& theme_name) override;
virtual std::string GetTheme() override;
};
// RGB LCD显示器
+38
View File
@@ -0,0 +1,38 @@
#include "iot/thing.h"
#include "board.h"
#include "display/lcd_display.h"
#include "settings.h"
#include <esp_log.h>
#include <string>
#define TAG "Screen"
namespace iot {
// 这里仅定义 Screen 的属性和方法,不包含具体的实现
class Screen : public Thing {
public:
Screen() : Thing("Screen", "这是一个屏幕,可设置主题") {
// 定义设备的属性
properties_.AddStringProperty("theme", "主题", [this]() -> std::string {
auto theme = Board::GetInstance().GetDisplay()->GetTheme();
return theme;
});
// 定义设备可以被远程执行的指令
methods_.AddMethod("SetTheme", "设置屏幕主题", ParameterList({
Parameter("theme_name", "主题模式, light 或 dark", kValueTypeString, true)
}), [this](const ParameterList& parameters) {
std::string theme_name = static_cast<std::string>(parameters["theme_name"].string());
auto display = Board::GetInstance().GetDisplay();
if (display) {
display->SetTheme(theme_name);
}
});
}
};
} // namespace iot
DECLARE_THING(Screen);