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
|
# Add the standard library to the build
|
||||||
target_link_libraries(eink_api
|
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
|
# Add the standard include files to the build
|
||||||
target_include_directories(eink_api PRIVATE
|
target_include_directories(eink_api PRIVATE
|
||||||
|
|||||||
87
eink_api.c
87
eink_api.c
@@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
|
#include "pico/multicore.h"
|
||||||
|
#include "pico/util/queue.h"
|
||||||
|
|
||||||
// e-Paper library includes
|
// e-Paper library includes
|
||||||
#include "DEV_Config.h"
|
#include "DEV_Config.h"
|
||||||
@@ -12,7 +14,10 @@
|
|||||||
//Create a new image cache
|
//Create a new image cache
|
||||||
UBYTE *BlackImage;
|
UBYTE *BlackImage;
|
||||||
|
|
||||||
|
queue_t q;
|
||||||
|
|
||||||
void process_command(char *cmd);
|
void process_command(char *cmd);
|
||||||
|
void core1_entry();
|
||||||
|
|
||||||
int epaper_init()
|
int epaper_init()
|
||||||
{
|
{
|
||||||
@@ -34,7 +39,6 @@ int epaper_init()
|
|||||||
}
|
}
|
||||||
printf("Paint_NewImage\r\n");
|
printf("Paint_NewImage\r\n");
|
||||||
Paint_NewImage(BlackImage, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -44,8 +48,8 @@ int epaper_init()
|
|||||||
int epaper_close()
|
int epaper_close()
|
||||||
{
|
{
|
||||||
DEV_Delay_ms(1000);
|
DEV_Delay_ms(1000);
|
||||||
// EPD_4IN2_V2_Init();
|
EPD_4IN2_V2_Init();
|
||||||
// EPD_4IN2_V2_Clear();
|
EPD_4IN2_V2_Clear();
|
||||||
printf("Goto Sleep...\r\n");
|
printf("Goto Sleep...\r\n");
|
||||||
EPD_4IN2_V2_Sleep();
|
EPD_4IN2_V2_Sleep();
|
||||||
free(BlackImage);
|
free(BlackImage);
|
||||||
@@ -64,7 +68,7 @@ void process_command(char *cmd)
|
|||||||
Paint_Clear(WHITE);
|
Paint_Clear(WHITE);
|
||||||
printf("e-Paper cleared\n");
|
printf("e-Paper cleared\n");
|
||||||
} else if (strcmp(cmd, "display") == 0) {
|
} 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");
|
printf("Display updated\n");
|
||||||
} else if (strcmp(cmd, "draw_test") == 0) {
|
} else if (strcmp(cmd, "draw_test") == 0) {
|
||||||
Paint_Clear(WHITE);
|
Paint_Clear(WHITE);
|
||||||
@@ -78,7 +82,7 @@ void process_command(char *cmd)
|
|||||||
int x, y;
|
int x, y;
|
||||||
char text[200];
|
char text[200];
|
||||||
if (sscanf(cmd, "draw_text %d %d %199[^\n]", &x, &y, text) == 3) {
|
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);
|
printf("Drew text at %d, %d: %s\n", x, y, text);
|
||||||
} else {
|
} else {
|
||||||
printf("Invalid draw_text command format. Use: draw_text x y text\n");
|
printf("Invalid draw_text command format. Use: draw_text x y text\n");
|
||||||
@@ -139,36 +143,75 @@ 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()
|
int main()
|
||||||
{
|
{
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
epaper_init();
|
|
||||||
|
|
||||||
printf("e-ink api ready\n");
|
printf("e-ink api ready\n");
|
||||||
|
|
||||||
|
queue_init(&q, sizeof(int), 256);
|
||||||
|
|
||||||
|
multicore_launch_core1(core1_entry);
|
||||||
|
|
||||||
char cmd_buffer[256];
|
|
||||||
int i = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getchar_timeout_us(0);
|
int c = getchar_timeout_us(0);
|
||||||
if (c != PICO_ERROR_TIMEOUT) {
|
if (c != PICO_ERROR_TIMEOUT) {
|
||||||
|
queue_add_blocking(&q, &c);
|
||||||
if (c == '\n' || c == '\r') {
|
if (c == '\n' || c == '\r') {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
cmd_buffer[i] = '\0';
|
} else if (c == '\b' || c == 127) {
|
||||||
process_command(cmd_buffer);
|
printf("\b \b");
|
||||||
i = 0;
|
|
||||||
} else if (c == '\b' || c == 127) { // Handle backspace
|
|
||||||
if (i > 0) {
|
|
||||||
i--;
|
|
||||||
printf("\b \b");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (i < (sizeof(cmd_buffer) - 1)) {
|
printf("%c", c);
|
||||||
cmd_buffer[i++] = c;
|
|
||||||
printf("%c", c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user