增加了双击SW2显示五行

Flash资源已用完
This commit is contained in:
CSBOOK\44744
2026-06-28 18:32:50 +08:00
parent 984787d736
commit 104c3a10e0
9 changed files with 307 additions and 10 deletions
+73 -4
View File
@@ -12,6 +12,7 @@
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -272,6 +273,48 @@ static esp_err_t lcd_direct_draw_test_pattern(const lcd_direct_request_t *reques
return ESP_OK;
}
static lcd_direct_rle_run_t *lcd_direct_load_icon_runs(const lcd_direct_icon_t *icon)
{
if (icon == NULL || icon->path == NULL || icon->run_count == 0U) {
return NULL;
}
const size_t bytes_to_read = icon->run_count * sizeof(lcd_direct_rle_run_t);
lcd_direct_rle_run_t *runs = (lcd_direct_rle_run_t *)malloc(bytes_to_read);
if (runs == NULL) {
ESP_LOGW(TAG, "allocate LCD icon failed path=%s bytes=%u", icon->path, (unsigned)bytes_to_read);
return NULL;
}
errno = 0;
int fd = open(icon->path, O_RDONLY);
if (fd < 0) {
ESP_LOGW(TAG, "open LCD icon failed path=%s errno=%d", icon->path, errno);
free(runs);
return NULL;
}
size_t offset = 0;
while (offset < bytes_to_read) {
ssize_t bytes_read = read(fd, ((uint8_t *)runs) + offset, bytes_to_read - offset);
if (bytes_read <= 0) {
ESP_LOGW(TAG,
"read LCD icon failed path=%s requested=%u read=%d errno=%d",
icon->path,
(unsigned)bytes_to_read,
(int)bytes_read,
errno);
close(fd);
free(runs);
return NULL;
}
offset += (size_t)bytes_read;
}
close(fd);
return runs;
}
static void lcd_direct_overlay_icons(uint16_t *pixel_buffer,
uint16_t row_start,
uint16_t row_count,
@@ -286,13 +329,23 @@ static void lcd_direct_overlay_icons(uint16_t *pixel_buffer,
for (size_t icon_index = 0; icon_index < icon_count; ++icon_index) {
const lcd_direct_icon_draw_t *draw = &icons[icon_index];
const lcd_direct_icon_t *icon = lcd_direct_icon(draw->icon_id);
if (icon == NULL || icon->runs == NULL || icon->width == 0U || icon->height == 0U) {
if (icon == NULL || icon->width == 0U || icon->height == 0U) {
continue;
}
if (draw->x >= LCD_DIRECT_WIDTH || draw->y >= LCD_DIRECT_HEIGHT) {
continue;
}
lcd_direct_rle_run_t *loaded_runs = NULL;
const lcd_direct_rle_run_t *runs = icon->runs;
if (runs == NULL) {
loaded_runs = lcd_direct_load_icon_runs(icon);
runs = loaded_runs;
}
if (runs == NULL) {
continue;
}
uint16_t draw_width = icon->width;
uint16_t draw_height = icon->height;
if (draw_width > LCD_DIRECT_WIDTH - draw->x) {
@@ -305,6 +358,7 @@ static void lcd_direct_overlay_icons(uint16_t *pixel_buffer,
const uint16_t overlay_y0 = draw->y;
const uint16_t overlay_y1 = draw->y + draw_height;
if (overlay_y1 <= row_start || overlay_y0 >= row_end) {
free(loaded_runs);
continue;
}
@@ -321,11 +375,11 @@ static void lcd_direct_overlay_icons(uint16_t *pixel_buffer,
run_index < icon->run_count && icon_pixel_pos < icon_pixel_end;
++run_index) {
const uint32_t run_start = icon_pixel_pos;
const uint32_t run_end = run_start + icon->runs[run_index].count;
const uint32_t run_end = run_start + runs[run_index].count;
if (run_end > icon_pixel_start && run_start < icon_pixel_end) {
const uint32_t copy_start = run_start > icon_pixel_start ? run_start : icon_pixel_start;
const uint32_t copy_end = run_end < icon_pixel_end ? run_end : icon_pixel_end;
const uint16_t color = lcd_direct_swap_color(icon->runs[run_index].color);
const uint16_t color = lcd_direct_swap_color(runs[run_index].color);
for (uint32_t x = copy_start; x < copy_end; ++x) {
pixel_buffer[(uint32_t)local_y * LCD_DIRECT_WIDTH + draw->x + (x - icon_pixel_start)] = color;
}
@@ -333,6 +387,8 @@ static void lcd_direct_overlay_icons(uint16_t *pixel_buffer,
icon_pixel_pos = run_end;
}
}
free(loaded_runs);
}
}
@@ -671,7 +727,20 @@ static esp_err_t lcd_direct_play_step_sequence(const lcd_direct_request_t *reque
step->asset_dir != NULL ? step->asset_dir : "<null>",
(unsigned)step->frame_index);
ESP_RETURN_ON_ERROR(lcd_direct_draw_rle_image(frame, NULL, 0),
lcd_direct_icon_draw_t icon = {0};
const lcd_direct_icon_draw_t *icons = NULL;
size_t icon_count = 0;
if (step->icon_id != PLATFORM_LCD_PRESENTATION_NO_ICON) {
icon = (lcd_direct_icon_draw_t) {
.icon_id = step->icon_id,
.x = step->icon_x,
.y = step->icon_y,
};
icons = &icon;
icon_count = 1;
}
ESP_RETURN_ON_ERROR(lcd_direct_draw_rle_image(frame, icons, icon_count),
TAG,
"draw step frame failed");