display.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. struct DisplayFonts {
  9. const lv_font_t* text_font = nullptr;
  10. const lv_font_t* icon_font = nullptr;
  11. const lv_font_t* emoji_font = nullptr;
  12. };
  13. class Display {
  14. public:
  15. Display();
  16. virtual ~Display();
  17. virtual void SetStatus(const char* status);
  18. virtual void ShowNotification(const char* notification, int duration_ms = 3000);
  19. virtual void ShowNotification(const std::string &notification, int duration_ms = 3000);
  20. virtual void SetEmotion(const char* emotion);
  21. virtual void SetChatMessage(const char* role, const char* content);
  22. virtual void SetIcon(const char* icon);
  23. virtual void SetTheme(const std::string& theme_name);
  24. virtual std::string GetTheme() { return current_theme_name_; }
  25. inline int width() const { return width_; }
  26. inline int height() const { return height_; }
  27. protected:
  28. int width_ = 0;
  29. int height_ = 0;
  30. esp_pm_lock_handle_t pm_lock_ = nullptr;
  31. lv_display_t *display_ = nullptr;
  32. lv_obj_t *emotion_label_ = nullptr;
  33. lv_obj_t *emotion_label_1 = nullptr;
  34. lv_obj_t *emotion_label_2 = nullptr;
  35. lv_obj_t *network_label_ = nullptr;
  36. lv_obj_t *status_label_ = nullptr;
  37. lv_obj_t *notification_label_ = nullptr;
  38. lv_obj_t *mute_label_ = nullptr;
  39. lv_obj_t *battery_label_ = nullptr;
  40. lv_obj_t* chat_message_label_ = nullptr;
  41. lv_obj_t* low_battery_popup_ = nullptr;
  42. const char* battery_icon_ = nullptr;
  43. const char* network_icon_ = nullptr;
  44. bool muted_ = false;
  45. std::string current_theme_name_;
  46. esp_timer_handle_t notification_timer_ = nullptr;
  47. esp_timer_handle_t update_timer_ = nullptr;
  48. friend class DisplayLockGuard;
  49. virtual bool Lock(int timeout_ms = 0) = 0;
  50. virtual void Unlock() = 0;
  51. virtual void Update();
  52. };
  53. class DisplayLockGuard {
  54. public:
  55. DisplayLockGuard(Display *display) : display_(display) {
  56. if (!display_->Lock(3000)) {
  57. ESP_LOGE("Display", "Failed to lock display");
  58. }
  59. }
  60. ~DisplayLockGuard() {
  61. display_->Unlock();
  62. }
  63. private:
  64. Display *display_;
  65. };
  66. class NoDisplay : public Display {
  67. private:
  68. virtual bool Lock(int timeout_ms = 0) override {
  69. return true;
  70. }
  71. virtual void Unlock() override {}
  72. };
  73. #endif