Files
xiaozhi-esp32/main/display/display.h

81 lines
2.0 KiB
C
Raw Normal View History

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>
#include <esp_pm.h>
2024-11-18 06:17:39 +08:00
#include <string>
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 &notification, 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-02-14 01:15:10 +08:00
virtual void SetBacklight(uint8_t brightness);
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_; }
inline uint8_t brightness() const { return brightness_; }
2024-11-18 06:17:39 +08:00
protected:
int width_ = 0;
int height_ = 0;
2025-02-14 01:15:10 +08:00
uint8_t brightness_ = 0;
2024-11-18 06:17:39 +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;
lv_obj_t* chat_message_label_ = nullptr;
2024-11-18 06:17:39 +08:00
const char* battery_icon_ = nullptr;
const char* network_icon_ = nullptr;
bool muted_ = false;
esp_timer_handle_t notification_timer_ = nullptr;
esp_timer_handle_t update_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;
virtual void Update();
};
class DisplayLockGuard {
public:
DisplayLockGuard(Display *display) : display_(display) {
2025-02-03 23:43:07 +08:00
if (!display_->Lock(3000)) {
ESP_LOGE("Display", "Failed to lock display");
}
2024-11-18 06:17:39 +08:00
}
~DisplayLockGuard() {
display_->Unlock();
}
private:
Display *display_;
};
#endif