display.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef DISPLAY_H
  2. #define DISPLAY_H
  3. #include <lvgl.h>
  4. #include <esp_timer.h>
  5. #include <esp_log.h>
  6. #include <esp_pm.h>
  7. #include <string>
  8. #include <chrono>
  9. struct DisplayFonts {
  10. const lv_font_t* text_font = nullptr;
  11. const lv_font_t* icon_font = nullptr;
  12. const lv_font_t* emoji_font = nullptr;
  13. };
  14. class Display {
  15. public:
  16. Display();
  17. virtual ~Display();
  18. virtual void SetStatus(const char* status);
  19. virtual void ShowNotification(const char* notification, int duration_ms = 3000);
  20. virtual void ShowNotification(const std::string &notification, int duration_ms = 3000);
  21. virtual void SetEmotion(const char* emotion);
  22. virtual void SetChatMessage(const char* role, const char* content);
  23. virtual void SetIcon(const char* icon);
  24. virtual void SetPreviewImage(const lv_img_dsc_t* image);
  25. virtual void SetTheme(const std::string& theme_name);
  26. virtual std::string GetTheme() { return current_theme_name_; }
  27. virtual void UpdateStatusBar(bool update_all = false);
  28. virtual void ShowStandbyScreen(bool show);
  29. virtual void ShowHomeScreen() = 0;
  30. virtual void HideHomeScreen() = 0;
  31. virtual void UpdateHomeTime() = 0;
  32. virtual void ShowCountdownScreen(int seconds, int rotation_angle) = 0;
  33. virtual void UpdateCountdown(int seconds) = 0;
  34. virtual void ShowCountdownEndScreen() = 0;
  35. virtual void ResetScreenRotation() = 0;
  36. inline int width() const { return width_; }
  37. inline int height() const { return height_; }
  38. protected:
  39. int width_ = 0;
  40. int height_ = 0;
  41. esp_pm_lock_handle_t pm_lock_ = nullptr;
  42. lv_display_t *display_ = nullptr;
  43. lv_obj_t *emotion_label_ = nullptr;
  44. lv_obj_t *network_label_ = nullptr;
  45. lv_obj_t *status_label_ = nullptr;
  46. lv_obj_t *notification_label_ = nullptr;
  47. lv_obj_t *mute_label_ = nullptr;
  48. lv_obj_t *battery_label_ = nullptr;
  49. lv_obj_t* chat_message_label_ = nullptr;
  50. lv_obj_t* low_battery_popup_ = nullptr;
  51. lv_obj_t* low_battery_label_ = nullptr;
  52. const char* battery_icon_ = nullptr;
  53. const char* network_icon_ = nullptr;
  54. bool muted_ = false;
  55. std::string current_theme_name_;
  56. std::chrono::system_clock::time_point last_status_update_time_;
  57. esp_timer_handle_t notification_timer_ = nullptr;
  58. friend class DisplayLockGuard;
  59. virtual bool Lock(int timeout_ms = 0) = 0;
  60. virtual void Unlock() = 0;
  61. };
  62. class DisplayLockGuard {
  63. public:
  64. DisplayLockGuard(Display *display) : display_(display) {
  65. if (!display_->Lock(30000)) {
  66. ESP_LOGE("Display", "Failed to lock display");
  67. }
  68. }
  69. ~DisplayLockGuard() {
  70. display_->Unlock();
  71. }
  72. private:
  73. Display *display_;
  74. };
  75. class NoDisplay : public Display {
  76. private:
  77. virtual bool Lock(int timeout_ms = 0) override {
  78. return true;
  79. }
  80. virtual void Unlock() override {}
  81. public:
  82. // 主界面相关方法的空实现
  83. void ShowHomeScreen() override {
  84. // 空实现
  85. }
  86. void HideHomeScreen() override {
  87. // 空实现
  88. }
  89. void UpdateHomeTime() override {
  90. // 空实现
  91. }
  92. void ShowCountdownScreen(int seconds, int rotation_angle) override {
  93. // 空实现
  94. ESP_LOGD("NoDisplay", "ShowCountdownScreen called: %d seconds, %d degrees",
  95. seconds, rotation_angle);
  96. }
  97. void UpdateCountdown(int seconds) override {
  98. // 空实现
  99. ESP_LOGD("NoDisplay", "UpdateCountdown called: %d seconds", seconds);
  100. }
  101. void ShowCountdownEndScreen() override {
  102. // 空实现
  103. ESP_LOGD("NoDisplay", "ShowCountdownEndScreen called");
  104. }
  105. void ResetScreenRotation() override {
  106. // 空实现
  107. ESP_LOGD("NoDisplay", "ResetScreenRotation called");
  108. }
  109. };
  110. #endif