2024-11-18 06:17:39 +08:00
|
|
|
#ifndef DISPLAY_H
|
|
|
|
|
#define DISPLAY_H
|
|
|
|
|
|
|
|
|
|
#include <lvgl.h>
|
|
|
|
|
#include <esp_timer.h>
|
2025-02-03 23:43:07 +08:00
|
|
|
#include <esp_log.h>
|
2025-03-04 06:27:11 +08:00
|
|
|
#include <esp_pm.h>
|
2024-11-18 06:17:39 +08:00
|
|
|
|
|
|
|
|
#include <string>
|
2025-07-19 22:45:22 +08:00
|
|
|
#include <chrono>
|
2024-11-18 06:17:39 +08:00
|
|
|
|
2025-01-24 03:00:50 +08:00
|
|
|
struct DisplayFonts {
|
|
|
|
|
const lv_font_t* text_font = nullptr;
|
|
|
|
|
const lv_font_t* icon_font = nullptr;
|
|
|
|
|
const lv_font_t* emoji_font = nullptr;
|
|
|
|
|
};
|
2024-11-18 06:17:39 +08:00
|
|
|
|
|
|
|
|
class Display {
|
|
|
|
|
public:
|
|
|
|
|
Display();
|
|
|
|
|
virtual ~Display();
|
|
|
|
|
|
2025-02-19 23:54:59 +08:00
|
|
|
virtual void SetStatus(const char* status);
|
|
|
|
|
virtual void ShowNotification(const char* notification, int duration_ms = 3000);
|
2024-11-18 06:17:39 +08:00
|
|
|
virtual void ShowNotification(const std::string ¬ification, int duration_ms = 3000);
|
2025-02-19 23:54:59 +08:00
|
|
|
virtual void SetEmotion(const char* emotion);
|
|
|
|
|
virtual void SetChatMessage(const char* role, const char* content);
|
2024-11-18 06:17:39 +08:00
|
|
|
virtual void SetIcon(const char* icon);
|
2025-05-25 07:02:44 +08:00
|
|
|
virtual void SetPreviewImage(const lv_img_dsc_t* image);
|
2025-03-20 03:00:07 +08:00
|
|
|
virtual void SetTheme(const std::string& theme_name);
|
|
|
|
|
virtual std::string GetTheme() { return current_theme_name_; }
|
2025-05-24 07:25:34 +08:00
|
|
|
virtual void UpdateStatusBar(bool update_all = false);
|
2025-07-29 15:25:40 +08:00
|
|
|
virtual void SetPowerSaveMode(bool on);
|
2024-11-18 06:17:39 +08:00
|
|
|
|
2025-02-14 01:15:10 +08:00
|
|
|
inline int width() const { return width_; }
|
|
|
|
|
inline int height() const { return height_; }
|
2024-11-18 06:17:39 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
int width_ = 0;
|
|
|
|
|
int height_ = 0;
|
2025-03-04 06:27:11 +08:00
|
|
|
|
|
|
|
|
esp_pm_lock_handle_t pm_lock_ = nullptr;
|
2025-02-03 23:43:07 +08:00
|
|
|
lv_display_t *display_ = nullptr;
|
2024-11-18 06:17:39 +08:00
|
|
|
|
|
|
|
|
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;
|
2025-02-16 06:59:19 +08:00
|
|
|
lv_obj_t* chat_message_label_ = nullptr;
|
2025-03-06 05:22:06 +08:00
|
|
|
lv_obj_t* low_battery_popup_ = nullptr;
|
2025-04-12 09:33:07 +08:00
|
|
|
lv_obj_t* low_battery_label_ = nullptr;
|
|
|
|
|
|
2024-11-18 06:17:39 +08:00
|
|
|
const char* battery_icon_ = nullptr;
|
|
|
|
|
const char* network_icon_ = nullptr;
|
|
|
|
|
bool muted_ = false;
|
2025-03-20 03:00:07 +08:00
|
|
|
std::string current_theme_name_;
|
2024-11-18 06:17:39 +08:00
|
|
|
|
2025-07-19 22:45:22 +08:00
|
|
|
std::chrono::system_clock::time_point last_status_update_time_;
|
2024-11-18 06:17:39 +08:00
|
|
|
esp_timer_handle_t notification_timer_ = nullptr;
|
|
|
|
|
|
|
|
|
|
friend class DisplayLockGuard;
|
2024-12-03 12:33:33 +08:00
|
|
|
virtual bool Lock(int timeout_ms = 0) = 0;
|
2024-11-18 06:17:39 +08:00
|
|
|
virtual void Unlock() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DisplayLockGuard {
|
|
|
|
|
public:
|
|
|
|
|
DisplayLockGuard(Display *display) : display_(display) {
|
2025-04-13 23:12:44 +08:00
|
|
|
if (!display_->Lock(30000)) {
|
2025-02-03 23:43:07 +08:00
|
|
|
ESP_LOGE("Display", "Failed to lock display");
|
|
|
|
|
}
|
2024-11-18 06:17:39 +08:00
|
|
|
}
|
|
|
|
|
~DisplayLockGuard() {
|
|
|
|
|
display_->Unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Display *display_;
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-08 19:56:56 +08:00
|
|
|
class NoDisplay : public Display {
|
|
|
|
|
private:
|
|
|
|
|
virtual bool Lock(int timeout_ms = 0) override {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
virtual void Unlock() override {}
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-18 06:17:39 +08:00
|
|
|
#endif
|