feature to send image from tcp connection

This commit is contained in:
Adolfo Reyna
2025-12-28 21:59:59 -05:00
parent 03e826653b
commit ed927e16b1
9 changed files with 212 additions and 3 deletions

View File

@@ -45,6 +45,7 @@ typedef struct {
UWORD ystart;
UWORD xend;
UWORD yend;
UBYTE *raw_image; // Pointer to raw image data (if not NULL, display this instead of text)
} DisplayMessage;
static void init_epaper_display() {
@@ -141,7 +142,11 @@ static void core1_display_init() {
// printf("[Core 1] Updating display with %d entries\n", msg->entries.count);
// Update the e-Paper display
if (g_epd_image != NULL) {
if (msg->raw_image != NULL) {
printf("[Core 1] Displaying raw image...\n");
EPD_4IN2_V2_Display(msg->raw_image);
free(msg->raw_image); // Free the image buffer allocated by Core 0
} else if (g_epd_image != NULL) {
// For partial refresh, only clear the text area
UWORD y_start = msg->ystart;
UWORD y_end = msg->yend;
@@ -219,6 +224,7 @@ void epaper_send_update(const char *entry, bool finish_line) {
// Copy entry list to message
msg->entries = g_entry_list;
msg->raw_image = NULL; // Not an image update
// We want to show the current line being edited, so we treat count as count + 1 for display purposes
msg->entries.count = g_entry_list.count + 1;
@@ -246,7 +252,11 @@ void epaper_send_update(const char *entry, bool finish_line) {
if (queue_try_add(&g_display_queue, &msg)) {
// printf("[Core 0] Display update sent to core 1\n");
} else {
printf("[Core 0] Queue full, skipping display update\n");
static int full_count = 0;
if (full_count < 5) {
printf("[Core 0] Queue full, skipping display update\n");
full_count++;
}
free(msg);
}
@@ -267,3 +277,31 @@ void epaper_force_refresh() {
g_force_full_refresh = true;
epaper_send_update("", false);
}
void epaper_display_full_image(const unsigned char* image_data, unsigned int len) {
if (!g_display_ready) return;
// Allocate message structure
DisplayMessage *msg = (DisplayMessage *)malloc(sizeof(DisplayMessage));
if (msg == NULL) {
printf("[Core 0] Failed to allocate display message for image!\n");
return;
}
// We are passing ownership of the image buffer to the message/Core 1
// The caller should have allocated image_data with malloc
msg->raw_image = (UBYTE*)image_data;
msg->use_partial = false; // Full refresh for images
// Send message pointer to core 1 via Queue
if (queue_try_add(&g_display_queue, &msg)) {
printf("[Core 0] Image update sent to core 1\n");
} else {
printf("[Core 0] Queue full, skipping image update\n");
free(msg);
// Note: We don't free image_data here because the caller might expect it to be consumed or not.
// Ideally, if we fail to send, we should free it if we took ownership.
// Let's assume we take ownership.
free((void*)image_data);
}
}