2024-11-18 06:17:39 +08:00
|
|
|
#ifndef DISPLAY_H
|
|
|
|
|
#define DISPLAY_H
|
|
|
|
|
|
2025-09-04 15:41:28 +08:00
|
|
|
#include "emoji_collection.h"
|
|
|
|
|
|
2025-09-11 03:53:12 +08:00
|
|
|
#ifdef LVGL_VERSION_MAJOR
|
|
|
|
|
#define HAVE_LVGL 1
|
2024-11-18 06:17:39 +08:00
|
|
|
#include <lvgl.h>
|
2025-09-11 03:53:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
2024-11-18 06:17:39 +08:00
|
|
|
#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-09-10 18:43:47 +08:00
|
|
|
class Theme {
|
|
|
|
|
public:
|
|
|
|
|
Theme(const std::string& name) : name_(name) {}
|
|
|
|
|
virtual ~Theme() = default;
|
2025-09-04 15:41:28 +08:00
|
|
|
|
2025-09-10 18:43:47 +08:00
|
|
|
inline std::string name() const { return name_; }
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
2025-01-24 03:00:50 +08:00
|
|
|
};
|
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);
|
2025-09-10 18:43:47 +08:00
|
|
|
virtual void SetTheme(Theme* theme);
|
|
|
|
|
virtual Theme* GetTheme() { return current_theme_; }
|
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-09-10 18:43:47 +08:00
|
|
|
|
|
|
|
|
Theme* current_theme_ = nullptr;
|
2024-11-18 06:17:39 +08:00
|
|
|
|
|
|
|
|
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
|