show commands as typed on screen
This commit is contained in:
@@ -60,7 +60,7 @@ target_include_directories(eink_api PRIVATE
|
||||
|
||||
# Add the standard library to the build
|
||||
target_link_libraries(eink_api
|
||||
pico_stdlib ePaper GUI Fonts hardware_spi)
|
||||
pico_stdlib ePaper GUI Fonts hardware_spi pico_multicore)
|
||||
|
||||
# Add the standard include files to the build
|
||||
target_include_directories(eink_api PRIVATE
|
||||
|
||||
81
eink_api.c
81
eink_api.c
@@ -2,6 +2,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/util/queue.h"
|
||||
|
||||
// e-Paper library includes
|
||||
#include "DEV_Config.h"
|
||||
@@ -12,7 +14,10 @@
|
||||
//Create a new image cache
|
||||
UBYTE *BlackImage;
|
||||
|
||||
queue_t q;
|
||||
|
||||
void process_command(char *cmd);
|
||||
void core1_entry();
|
||||
|
||||
int epaper_init()
|
||||
{
|
||||
@@ -34,7 +39,6 @@ int epaper_init()
|
||||
}
|
||||
printf("Paint_NewImage\r\n");
|
||||
Paint_NewImage(BlackImage, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE);
|
||||
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -44,8 +48,8 @@ int epaper_init()
|
||||
int epaper_close()
|
||||
{
|
||||
DEV_Delay_ms(1000);
|
||||
// EPD_4IN2_V2_Init();
|
||||
// EPD_4IN2_V2_Clear();
|
||||
EPD_4IN2_V2_Init();
|
||||
EPD_4IN2_V2_Clear();
|
||||
printf("Goto Sleep...\r\n");
|
||||
EPD_4IN2_V2_Sleep();
|
||||
free(BlackImage);
|
||||
@@ -64,7 +68,7 @@ void process_command(char *cmd)
|
||||
Paint_Clear(WHITE);
|
||||
printf("e-Paper cleared\n");
|
||||
} else if (strcmp(cmd, "display") == 0) {
|
||||
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT);
|
||||
EPD_4IN2_V2_Display(BlackImage);
|
||||
printf("Display updated\n");
|
||||
} else if (strcmp(cmd, "draw_test") == 0) {
|
||||
Paint_Clear(WHITE);
|
||||
@@ -78,7 +82,7 @@ void process_command(char *cmd)
|
||||
int x, y;
|
||||
char text[200];
|
||||
if (sscanf(cmd, "draw_text %d %d %199[^\n]", &x, &y, text) == 3) {
|
||||
Paint_DrawString_EN(x, y, text, &Font16, WHITE, BLACK);
|
||||
Paint_DrawString_EN(x, y, text, &Font24, BLACK, WHITE);
|
||||
printf("Drew text at %d, %d: %s\n", x, y, text);
|
||||
} else {
|
||||
printf("Invalid draw_text command format. Use: draw_text x y text\n");
|
||||
@@ -139,39 +143,78 @@ void process_command(char *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
void core1_entry() {
|
||||
epaper_init();
|
||||
|
||||
EPD_4IN2_V2_Display(BlackImage);
|
||||
|
||||
char cmd_buffer[256];
|
||||
int i = 0;
|
||||
|
||||
while (true) {
|
||||
bool newChar = false;
|
||||
while (!queue_is_empty(&q)) {
|
||||
int c;
|
||||
queue_remove_blocking(&q, &c);
|
||||
newChar = true;
|
||||
|
||||
if (c == '\n' || c == '\r') {
|
||||
cmd_buffer[i] = '\0';
|
||||
process_command(cmd_buffer);
|
||||
i = 0;
|
||||
// Clear the command buffer display area
|
||||
Paint_ClearWindows(1, 281, 399, 299, WHITE);
|
||||
break;
|
||||
} else if (c == '\b' || c == 127) { // Handle backspace
|
||||
if (i > 0) {
|
||||
i--;
|
||||
}
|
||||
} else {
|
||||
if (i < (sizeof(cmd_buffer) - 1)) {
|
||||
cmd_buffer[i++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(newChar){
|
||||
cmd_buffer[i] = '\0';
|
||||
//char text[200];
|
||||
//sscanf(cmd_buffer, "199[^\n]", text);
|
||||
|
||||
// Update the command buffer display
|
||||
Paint_ClearWindows(2, 271, 399, 299, WHITE);
|
||||
Paint_DrawRectangle(1, 270, 400, 300, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
|
||||
// printf("Current: %s, buff:%s\n", text, cmd_buffer);
|
||||
Paint_DrawString_EN(10, 275, cmd_buffer, &Font24, WHITE, BLACK);
|
||||
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, 400, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
stdio_init_all();
|
||||
|
||||
epaper_init();
|
||||
|
||||
printf("e-ink api ready\n");
|
||||
|
||||
char cmd_buffer[256];
|
||||
int i = 0;
|
||||
queue_init(&q, sizeof(int), 256);
|
||||
|
||||
multicore_launch_core1(core1_entry);
|
||||
|
||||
while (true) {
|
||||
int c = getchar_timeout_us(0);
|
||||
if (c != PICO_ERROR_TIMEOUT) {
|
||||
queue_add_blocking(&q, &c);
|
||||
if (c == '\n' || c == '\r') {
|
||||
printf("\n");
|
||||
cmd_buffer[i] = '\0';
|
||||
process_command(cmd_buffer);
|
||||
i = 0;
|
||||
} else if (c == '\b' || c == 127) { // Handle backspace
|
||||
if (i > 0) {
|
||||
i--;
|
||||
} else if (c == '\b' || c == 127) {
|
||||
printf("\b \b");
|
||||
}
|
||||
} else {
|
||||
if (i < (sizeof(cmd_buffer) - 1)) {
|
||||
cmd_buffer[i++] = c;
|
||||
printf("%c", c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
epaper_close();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user