Add Display::set_text.
This commit is contained in:
parent
ef7a027cf0
commit
046dfbb6e6
@ -1,4 +1,5 @@
|
||||
#include "display.h"
|
||||
#include "widgets/label/lv_label.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
@ -97,6 +98,28 @@ Display::Display(const I2C &i2c) :
|
||||
nullptr, LVGL_TASK_PRIORITY, nullptr);
|
||||
}
|
||||
|
||||
void Display::set_text(const char *text,
|
||||
const char *name,
|
||||
lv_label_long_mode_t long_mode,
|
||||
lv_align_t align)
|
||||
{
|
||||
// Lock the mutex due to the LVGL APIs are not thread-safe.
|
||||
ScopedLock lock;
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Scroll Text");
|
||||
lv_obj_t *scr = lv_display_get_screen_active(display_);
|
||||
objects_[name] = lv_label_create(scr);
|
||||
// Circular scroll
|
||||
lv_label_set_long_mode(objects_[name], long_mode);
|
||||
lv_label_set_text(objects_[name], text);
|
||||
|
||||
// Set the size of the screen.
|
||||
// If you use rotation 90 or 270 use lv_display_get_vertical_resolution.
|
||||
lv_obj_set_width(objects_[name],
|
||||
lv_display_get_horizontal_resolution(display_));
|
||||
lv_obj_align(objects_[name], align, 0, 0);
|
||||
}
|
||||
|
||||
bool Display::lvgl_flush_ready(esp_lcd_panel_io_handle_t,
|
||||
esp_lcd_panel_io_event_data_t *,
|
||||
void *user_ctx)
|
||||
|
@ -5,9 +5,11 @@
|
||||
#include <esp_lcd_panel_ssd1306.h>
|
||||
#include <driver/i2c_types.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include <unordered_map>
|
||||
#include "misc/lv_types.h"
|
||||
#include "misc/lv_area.h"
|
||||
#include "display/lv_display.h"
|
||||
#include "widgets/label/lv_label.h"
|
||||
|
||||
#define I2C_BUS_PORT 0
|
||||
#define LVGL_TICK_PERIOD_MS 5
|
||||
@ -66,6 +68,11 @@ public:
|
||||
|
||||
[[nodiscard]] inline lv_display_t *operator*() { return get(); }
|
||||
|
||||
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);
|
||||
|
||||
static bool lvgl_flush_ready(esp_lcd_panel_io_handle_t panel,
|
||||
esp_lcd_panel_io_event_data_t *data,
|
||||
void *user_ctx);
|
||||
@ -93,6 +100,8 @@ protected:
|
||||
private:
|
||||
// virtual void *vendor_config() = 0;
|
||||
|
||||
std::unordered_map<const char*, lv_obj_t*> objects_;
|
||||
|
||||
lv_display_t *display_;
|
||||
|
||||
void *vendor_config_;
|
||||
|
@ -1,31 +1,22 @@
|
||||
#include "display.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "lvgl.h"
|
||||
|
||||
I2C i2c;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Display d(i2c);
|
||||
|
||||
// UI function scope.
|
||||
{
|
||||
// Lock the mutex due to the LVGL APIs are not thread-safe
|
||||
ScopedLock lock;
|
||||
d.set_text("Test test 12345678910",
|
||||
"test-text1",
|
||||
LV_LABEL_LONG_SCROLL,
|
||||
LV_ALIGN_CENTER);
|
||||
|
||||
ESP_LOGI(TAG, "Display LVGL Scroll Text");
|
||||
lv_obj_t *scr = lv_display_get_screen_active(d.get());
|
||||
lv_obj_t *label = lv_label_create(scr);
|
||||
// Circular scroll
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_label_set_text(label, "Hello hello hello hello hello hello hello.");
|
||||
d.set_text("Hello hello hello hello hello hello hello hello!", "test-text2");
|
||||
|
||||
// Size of the screen
|
||||
// if you use rotation 90 or 270 use lv_display_get_vertical_resolution
|
||||
lv_obj_set_width(label, lv_display_get_horizontal_resolution(*d));
|
||||
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
|
||||
}
|
||||
d.set_text("A random sentence with no meaning at all.",
|
||||
"test-text3",
|
||||
LV_LABEL_LONG_CLIP,
|
||||
LV_ALIGN_BOTTOM_MID);
|
||||
}
|
||||
|
||||
void loop() { }
|
||||
|
Loading…
x
Reference in New Issue
Block a user