增加了双击SW2显示五行
Flash资源已用完
This commit is contained in:
@@ -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");
|
||||
|
||||
|
||||
@@ -129,6 +129,101 @@ static const lcd_direct_image_t s_chouqian_zhongshang_frames[] = {
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_qianzhiwuxing_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "qianzhiwuxing0.rle",
|
||||
.run_count = 4157U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_shui_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "shui0.rle",
|
||||
.run_count = 74146U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "shui1.rle",
|
||||
.run_count = 71868U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_mu_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "mu0.rle",
|
||||
.run_count = 73537U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "mu1.rle",
|
||||
.run_count = 69337U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_huo_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "huo0.rle",
|
||||
.run_count = 74455U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "huo1.rle",
|
||||
.run_count = 72474U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_tu_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "tu0.rle",
|
||||
.run_count = 95829U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "tu1.rle",
|
||||
.run_count = 71964U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t s_jin_frames[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "jin0.rle",
|
||||
.run_count = 75151U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "jin1.rle",
|
||||
.run_count = 72012U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_icon_t s_wuxing_icons[] = {
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "icon_shui0.rle",
|
||||
.run_count = 549U,
|
||||
.width = 60U,
|
||||
.height = 56U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "icon_mu0.rle",
|
||||
.run_count = 1005U,
|
||||
.width = 86U,
|
||||
.height = 50U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "icon_huo0.rle",
|
||||
.run_count = 565U,
|
||||
.width = 56U,
|
||||
.height = 58U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "icon_tu0.rle",
|
||||
.run_count = 754U,
|
||||
.width = 75U,
|
||||
.height = 42U,
|
||||
},
|
||||
{
|
||||
.path = LCD_ASSET_BASE_PATH "icon_jin0.rle",
|
||||
.run_count = 605U,
|
||||
.width = 65U,
|
||||
.height = 44U,
|
||||
},
|
||||
};
|
||||
|
||||
static const lcd_direct_image_t *lcd_direct_frame_from_array(const lcd_direct_image_t *frames,
|
||||
size_t frame_count,
|
||||
uint8_t frame_index)
|
||||
@@ -198,13 +293,51 @@ const lcd_direct_image_t *lcd_direct_asset_frame(const char *asset_dir, uint8_t
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "qianzhiwuxing") == 0) {
|
||||
return lcd_direct_frame_from_array(s_qianzhiwuxing_frames,
|
||||
sizeof(s_qianzhiwuxing_frames) / sizeof(s_qianzhiwuxing_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "shui") == 0) {
|
||||
return lcd_direct_frame_from_array(s_shui_frames,
|
||||
sizeof(s_shui_frames) / sizeof(s_shui_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "mu") == 0) {
|
||||
return lcd_direct_frame_from_array(s_mu_frames,
|
||||
sizeof(s_mu_frames) / sizeof(s_mu_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "huo") == 0) {
|
||||
return lcd_direct_frame_from_array(s_huo_frames,
|
||||
sizeof(s_huo_frames) / sizeof(s_huo_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "tu") == 0) {
|
||||
return lcd_direct_frame_from_array(s_tu_frames,
|
||||
sizeof(s_tu_frames) / sizeof(s_tu_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
if (strcmp(asset_dir, "jin") == 0) {
|
||||
return lcd_direct_frame_from_array(s_jin_frames,
|
||||
sizeof(s_jin_frames) / sizeof(s_jin_frames[0]),
|
||||
frame_index);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const lcd_direct_icon_t *lcd_direct_icon(uint16_t icon_id)
|
||||
{
|
||||
(void)icon_id;
|
||||
return NULL;
|
||||
if (icon_id >= (sizeof(s_wuxing_icons) / sizeof(s_wuxing_icons[0]))) {
|
||||
return NULL;
|
||||
}
|
||||
return &s_wuxing_icons[icon_id];
|
||||
}
|
||||
|
||||
const lcd_direct_icon_draw_t *lcd_direct_default_icon_sequence(size_t *out_count)
|
||||
|
||||
Reference in New Issue
Block a user