Refactor draw buffer handling
This commit is contained in:
@@ -17,10 +17,13 @@
|
||||
|
||||
static uint8_t black_data[DISPLAY_BUFFER_SIZE]; // all black data
|
||||
static uint8_t white_data[DISPLAY_BUFFER_SIZE]; // all white data
|
||||
static uint8_t DRAW_BUFFER[DISPLAY_WIDTH * DISPLAY_HEIGHT / 8]; // 1 bit per pixel
|
||||
|
||||
EInkDisplayHandler::EInkDisplayHandler() {
|
||||
memset(black_data, 0xFF, sizeof(black_data)); // eink uses 1 for black
|
||||
memset(white_data, 0x00, sizeof(white_data));
|
||||
memset(DRAW_BUFFER, 0x00, sizeof(DRAW_BUFFER)); // start with all white
|
||||
draw_buffer_ = DRAW_BUFFER;
|
||||
spi_mutex_ = xSemaphoreCreateMutex();
|
||||
if (spi_mutex_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to create SPI mutex");
|
||||
@@ -147,6 +150,8 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
||||
ESP_LOGI(TAG, "Starting full refresh (3 seconds)...");
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
write_to_buffer_(framebuffer, RefreshArea { 0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1 });
|
||||
|
||||
if (is_deep_sleep_) {
|
||||
epd_init_();
|
||||
}
|
||||
@@ -188,7 +193,7 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
||||
return err;
|
||||
}
|
||||
|
||||
err = transfer_spi_data(framebuffer, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send new framebuffer data
|
||||
err = transfer_spi_data(draw_buffer_, DISPLAY_BUFFER_SIZE, transaction_guard.transaction_id()); // Send new framebuffer data
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to send framebuffer data for new data: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
@@ -214,19 +219,51 @@ esp_err_t EInkDisplayHandler::full_write(const uint8_t* framebuffer, const bool
|
||||
return err;
|
||||
}
|
||||
|
||||
refresh_area_.reset();
|
||||
|
||||
ESP_LOGI(TAG, "Full refresh complete");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* partial_framebuffer, const RefreshArea& area) {
|
||||
esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* incoming_partial_framebuffer, const RefreshArea& incoming_area, const bool is_last_partial_update) {
|
||||
ESP_LOGI(TAG, "Starting partial refresh (0.3 seconds)...");
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
write_to_buffer_(incoming_partial_framebuffer, incoming_area);
|
||||
|
||||
if (!is_last_partial_update) {
|
||||
ESP_LOGI(TAG, "Partial refresh skipped (not last partial update)");
|
||||
refresh_area_.expand_to_include(incoming_area);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
RefreshArea area = refresh_area_;
|
||||
if (area.x1 % 8 != 0 || area.x2 % 8 != 7) {
|
||||
ESP_LOGE(TAG, "Partial refresh area x1 and x2 must be byte-aligned (x1 %% 8 == 0 and x2 %% 8 == 7)");
|
||||
ESP_LOGI(TAG, "Given area: x1=%d, x2=%d", area.x1, area.x2);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Calculate partial buffer size based on the refresh area
|
||||
const uint32_t area_width_bytes = (area.x2 - area.x1 + 1) / 8;
|
||||
const uint32_t area_height = area.y2 - area.y1 + 1;
|
||||
const size_t partial_buffer_size = area_width_bytes * area_height;
|
||||
|
||||
uint8_t* partial_buffer = new uint8_t[partial_buffer_size];
|
||||
if (partial_buffer == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate partial buffer for partial refresh");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
// Copy the relevant area from draw_buffer_ to partial_buffer
|
||||
for (int32_t row = 0; row < area_height; ++row) {
|
||||
uint32_t fb_y = area.y1 + row;
|
||||
uint32_t fb_x_byte_start = area.x1 / 8;
|
||||
uint8_t* fb_ptr = &draw_buffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||
uint8_t* dest_ptr = &partial_buffer[row * area_width_bytes];
|
||||
memcpy(dest_ptr, fb_ptr, area_width_bytes);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
TransactionGuard transaction_guard(*this);
|
||||
err = transaction_guard.begin(pdMS_TO_TICKS(5000));
|
||||
@@ -261,10 +298,6 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* partial_framebuffer
|
||||
}
|
||||
// Step 3: Set partial window
|
||||
{
|
||||
if (area.x1 % 8 != 0 || area.x2 % 8 != 7) {
|
||||
ESP_LOGE(TAG, "Partial refresh area x1 and x2 must be byte-aligned (x1 %% 8 == 0 and x2 %% 8 == 7)");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
// ------DD
|
||||
// DDDDD000
|
||||
// ------DD
|
||||
@@ -320,9 +353,9 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* partial_framebuffer
|
||||
// Send only the partial area data, not the full display buffer
|
||||
ESP_LOGI(TAG, "Sending partial buffer: %zu bytes (area: %dx%d)",
|
||||
partial_buffer_size, area_width_bytes * 8, area_height);
|
||||
err = transfer_spi_data(partial_framebuffer, partial_buffer_size, transaction_guard.transaction_id());
|
||||
err = transfer_spi_data(partial_buffer, partial_buffer_size, transaction_guard.transaction_id());
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to send partial_framebuffer data for partial refresh: %s", esp_err_to_name(err));
|
||||
ESP_LOGE(TAG, "Failed to send partial_buffer data for partial refresh: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -378,6 +411,8 @@ esp_err_t EInkDisplayHandler::partial_refresh(const uint8_t* partial_framebuffer
|
||||
return err;
|
||||
}
|
||||
|
||||
refresh_area_.reset();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -393,7 +428,19 @@ esp_err_t EInkDisplayHandler::clear_display(void) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void EInkDisplayHandler::write_to_buffer_(const uint8_t* src_buffer, const RefreshArea& area) {
|
||||
// Copy the relevant area from src_buffer to draw_buffer_
|
||||
const uint32_t area_width_bytes = (area.x2 - area.x1 + 1) / 8;
|
||||
const uint32_t area_height = area.y2 - area.y1 + 1;
|
||||
|
||||
for (int32_t row = 0; row < area_height; ++row) {
|
||||
uint32_t fb_y = area.y1 + row;
|
||||
uint32_t fb_x_byte_start = area.x1 / 8;
|
||||
const uint8_t* src_ptr = &src_buffer[row * area_width_bytes];
|
||||
uint8_t* dest_ptr = &draw_buffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||
memcpy(dest_ptr, src_ptr, area_width_bytes);
|
||||
}
|
||||
}
|
||||
|
||||
// Request a full refresh on next flush
|
||||
void EInkDisplayHandler::request_full_refresh(void) {
|
||||
@@ -608,8 +655,15 @@ esp_err_t EInkDisplayHandler::epd_init_(void) {
|
||||
ESP_LOGE(TAG, "Failed to send Enhanced Display Drive command: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
is_deep_sleep_ = false;
|
||||
|
||||
err = refresh_old_buffer_(transaction_guard.transaction_id());
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to refresh old buffer during init: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -676,6 +730,13 @@ esp_err_t EInkDisplayHandler::epd_init_partial_internal_(uint32_t transaction_id
|
||||
}
|
||||
|
||||
is_deep_sleep_ = false;
|
||||
|
||||
err = refresh_old_buffer_(transaction_id);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to refresh old buffer during partial init: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "EPD partial init (internal) complete");
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -742,6 +803,27 @@ esp_err_t EInkDisplayHandler::init_touch_() {
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t EInkDisplayHandler::refresh_old_buffer_(uint32_t transaction_id) {
|
||||
ESP_LOGI(TAG, "Refreshing old buffer to match current draw buffer...");
|
||||
esp_err_t err;
|
||||
|
||||
// Send command to write old data
|
||||
err = epd_write_cmd(0x10, transaction_id); // Command to write old data
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to send old data command: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
// Send the current draw buffer as old data
|
||||
err = transfer_spi_data(draw_buffer_, DISPLAY_BUFFER_SIZE, transaction_id);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to send old buffer data: %s", esp_err_to_name(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Old buffer refreshed successfully");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t EInkDisplayHandler::epd_write_cmd(const uint8_t cmd, uint32_t transaction_id) {
|
||||
ESP_LOGI(TAG, "epd_write_cmd: waiting to send 0x%02X", cmd);
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
esp_err_t refresh_display(void);
|
||||
esp_err_t full_write(const uint8_t* framebuffer, const bool white_basemap = true);
|
||||
esp_err_t partial_refresh(const uint8_t* framebuffer, const RefreshArea& area);
|
||||
esp_err_t partial_refresh(const uint8_t* framebuffer, const RefreshArea& area, const bool is_last_partial_update = true);
|
||||
esp_err_t clear_display(void);
|
||||
esp_err_t deep_sleep_display(void);
|
||||
// Request a full refresh on next flush
|
||||
@@ -84,6 +84,11 @@ private:
|
||||
esp_err_t dangerous_epd_write_cmd_without_lock_(const uint8_t cmd);
|
||||
esp_err_t dangerous_epd_write_data_without_lock_(const uint8_t data);
|
||||
|
||||
// write to the internal draw buffer
|
||||
void write_to_buffer_(const uint8_t* src, const RefreshArea& area);
|
||||
// write the internal draw buffer to the display's old sram
|
||||
esp_err_t refresh_old_buffer_(uint32_t transaction_id);
|
||||
|
||||
esp_err_t begin_transaction_(TickType_t timeout, uint32_t& out_id);
|
||||
esp_err_t end_transaction_(void);
|
||||
// given a transaction ID, wait for current transaction to complete. The transaction ID will determine if the wait is needed.
|
||||
@@ -102,6 +107,10 @@ private:
|
||||
spi_device_handle_t spi_ = nullptr;
|
||||
esp_lcd_panel_io_handle_t tp_io_handle_ = nullptr;
|
||||
esp_lcd_touch_handle_t tp_handle_ = nullptr;
|
||||
|
||||
// this buffer reflects the current display state (1=black, 0=white)
|
||||
uint8_t* draw_buffer_ = nullptr;
|
||||
RefreshArea refresh_area_ = { 0, 0, 0, 0 };
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@ LVGLHandler::~LVGLHandler() {
|
||||
lv_draw_buf_destroy(lvgl_draw_buf_);
|
||||
lvgl_draw_buf_ = nullptr;
|
||||
}
|
||||
if (framebuffer_ != nullptr) {
|
||||
heap_caps_free(framebuffer_);
|
||||
framebuffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t LVGLHandler::initLVGL(EventGroupHandle_t system_event_group) {
|
||||
@@ -94,8 +90,8 @@ void LVGLHandler::flush_cb_(lv_display_t* disp, const lv_area_t* area, uint8_t*
|
||||
return;
|
||||
}
|
||||
LVGLHandler* handler = static_cast<LVGLHandler*>(lv_display_get_user_data(disp));
|
||||
if (handler == nullptr || handler->display_handler_ == nullptr || handler->framebuffer_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Invalid handler or framebuffer in flush callback");
|
||||
if (handler == nullptr || handler->display_handler_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Invalid handler in flush callback");
|
||||
lv_display_flush_ready(disp);
|
||||
return;
|
||||
}
|
||||
@@ -107,82 +103,47 @@ void LVGLHandler::flush_cb_(lv_display_t* disp, const lv_area_t* area, uint8_t*
|
||||
int32_t area_w = lv_area_get_width(area);
|
||||
int32_t area_h = lv_area_get_height(area);
|
||||
if (area->x1 == 0 && area->y1 == 0 && area_w == DISPLAY_WIDTH && area_h == DISPLAY_HEIGHT) {
|
||||
// Check if content actually changed before triggering expensive e-ink refresh
|
||||
if (memcmp(handler->framebuffer_, pixel_data, DISPLAY_BUFFER_SIZE) == 0) {
|
||||
ESP_LOGD(TAG, "Full screen flush with no changes - skipping e-ink refresh");
|
||||
lv_display_flush_ready(disp);
|
||||
return;
|
||||
}
|
||||
ESP_LOGI(TAG, "Full screen update");
|
||||
memcpy(handler->framebuffer_, pixel_data, DISPLAY_BUFFER_SIZE);
|
||||
// invert the framebuffer for e-ink display
|
||||
for (size_t i = 0; i < DISPLAY_BUFFER_SIZE; ++i) {
|
||||
handler->framebuffer_[i] = ~handler->framebuffer_[i];
|
||||
}
|
||||
// request full refresh
|
||||
esp_err_t err = handler->display_handler_->full_write(handler->framebuffer_, true);
|
||||
esp_err_t err = handler->display_handler_->full_write(
|
||||
pixel_data,
|
||||
true // white basemap
|
||||
);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Full refresh request failed: %s", esp_err_to_name(err));
|
||||
}
|
||||
} else {
|
||||
// partial update
|
||||
ESP_LOGI(TAG, "Partial update: x1=%d, y1=%d, w=%d, h=%d", area->x1, area->y1, area_w, area_h);
|
||||
// update the framebuffer with the partial data
|
||||
for (int32_t row = 0; row < area_h; ++row) {
|
||||
int32_t fb_y = area->y1 + row;
|
||||
int32_t fb_x_byte_start = area->x1 / 8;
|
||||
int32_t fb_x_byte_end = area->x2 / 8;
|
||||
uint8_t* fb_ptr = &handler->framebuffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||
const uint8_t* src_ptr = &pixel_data[row * (area_w / 8)];
|
||||
// invert the partial framebuffer data for e-ink display
|
||||
for (int32_t i = 0; i < (fb_x_byte_end - fb_x_byte_start + 1); ++i) {
|
||||
fb_ptr[i] = ~src_ptr[i];
|
||||
}
|
||||
}
|
||||
// update the refresh area
|
||||
handler->refresh_area_.expand_to_include(area->x1, area->y1, area->x2, area->y2);
|
||||
//
|
||||
|
||||
if (lv_display_flush_is_last(disp) && !handler->refresh_area_.is_empty()) {
|
||||
ESP_LOGI(TAG, "Last flush in batch - performing partial refresh");
|
||||
ESP_LOGI(TAG, "Refresh area: x1=%d, y1=%d, x2=%d, y2=%d",
|
||||
handler->refresh_area_.x1, handler->refresh_area_.y1,
|
||||
handler->refresh_area_.x2, handler->refresh_area_.y2);
|
||||
// copy the area to refresh
|
||||
uint8_t* partial_buffer = new uint8_t[handler->refresh_area_.area() / 8];
|
||||
// Prepare partial buffer
|
||||
const uint32_t area_width_bytes = (area->x2 - area->x1 + 1) / 8;
|
||||
const uint32_t area_height = area->y2 - area->y1 + 1;
|
||||
const size_t partial_buffer_size = area_width_bytes * area_height;
|
||||
uint8_t* partial_buffer = new uint8_t[partial_buffer_size];
|
||||
if (partial_buffer == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate partial buffer for refresh");
|
||||
ESP_LOGE(TAG, "Failed to allocate partial buffer for flush callback");
|
||||
lv_display_flush_ready(disp);
|
||||
return;
|
||||
}
|
||||
// loop the refresh area and copy data
|
||||
uint32_t x1 = handler->refresh_area_.x1;
|
||||
uint32_t x2 = handler->refresh_area_.x2;
|
||||
uint32_t y1 = handler->refresh_area_.y1;
|
||||
uint32_t y2 = handler->refresh_area_.y2;
|
||||
uint32_t height = y2 - y1 + 1;
|
||||
uint32_t width = x2 - x1 + 1;
|
||||
|
||||
for (uint32_t row = 0; row < height; ++row) {
|
||||
uint32_t fb_y = y1 + row;
|
||||
uint32_t fb_x_byte_start = x1 / 8;
|
||||
uint32_t fb_x_byte_end = x2 / 8;
|
||||
uint8_t* fb_ptr = &handler->framebuffer_[fb_y * (DISPLAY_WIDTH / 8) + fb_x_byte_start];
|
||||
uint8_t* dest_ptr = &partial_buffer[row * (width / 8)];
|
||||
for (uint32_t i = 0; i < (fb_x_byte_end - fb_x_byte_start + 1); ++i) {
|
||||
dest_ptr[i] = ~fb_ptr[i];
|
||||
// Copy pixel data to partial buffer and invert for e-ink
|
||||
for (int32_t row = 0; row < area_height; ++row) {
|
||||
for (int32_t col = 0; col < area_width_bytes; ++col) {
|
||||
size_t src_index = row * area_width_bytes + col;
|
||||
partial_buffer[src_index] = ~pixel_data[src_index];
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t err = handler->display_handler_->partial_refresh(partial_buffer,
|
||||
handler->refresh_area_);
|
||||
RefreshArea {
|
||||
area->x1,
|
||||
area->y1,
|
||||
area->x2,
|
||||
area->y2
|
||||
}, lv_display_flush_is_last(disp));
|
||||
delete[] partial_buffer;
|
||||
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Partial refresh request failed: %s", esp_err_to_name(err));
|
||||
}
|
||||
handler->refresh_area_.reset();
|
||||
}
|
||||
}
|
||||
//
|
||||
lv_display_flush_ready(disp);
|
||||
@@ -252,31 +213,10 @@ esp_err_t LVGLHandler::initLVGLDisplay_() {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// set framebuffer
|
||||
framebuffer_ = (uint8_t*)heap_caps_malloc(LVGL_BUFFER_SIZE, MALLOC_CAP_SPIRAM);
|
||||
if (framebuffer_ != nullptr) {
|
||||
framebuffer_in_psram_ = true;
|
||||
ESP_LOGI(TAG, "Framebuffer allocated in PSRAM (%zu bytes)", LVGL_BUFFER_SIZE);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "PSRAM not available, allocating framebuffer in internal RAM");
|
||||
framebuffer_ = (uint8_t*)heap_caps_malloc(LVGL_BUFFER_SIZE, MALLOC_CAP_INTERNAL);
|
||||
framebuffer_in_psram_ = false;
|
||||
if (framebuffer_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to allocate framebuffer");
|
||||
lv_display_delete(lvgl_display_);
|
||||
lvgl_display_ = nullptr;
|
||||
lvgl_port_unlock();
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGI(TAG, "Framebuffer allocated in internal RAM (%zu bytes)", LVGL_BUFFER_SIZE);
|
||||
}
|
||||
memset(framebuffer_, 0xFF, LVGL_BUFFER_SIZE); // Initialize to white
|
||||
// Create a draw buffer covering the entire display
|
||||
lvgl_draw_buf_ = lv_draw_buf_create(DISPLAY_WIDTH, DISPLAY_HEIGHT, LV_COLOR_FORMAT_I1, LV_STRIDE_AUTO);
|
||||
if (lvgl_draw_buf_ == nullptr) {
|
||||
ESP_LOGE(TAG, "Failed to create LVGL draw buffer");
|
||||
heap_caps_free(framebuffer_);
|
||||
framebuffer_ = nullptr;
|
||||
lv_display_delete(lvgl_display_);
|
||||
lvgl_display_ = nullptr;
|
||||
lvgl_port_unlock();
|
||||
|
||||
@@ -31,10 +31,4 @@ private:
|
||||
lv_display_t* lvgl_display_ = nullptr;
|
||||
lv_indev_t* lvgl_touch_indev_ = nullptr;
|
||||
lv_draw_buf_t* lvgl_draw_buf_ = nullptr;
|
||||
uint8_t* framebuffer_ = nullptr;
|
||||
bool framebuffer_in_psram_ = false;
|
||||
RefreshArea refresh_area_ = { 0, 0, 0, 0 };
|
||||
|
||||
|
||||
SemaphoreHandle_t lvgl_mutex_ = nullptr;
|
||||
};
|
||||
|
||||
@@ -44,6 +44,40 @@ void init_queues(
|
||||
|
||||
|
||||
|
||||
void random_draw_rect(
|
||||
LVGLHandler* lvgl_handler
|
||||
) {
|
||||
// Draw a random rectangle on the display using LVGL every 2 seconds until 100 rectangles have been drawn
|
||||
static int rect_count = 0;
|
||||
do {
|
||||
|
||||
rect_count++;
|
||||
LVGLHandler* handler = lvgl_handler;
|
||||
if (handler == nullptr) {
|
||||
return;
|
||||
}
|
||||
lvgl_port_lock(pdMS_TO_TICKS(5000));
|
||||
// Create a random rectangle
|
||||
lv_obj_t* rect = lv_obj_create(lv_scr_act());
|
||||
int x = esp_random() % (DISPLAY_WIDTH - 50);
|
||||
int y = esp_random() % (DISPLAY_HEIGHT - 50);
|
||||
lv_obj_set_pos(rect, x, y);
|
||||
int w = 20 + (esp_random() % 100);
|
||||
int h = 20 + (esp_random() % 100);
|
||||
lv_obj_set_size(rect, w, h);
|
||||
// white or black fill for the rect
|
||||
bool is_white = (esp_random() % 2 == 0);
|
||||
lv_obj_set_style_bg_color(rect, is_white ? lv_color_hex(0xFFFFFF) : lv_color_hex(0x000000), 0);
|
||||
|
||||
lvgl_port_unlock();
|
||||
ESP_LOGI(TAG, "Drawn %s rectangle %d at (%d,%d) size (%d x %d)",
|
||||
is_white ? "white" : "black",
|
||||
rect_count, x, y, w, h);
|
||||
// Schedule next rectangle draw
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
} while (rect_count < 100);
|
||||
}
|
||||
|
||||
void EInk_Checkerboard(
|
||||
EInkDisplayHandler* display_handler
|
||||
) {
|
||||
@@ -231,7 +265,7 @@ void LVGL_Checkerboard(
|
||||
}
|
||||
lvgl_port_unlock();
|
||||
// Yield to allow LVGL to process rendering
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +278,7 @@ void LVGL_Checkerboard(
|
||||
checker_params->lvgl_handler = lvgl_handler;
|
||||
BaseType_t res = xTaskCreate(
|
||||
checkerboard_task_fn,
|
||||
"lvgl_checkerboard_task",
|
||||
"lvgl_checkerboard_task0",
|
||||
8192,
|
||||
static_cast<void*>(checker_params),
|
||||
tskIDLE_PRIORITY + 1,
|
||||
@@ -272,14 +306,14 @@ void app_main(void) {
|
||||
ESP_LOGI(TAG, "Queues initialized.\n");
|
||||
|
||||
//
|
||||
// KVStorageHandler* kv_storage_handler = new NVSStorageHandler(
|
||||
// DEFAULT_STORAGE_NAMESPACE
|
||||
// );
|
||||
KVStorageHandler* kv_storage_handler = new NVSStorageHandler(
|
||||
DEFAULT_STORAGE_NAMESPACE
|
||||
);
|
||||
|
||||
// auto wifi_handler = std::make_unique<WifiHandler>(
|
||||
// std::unique_ptr<KVStorageHandler>(new NVSStorageHandler(WIFI_CREDENTIALS_STORAGE_NAMESPACE))
|
||||
// );
|
||||
// NetworkHandler* network_handler = new NetworkHandler(std::move(wifi_handler));
|
||||
auto wifi_handler = std::make_unique<WifiHandler>(
|
||||
std::unique_ptr<KVStorageHandler>(new NVSStorageHandler(WIFI_CREDENTIALS_STORAGE_NAMESPACE))
|
||||
);
|
||||
NetworkHandler* network_handler = new NetworkHandler(std::move(wifi_handler));
|
||||
EInkDisplayHandler* display_handler = new EInkDisplayHandler();
|
||||
// Initialize display and touch
|
||||
// display_handler->init_devices(system_event_group);
|
||||
@@ -296,8 +330,8 @@ void app_main(void) {
|
||||
}
|
||||
|
||||
//
|
||||
// kv_storage_handler->init(system_event_group);
|
||||
// network_handler->init(system_event_group);
|
||||
kv_storage_handler->init(system_event_group);
|
||||
network_handler->init(system_event_group);
|
||||
|
||||
//
|
||||
ESP_LOGI(TAG, "Waiting for system to be ready...\n");
|
||||
@@ -317,13 +351,13 @@ void app_main(void) {
|
||||
|
||||
// Show checkerboard pattern on display for testing
|
||||
// EInk_Checkerboard(display_handler);
|
||||
LVGL_Checkerboard(&lvgl_handler);
|
||||
// LVGL_Checkerboard(&lvgl_handler);
|
||||
|
||||
// Register apps with AppRegistry by creating their descriptors
|
||||
// Each descriptor will create and register the app instance
|
||||
// DemoAppDescriptor* demo_descriptor = new DemoAppDescriptor();
|
||||
// ShutdownAppDescriptor* shutdown_descriptor = new ShutdownAppDescriptor();
|
||||
// DiscordAppDescriptor::instance(); // Use singleton pattern for Discord app
|
||||
DiscordAppDescriptor::instance(); // Use singleton pattern for Discord app
|
||||
// MtrAppDescriptor* mtr_descriptor = new MtrAppDescriptor();
|
||||
|
||||
// Pass network handler to MtrApp so it can fetch arrival data
|
||||
@@ -332,17 +366,17 @@ void app_main(void) {
|
||||
// mtr_app->set_network_handler(network_handler);
|
||||
// }
|
||||
|
||||
// ESP_LOGI(TAG, "Apps registered with AppRegistry\n");
|
||||
ESP_LOGI(TAG, "Apps registered with AppRegistry\n");
|
||||
|
||||
// Initialize UI Handler (will render app icons from registry)
|
||||
// UIHandler ui_handler;
|
||||
// if (ui_handler.init() != ESP_OK) {
|
||||
// ESP_LOGE(TAG, "Failed to initialize UI handler");
|
||||
// vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
// return esp_restart();
|
||||
// }
|
||||
// ESP_LOGI(TAG, "UI handler initialized successfully\n");
|
||||
// ESP_LOGI(TAG, "Main screen displayed with app icons. Tap an icon to launch an app.\n");
|
||||
UIHandler ui_handler;
|
||||
if (ui_handler.init() != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize UI handler");
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
return esp_restart();
|
||||
}
|
||||
ESP_LOGI(TAG, "UI handler initialized successfully\n");
|
||||
ESP_LOGI(TAG, "Main screen displayed with app icons. Tap an icon to launch an app.\n");
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user