140 lines
3.6 KiB
C
Raw Normal View History

2025-02-14 15:02:49 -05:00
#ifndef DISPLAY_H
#define DISPLAY_H
2025-02-16 09:38:28 -05:00
2025-02-15 18:26:26 -05:00
#include <widgets/label/lv_label.h>
2025-02-14 17:19:13 -05:00
#include <unordered_map>
2025-02-14 15:02:49 -05:00
#include "time_keeper.h"
2025-02-15 17:51:57 -05:00
#include "panel.h"
2025-02-15 10:11:49 -05:00
2025-02-14 15:02:49 -05:00
#define LVGL_TICK_PERIOD_MS 5
#define LVGL_TASK_STACK_SIZE (4 * 1024)
#define LVGL_TASK_PRIORITY 2
class Display {
public:
//
// CONSTRUCTORS
2025-02-16 08:58:40 -05:00
Display(const Display &) = delete;
2025-02-16 08:58:40 -05:00
Display(Display &) = delete;
2025-02-16 08:58:40 -05:00
Display &operator=(Display &) = delete;
2025-02-16 08:58:40 -05:00
/**
* Construct a new Display using an IPanelDevice.
*
* @param device An object that implements the IPanelDevice interface.
*/
explicit Display(IPanelDevice &device);
~Display() = default;
//
// GETTERS
/**
* Getter for accessing LVGL display handle.
*
* @sa ScopedLock for calling custom LVGL API's not implemented by Display.
*/
[[nodiscard]] inline const lv_display_t *get() const { return lv_display_; }
/**
* Getter for accessing LVGL display handle.
*
* @sa ScopedLock for calling custom LVGL API's not implemented by Display.
*/
[[nodiscard]] inline lv_display_t *get() { return lv_display_; }
/// Dereference operator for accessing LVGL display handle.
[[nodiscard]] inline const lv_display_t *operator*() const { return get(); }
/// Dereference operator for accessing LVGL display handle.
[[nodiscard]] inline lv_display_t *operator*() { return get(); }
//
// LVGL OPERATIONS
/**
* Create a LVGL label with some given text on the current display.
* The name of the object can be reused to change text on this label later.
*
* @param text Text to write to the display.
* @param name Name for the LVGL label object associated with this text.
* @param long_mode LVGL long mode for text wider than the current display.
* @param align LVGL alignment to use for placing the label on the display.
*/
void set_text(const char *text,
const char *name,
lv_label_long_mode_t long_mode = LV_LABEL_LONG_SCROLL_CIRCULAR,
lv_align_t align = LV_ALIGN_TOP_MID);
//
// TYPE DEFINITIONS
/**
* Obtains LVGL API mutex lock for the duration of local scope.
*
* LVGL library is not thread-safe, this example calls LVGL APIs from tasks.
*/
struct ScopedLock {
explicit ScopedLock() { _lock_acquire(&lv_lock_); }
~ScopedLock() { _lock_release(&lv_lock_); }
/// Mutex used to protect LVGL API calls.
static _lock_t lv_lock_;
};
//
// PUBLIC STATIC MEMBERS
/// Public static TimeKeeper for managing ESP timers across all displays.
static TimeKeeper timers_;
2025-02-14 15:02:49 -05:00
private:
/// Registers LVGL draw buffers for this display.
void register_draw_buffer();
/// Registers LVGL ticker timer callback for rendering this display.
2025-02-16 09:38:28 -05:00
static void register_lvgl_tick_timer();
2025-02-16 07:21:16 -05:00
static bool lvgl_flush_ready_cb(esp_lcd_panel_io_handle_t panel,
esp_lcd_panel_io_event_data_t *data,
void *user_ctx);
static void lvgl_flush_cb(lv_display_t *display,
const lv_area_t *area,
uint8_t *px_map);
static void lvgl_increase_tick_cb(void *arg);
[[noreturn]] static void lvgl_port_task(void *arg);
//
// PRIVATE MEMBERS
/// Panel associated with this Display.
2025-02-14 17:47:44 -05:00
Panel panel_;
2025-02-14 17:19:13 -05:00
/// LVGL display handle.
2025-02-15 17:12:06 -05:00
lv_display_t *lv_display_;
2025-02-15 14:04:08 -05:00
/// LVGL draw buffer associated with this Display's lv_display_t.
2025-02-15 17:12:06 -05:00
void *lv_buf_;
2025-02-14 17:47:44 -05:00
/**
* LVGL object handles stored in the LVGL screen associated with this Display.
*
* @sa Display::set_text
* @sa lv_display_get_screen_active
*/
2025-02-15 18:26:26 -05:00
std::unordered_map<const char *, lv_obj_t *> lv_objects_;
2025-02-14 15:02:49 -05:00
};
#endif // DISPLAY_H