| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef DISPLAY_H
- #define DISPLAY_H
- #include <lvgl.h>
- #include <esp_timer.h>
- #include <esp_log.h>
- #include <esp_pm.h>
- #include <string>
- #include <chrono>
- struct DisplayFonts {
- const lv_font_t* text_font = nullptr;
- const lv_font_t* icon_font = nullptr;
- const lv_font_t* emoji_font = nullptr;
- };
- class Display {
- public:
- Display();
- virtual ~Display();
- virtual void SetStatus(const char* status);
- virtual void ShowNotification(const char* notification, int duration_ms = 3000);
- virtual void ShowNotification(const std::string ¬ification, int duration_ms = 3000);
- virtual void SetEmotion(const char* emotion);
- virtual void SetChatMessage(const char* role, const char* content);
- virtual void SetIcon(const char* icon);
- virtual void SetPreviewImage(const lv_img_dsc_t* image);
- virtual void SetTheme(const std::string& theme_name);
- virtual std::string GetTheme() { return current_theme_name_; }
- virtual void UpdateStatusBar(bool update_all = false);
- virtual void ShowStandbyScreen(bool show);
- virtual void ShowHomeScreen() = 0;
- virtual void HideHomeScreen() = 0;
- virtual void UpdateHomeTime() = 0;
- virtual void ShowCountdownScreen(int seconds, int rotation_angle) = 0;
- virtual void UpdateCountdown(int seconds) = 0;
- virtual void ShowCountdownEndScreen() = 0;
- virtual void ResetScreenRotation() = 0;
- inline int width() const { return width_; }
- inline int height() const { return height_; }
- protected:
- int width_ = 0;
- int height_ = 0;
-
- esp_pm_lock_handle_t pm_lock_ = nullptr;
- lv_display_t *display_ = nullptr;
- lv_obj_t *emotion_label_ = nullptr;
- lv_obj_t *network_label_ = nullptr;
- lv_obj_t *status_label_ = nullptr;
- lv_obj_t *notification_label_ = nullptr;
- lv_obj_t *mute_label_ = nullptr;
- lv_obj_t *battery_label_ = nullptr;
- lv_obj_t* chat_message_label_ = nullptr;
- lv_obj_t* low_battery_popup_ = nullptr;
- lv_obj_t* low_battery_label_ = nullptr;
-
- const char* battery_icon_ = nullptr;
- const char* network_icon_ = nullptr;
- bool muted_ = false;
- std::string current_theme_name_;
- std::chrono::system_clock::time_point last_status_update_time_;
- esp_timer_handle_t notification_timer_ = nullptr;
- friend class DisplayLockGuard;
- virtual bool Lock(int timeout_ms = 0) = 0;
- virtual void Unlock() = 0;
- };
- class DisplayLockGuard {
- public:
- DisplayLockGuard(Display *display) : display_(display) {
- if (!display_->Lock(30000)) {
- ESP_LOGE("Display", "Failed to lock display");
- }
- }
- ~DisplayLockGuard() {
- display_->Unlock();
- }
- private:
- Display *display_;
- };
- class NoDisplay : public Display {
- private:
- virtual bool Lock(int timeout_ms = 0) override {
- return true;
- }
-
- virtual void Unlock() override {}
- public:
- // 主界面相关方法的空实现
- void ShowHomeScreen() override {
- // 空实现
- }
-
- void HideHomeScreen() override {
- // 空实现
- }
-
- void UpdateHomeTime() override {
- // 空实现
- }
-
- void ShowCountdownScreen(int seconds, int rotation_angle) override {
- // 空实现
- ESP_LOGD("NoDisplay", "ShowCountdownScreen called: %d seconds, %d degrees",
- seconds, rotation_angle);
- }
- void UpdateCountdown(int seconds) override {
- // 空实现
- ESP_LOGD("NoDisplay", "UpdateCountdown called: %d seconds", seconds);
- }
-
- void ShowCountdownEndScreen() override {
- // 空实现
- ESP_LOGD("NoDisplay", "ShowCountdownEndScreen called");
- }
-
- void ResetScreenRotation() override {
- // 空实现
- ESP_LOGD("NoDisplay", "ResetScreenRotation called");
- }
- };
- #endif
|