diff --git a/epaper_manager.cpp b/epaper_manager.cpp index c6ef839..091a66d 100644 --- a/epaper_manager.cpp +++ b/epaper_manager.cpp @@ -12,16 +12,15 @@ // e-Paper library includes extern "C" { #include "DEV_Config.h" - #include "EPD_7in5b_V2.h" + #include "EPD_4in2_V2.h" #include "GUI_Paint.h" } // e-Paper display buffers static UBYTE *g_epd_image = NULL; // Black image buffer -static UBYTE *g_epd_red = NULL; // Red image buffer // Entry list for display -#define MAX_ENTRIES 15 +#define MAX_ENTRIES 10 #define ENTRY_LENGTH 64 typedef struct { char entries[MAX_ENTRIES][ENTRY_LENGTH]; @@ -49,7 +48,7 @@ typedef struct { } DisplayMessage; static void init_epaper_display() { - printf("[Core 1] Initializing 7.5\" e-Paper display (B V2)...\r\n"); + printf("[Core 1] Initializing 4.2\" e-Paper display (V2)...\r\n"); // Initialize the hardware if (DEV_Module_Init() != 0) { @@ -58,38 +57,27 @@ static void init_epaper_display() { } // Initialize the display - printf("[Core 1] EPD_7IN5B_V2_Init()\r\n"); - EPD_7IN5B_V2_Init_Fast(); - printf("[Core 1] EPD_7IN5B_V2_Clear()\r\n"); + printf("[Core 1] EPD_4IN2_V2_Init_Fast()\r\n"); + EPD_4IN2_V2_Init(); + printf("[Core 1] EPD_4IN2_V2_Clear()\r\n"); + EPD_4IN2_V2_Clear(); - // Create image buffers for black and red content - // 7.5" display: 800x480, 8 pixels per byte, so (800/8) * 480 = 48000 bytes each - UWORD imagesize = (EPD_7IN5B_V2_WIDTH / 8) * EPD_7IN5B_V2_HEIGHT; + // Create image buffers for black content + // 4.2" display: 400x300, 8 pixels per byte + UWORD imagesize = ((EPD_4IN2_V2_WIDTH % 8 == 0)? (EPD_4IN2_V2_WIDTH / 8 ): (EPD_4IN2_V2_WIDTH / 8 + 1)) * EPD_4IN2_V2_HEIGHT; g_epd_image = (UBYTE *)malloc(imagesize); - g_epd_red = (UBYTE *)malloc(imagesize); - if (g_epd_image == NULL || g_epd_red == NULL) { + if (g_epd_image == NULL) { printf("[Core 1] Failed to allocate memory for e-Paper image buffers!\r\n"); return; } - // Initialize red buffer to all white (0xFF = no red pixels) - for (UWORD i = 0; i < imagesize; i++) { - g_epd_red[i] = 0xFF; - } - // Setup paint buffer for black content printf("[Core 1] White background\r\n"); - Paint_NewImage(g_epd_image, EPD_7IN5B_V2_WIDTH, EPD_7IN5B_V2_HEIGHT, 0, WHITE); + Paint_NewImage(g_epd_image, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE); Paint_SelectImage(g_epd_image); Paint_Clear(WHITE); - - // Draw header - EPD_7IN5B_V2_Init_Part(); - EPD_7IN5B_V2_Display_Partial(g_epd_image, 0, 0, EPD_7IN5B_V2_WIDTH, EPD_7IN5B_V2_HEIGHT); - EPD_7IN5B_V2_Display_Partial(g_epd_image, 0, 0, EPD_7IN5B_V2_WIDTH, EPD_7IN5B_V2_HEIGHT); - EPD_7IN5B_V2_Display_Partial(g_epd_image, 0, 0, EPD_7IN5B_V2_WIDTH, EPD_7IN5B_V2_HEIGHT); printf("[Core 1] Trying to connect to wifi\r\n"); bool connected = wifi_try_auto_connect(); @@ -99,17 +87,21 @@ static void init_epaper_display() { tcp_debug_init(); } - Paint_SelectImage(g_epd_red); + Paint_SelectImage(g_epd_image); printf("[Core 1] Drawing header\r\n"); if (connected) { - Paint_DrawString_EN(10, 10, "What's new today: ...", &Font24, WHITE, RED); + char header_text[64]; + const char* ip = wifi_get_ip(); + snprintf(header_text, sizeof(header_text), "IP: %s", ip ? ip : "Unknown"); + Paint_DrawString_EN(10, 10, header_text, &Font24, WHITE, BLACK); } else { - Paint_DrawString_EN(10, 10, "What's new today:", &Font24, WHITE, RED); + Paint_DrawString_EN(10, 10, "What's new today:", &Font24, WHITE, BLACK); } - // Display the image with both black and red buffers - EPD_7IN5B_V2_Display_Partial(g_epd_red, 0, 0, EPD_7IN5B_V2_WIDTH, EPD_7IN5B_V2_HEIGHT); + // Display the image + EPD_4IN2_V2_PartialDisplay(g_epd_image, 0, 0, EPD_4IN2_V2_WIDTH, 40); + // EPD_4IN2_V2_Display_Fast(g_epd_image); printf("[Core 1] e-Paper display ready!\r\n"); } @@ -130,7 +122,7 @@ static void core1_display_init() { printf("[Core 1] Display ready, waiting for update messages...\n"); // Initialize for partial refresh on second call - EPD_7IN5B_V2_Init_Part(); + // EPD_4IN2_V2_Init_Fast(Seconds_1S); // Already done in init // Core 1 main loop: handle display updates via Queue while (true) { @@ -141,15 +133,15 @@ static void core1_display_init() { // Drain Queue to get the latest message DisplayMessage *next_msg; while (queue_try_remove(&g_display_queue, &next_msg)) { - printf("[Core 1] Skipping intermediate update\n"); + // printf("[Core 1] Skipping intermediate update\n"); free(msg); // Free the stale message msg = next_msg; } - printf("[Core 1] Updating display with %d entries\n", msg->entries.count); + // printf("[Core 1] Updating display with %d entries\n", msg->entries.count); // Update the e-Paper display - if (g_epd_image != NULL && g_epd_red != NULL) { + if (g_epd_image != NULL) { // For partial refresh, only clear the text area UWORD y_start = msg->ystart; UWORD y_end = msg->yend; @@ -158,13 +150,14 @@ static void core1_display_init() { Paint_Clear(WHITE); // Calculate offset for partial refresh - UBYTE *image_ptr = g_epd_image + (msg->ystart * (EPD_7IN5B_V2_WIDTH / 8)); + // UBYTE *image_ptr = g_epd_image + (msg->ystart * (EPD_4IN2_V2_WIDTH / 8)); if(!msg->use_partial){ // for loop 5 times display white partial + Paint_Clear(WHITE); int i = 0; for(i = 0; i < 1; i++){ - EPD_7IN5B_V2_Display_Partial(image_ptr, msg->xstart, msg->ystart, msg->xend, msg->yend); + EPD_4IN2_V2_PartialDisplay(g_epd_image, 0, 0, 400, 300); } } @@ -173,7 +166,7 @@ static void core1_display_init() { // paint only the last 10 entries int start_index = msg->entries.count > 10 ? msg->entries.count - 10 : 0; for (int i = start_index; i < msg->entries.count; i++) { - if (y_pos + 25 < 480) { //Don't draw beyond screen + if (y_pos + 25 < 300) { //Don't draw beyond screen Paint_DrawString_EN(20, 50 + i*25, msg->entries.entries[i], &Font16, WHITE, BLACK); y_pos += 25; // Space between entries } else { @@ -181,8 +174,8 @@ static void core1_display_init() { } } // Use partial or full refresh - printf("[Core 1] Using partial refresh\n"); - EPD_7IN5B_V2_Display_Partial(image_ptr, msg->xstart, msg->ystart, msg->xend, msg->yend); + // printf("[Core 1] Using partial refresh\n"); + EPD_4IN2_V2_PartialDisplay(g_epd_image, 0, 0, 400, 300); } // Free the message (it was allocated by core 0) @@ -239,13 +232,13 @@ void epaper_send_update(const char *entry, bool finish_line) { // Full text area refresh msg->xstart = 0; msg->ystart = 50; // Start below the header - msg->xend = 800; // Full width - msg->yend = 480; // Full height from header onwards + msg->xend = EPD_4IN2_V2_WIDTH; // Full width + msg->yend = EPD_4IN2_V2_HEIGHT; // Full height from header onwards } else { // Partial refresh of ONLY the current line msg->xstart = 0; msg->ystart = 50 + (g_entry_list.count * 25); - msg->xend = 800; + msg->xend = EPD_4IN2_V2_WIDTH; msg->yend = msg->ystart + 25; }