forked from xiaozhi/xiaozhi-esp32
Add theme switch to all LCD boards
This commit is contained in:
@@ -277,7 +277,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ private:
|
|||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,11 +151,8 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
|
||||||
if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) {
|
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
||||||
}
|
|
||||||
thing_manager.AddThing(iot::CreateThing("Screen"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
|
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Battery"));
|
thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Chassis"));
|
thing_manager.AddThing(iot::CreateThing("Chassis"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -230,9 +230,9 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("BoardControl"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
||||||
thing_manager.AddThing(iot::CreateThing("Battery"));
|
thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||||
|
thing_manager.AddThing(iot::CreateThing("BoardControl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
thing_manager.AddThing(iot::CreateThing("Lamp"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
||||||
thing_manager.AddThing(iot::CreateThing("Screen"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Battery"));
|
thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
}
|
}
|
||||||
void InitializeMute() {
|
void InitializeMute() {
|
||||||
gpio_reset_pin(AUDIO_MUTE_PIN);
|
gpio_reset_pin(AUDIO_MUTE_PIN);
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Battery"));
|
thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ private:
|
|||||||
void InitializeIot() {
|
void InitializeIot() {
|
||||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
thing_manager.AddThing(iot::CreateThing("Screen"));
|
||||||
thing_manager.AddThing(iot::CreateThing("Battery"));
|
thing_manager.AddThing(iot::CreateThing("Battery"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
#define TAG "Display"
|
#define TAG "Display"
|
||||||
|
|
||||||
Display::Display() {
|
Display::Display() {
|
||||||
|
// Load theme from settings
|
||||||
|
Settings settings("display", false);
|
||||||
|
current_theme_name_ = settings.GetString("theme", "light");
|
||||||
|
|
||||||
// Notification timer
|
// Notification timer
|
||||||
esp_timer_create_args_t notification_timer_args = {
|
esp_timer_create_args_t notification_timer_args = {
|
||||||
.callback = [](void *arg) {
|
.callback = [](void *arg) {
|
||||||
@@ -249,3 +253,9 @@ void Display::SetChatMessage(const char* role, const char* content) {
|
|||||||
}
|
}
|
||||||
lv_label_set_text(chat_message_label_, content);
|
lv_label_set_text(chat_message_label_, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Display::SetTheme(const std::string& theme_name) {
|
||||||
|
current_theme_name_ = theme_name;
|
||||||
|
Settings settings("display", true);
|
||||||
|
settings.SetString("theme", theme_name);
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ public:
|
|||||||
virtual void SetEmotion(const char* emotion);
|
virtual void SetEmotion(const char* emotion);
|
||||||
virtual void SetChatMessage(const char* role, const char* content);
|
virtual void SetChatMessage(const char* role, const char* content);
|
||||||
virtual void SetIcon(const char* icon);
|
virtual void SetIcon(const char* icon);
|
||||||
virtual void SetTheme(const std::string& theme_name){}
|
virtual void SetTheme(const std::string& theme_name);
|
||||||
virtual std::string GetTheme() { return "light"; }
|
virtual std::string GetTheme() { return current_theme_name_; }
|
||||||
|
|
||||||
inline int width() const { return width_; }
|
inline int width() const { return width_; }
|
||||||
inline int height() const { return height_; }
|
inline int height() const { return height_; }
|
||||||
@@ -50,6 +50,7 @@ protected:
|
|||||||
const char* battery_icon_ = nullptr;
|
const char* battery_icon_ = nullptr;
|
||||||
const char* network_icon_ = nullptr;
|
const char* network_icon_ = nullptr;
|
||||||
bool muted_ = false;
|
bool muted_ = false;
|
||||||
|
std::string current_theme_name_;
|
||||||
|
|
||||||
esp_timer_handle_t notification_timer_ = nullptr;
|
esp_timer_handle_t notification_timer_ = nullptr;
|
||||||
esp_timer_handle_t update_timer_ = nullptr;
|
esp_timer_handle_t update_timer_ = nullptr;
|
||||||
|
|||||||
@@ -76,8 +76,6 @@ static const ThemeColors LIGHT_THEME = {
|
|||||||
|
|
||||||
// Current theme - initialize based on default config
|
// Current theme - initialize based on default config
|
||||||
static ThemeColors current_theme = LIGHT_THEME;
|
static ThemeColors current_theme = LIGHT_THEME;
|
||||||
// Add theme name variable to track current theme
|
|
||||||
static std::string current_theme_name = "light";
|
|
||||||
|
|
||||||
|
|
||||||
LV_FONT_DECLARE(font_awesome_30_4);
|
LV_FONT_DECLARE(font_awesome_30_4);
|
||||||
@@ -144,17 +142,11 @@ SpiLcdDisplay::SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
|||||||
lv_display_set_offset(display_, offset_x, offset_y);
|
lv_display_set_offset(display_, offset_x, offset_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load theme from settings
|
// Update the theme
|
||||||
Settings settings("display", false);
|
if (current_theme_name_ == "dark") {
|
||||||
std::string theme = settings.GetString("theme", "");
|
current_theme = DARK_THEME;
|
||||||
if (!theme.empty()) {
|
} else if (current_theme_name_ == "light") {
|
||||||
if (theme == "dark") {
|
current_theme = LIGHT_THEME;
|
||||||
current_theme = DARK_THEME;
|
|
||||||
current_theme_name = "dark";
|
|
||||||
} else if (theme == "light") {
|
|
||||||
current_theme = LIGHT_THEME;
|
|
||||||
current_theme_name = "light";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupUI();
|
SetupUI();
|
||||||
@@ -221,17 +213,11 @@ RgbLcdDisplay::RgbLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
|||||||
lv_display_set_offset(display_, offset_x, offset_y);
|
lv_display_set_offset(display_, offset_x, offset_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load theme from settings
|
// Update the theme
|
||||||
Settings settings("display", false);
|
if (current_theme_name_ == "dark") {
|
||||||
std::string theme = settings.GetString("theme", "");
|
current_theme = DARK_THEME;
|
||||||
if (!theme.empty()) {
|
} else if (current_theme_name_ == "light") {
|
||||||
if (theme == "dark") {
|
current_theme = LIGHT_THEME;
|
||||||
current_theme = DARK_THEME;
|
|
||||||
current_theme_name = "dark";
|
|
||||||
} else if (theme == "light") {
|
|
||||||
current_theme = LIGHT_THEME;
|
|
||||||
current_theme_name = "light";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupUI();
|
SetupUI();
|
||||||
@@ -711,22 +697,16 @@ void LcdDisplay::SetIcon(const char* icon) {
|
|||||||
void LcdDisplay::SetTheme(const std::string& theme_name) {
|
void LcdDisplay::SetTheme(const std::string& theme_name) {
|
||||||
DisplayLockGuard lock(this);
|
DisplayLockGuard lock(this);
|
||||||
|
|
||||||
// Update the current theme based on the theme name
|
|
||||||
if (theme_name == "dark" || theme_name == "DARK") {
|
if (theme_name == "dark" || theme_name == "DARK") {
|
||||||
current_theme = DARK_THEME;
|
current_theme = DARK_THEME;
|
||||||
current_theme_name = "dark";
|
|
||||||
} else if (theme_name == "light" || theme_name == "LIGHT") {
|
} else if (theme_name == "light" || theme_name == "LIGHT") {
|
||||||
current_theme = LIGHT_THEME;
|
current_theme = LIGHT_THEME;
|
||||||
current_theme_name = "light";
|
|
||||||
} else {
|
} else {
|
||||||
// Invalid theme name, return false
|
// Invalid theme name, return false
|
||||||
|
ESP_LOGE(TAG, "Invalid theme name: %s", theme_name.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save theme to settings
|
|
||||||
Settings settings("display", true);
|
|
||||||
settings.SetString("theme", current_theme_name);
|
|
||||||
|
|
||||||
// Get the active screen
|
// Get the active screen
|
||||||
lv_obj_t* screen = lv_screen_active();
|
lv_obj_t* screen = lv_screen_active();
|
||||||
|
|
||||||
@@ -902,17 +882,7 @@ void LcdDisplay::SetTheme(const std::string& theme_name) {
|
|||||||
if (low_battery_popup_ != nullptr) {
|
if (low_battery_popup_ != nullptr) {
|
||||||
lv_obj_set_style_bg_color(low_battery_popup_, current_theme.low_battery, 0);
|
lv_obj_set_style_bg_color(low_battery_popup_, current_theme.low_battery, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::string LcdDisplay::GetTheme() {
|
// No errors occurred. Save theme to settings
|
||||||
// First try to read from settings
|
Display::SetTheme(theme_name);
|
||||||
Settings settings("display", false);
|
|
||||||
std::string theme = settings.GetString("theme", "light");
|
|
||||||
|
|
||||||
// If theme is not set in settings, return the current theme
|
|
||||||
if (theme.empty()) {
|
|
||||||
return current_theme_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return theme;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public:
|
|||||||
|
|
||||||
// Add theme switching function
|
// Add theme switching function
|
||||||
virtual void SetTheme(const std::string& theme_name) override;
|
virtual void SetTheme(const std::string& theme_name) override;
|
||||||
virtual std::string GetTheme() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// RGB LCD显示器
|
// RGB LCD显示器
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
#include "iot/thing.h"
|
|
||||||
#include "board.h"
|
|
||||||
#include "display/lcd_display.h"
|
|
||||||
#include "settings.h"
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
|
|
||||||
#define TAG "Backlight"
|
|
||||||
|
|
||||||
namespace iot {
|
|
||||||
|
|
||||||
// 这里仅定义 Backlight 的属性和方法,不包含具体的实现
|
|
||||||
class Backlight : public Thing {
|
|
||||||
public:
|
|
||||||
Backlight() : Thing("Backlight", "屏幕背光") {
|
|
||||||
// 定义设备的属性
|
|
||||||
properties_.AddNumberProperty("brightness", "当前亮度百分比", [this]() -> int {
|
|
||||||
// 这里可以添加获取当前亮度的逻辑
|
|
||||||
auto backlight = Board::GetInstance().GetBacklight();
|
|
||||||
return backlight ? backlight->brightness() : 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 定义设备可以被远程执行的指令
|
|
||||||
methods_.AddMethod("SetBrightness", "设置亮度", ParameterList({
|
|
||||||
Parameter("brightness", "0到100之间的整数", kValueTypeNumber, true)
|
|
||||||
}), [this](const ParameterList& parameters) {
|
|
||||||
uint8_t brightness = static_cast<uint8_t>(parameters["brightness"].number());
|
|
||||||
auto backlight = Board::GetInstance().GetBacklight();
|
|
||||||
if (backlight) {
|
|
||||||
backlight->SetBrightness(brightness, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace iot
|
|
||||||
|
|
||||||
DECLARE_THING(Backlight);
|
|
||||||
@@ -13,13 +13,19 @@ namespace iot {
|
|||||||
// 这里仅定义 Screen 的属性和方法,不包含具体的实现
|
// 这里仅定义 Screen 的属性和方法,不包含具体的实现
|
||||||
class Screen : public Thing {
|
class Screen : public Thing {
|
||||||
public:
|
public:
|
||||||
Screen() : Thing("Screen", "这是一个屏幕,可设置主题") {
|
Screen() : Thing("Screen", "这是一个屏幕,可设置主题和亮度") {
|
||||||
// 定义设备的属性
|
// 定义设备的属性
|
||||||
properties_.AddStringProperty("theme", "主题", [this]() -> std::string {
|
properties_.AddStringProperty("theme", "主题", [this]() -> std::string {
|
||||||
auto theme = Board::GetInstance().GetDisplay()->GetTheme();
|
auto theme = Board::GetInstance().GetDisplay()->GetTheme();
|
||||||
return theme;
|
return theme;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
properties_.AddNumberProperty("brightness", "当前亮度百分比", [this]() -> int {
|
||||||
|
// 这里可以添加获取当前亮度的逻辑
|
||||||
|
auto backlight = Board::GetInstance().GetBacklight();
|
||||||
|
return backlight ? backlight->brightness() : 100;
|
||||||
|
});
|
||||||
|
|
||||||
// 定义设备可以被远程执行的指令
|
// 定义设备可以被远程执行的指令
|
||||||
methods_.AddMethod("SetTheme", "设置屏幕主题", ParameterList({
|
methods_.AddMethod("SetTheme", "设置屏幕主题", ParameterList({
|
||||||
Parameter("theme_name", "主题模式, light 或 dark", kValueTypeString, true)
|
Parameter("theme_name", "主题模式, light 或 dark", kValueTypeString, true)
|
||||||
@@ -30,6 +36,16 @@ public:
|
|||||||
display->SetTheme(theme_name);
|
display->SetTheme(theme_name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
methods_.AddMethod("SetBrightness", "设置亮度", ParameterList({
|
||||||
|
Parameter("brightness", "0到100之间的整数", kValueTypeNumber, true)
|
||||||
|
}), [this](const ParameterList& parameters) {
|
||||||
|
uint8_t brightness = static_cast<uint8_t>(parameters["brightness"].number());
|
||||||
|
auto backlight = Board::GetInstance().GetBacklight();
|
||||||
|
if (backlight) {
|
||||||
|
backlight->SetBrightness(brightness, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user