editor restarts and close actually sleep the screen

This commit is contained in:
aeroreyna
2026-01-08 23:17:17 -05:00
parent 3681a7f81d
commit 564484aa2e
3 changed files with 109 additions and 43 deletions

View File

@@ -557,20 +557,21 @@ parameter:
Color_Foreground : Select the foreground color Color_Foreground : Select the foreground color
Color_Background : Select the background color Color_Background : Select the background color
******************************************************************************/ ******************************************************************************/
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, bool Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
{ {
UWORD Xpoint = Xstart; UWORD Xpoint = Xstart;
UWORD Ypoint = Ystart; UWORD Ypoint = Ystart;
bool overflow = false;
if (Xstart > Paint.Width || Ystart > Paint.Height) { if (Xstart > Paint.Width || Ystart > Paint.Height) {
Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n"); Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
return; return overflow;
} }
while (* pString != '\0') { while (* pString != '\0') {
//if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
if ((Xpoint + Font->Width ) > Paint.Width ) { if ((Xpoint + Font->Width ) > Paint.Width || * pString == '\n') {
Xpoint = Xstart; Xpoint = Xstart;
Ypoint += Font->Height; Ypoint += Font->Height;
} }
@@ -579,8 +580,11 @@ void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
if ((Ypoint + Font->Height ) > Paint.Height ) { if ((Ypoint + Font->Height ) > Paint.Height ) {
Xpoint = Xstart; Xpoint = Xstart;
Ypoint = Ystart; Ypoint = Ystart;
overflow = true;
}
if(* pString != '\n'){
Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
} }
Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
//The next character of the address //The next character of the address
pString ++; pString ++;
@@ -588,6 +592,7 @@ void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
//The next word of the abscissa increases the font of the broadband //The next word of the abscissa increases the font of the broadband
Xpoint += Font->Width; Xpoint += Font->Width;
} }
return overflow;
} }

View File

@@ -198,7 +198,7 @@ void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color,
//Display string //Display string
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Acsii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Acsii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); bool Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);

View File

@@ -4,6 +4,7 @@
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "pico/multicore.h" #include "pico/multicore.h"
#include "pico/util/queue.h" #include "pico/util/queue.h"
#include "hardware/timer.h"
// e-Paper library includes // e-Paper library includes
#include "DEV_Config.h" #include "DEV_Config.h"
@@ -19,6 +20,8 @@ queue_t q;
void process_command(char *cmd); void process_command(char *cmd);
void core1_entry(); void core1_entry();
bool screen_on = false;
int epaper_init() int epaper_init()
{ {
printf("EPD_4IN2_V2_test Demo\r\n"); printf("EPD_4IN2_V2_test Demo\r\n");
@@ -39,22 +42,29 @@ 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);
screen_on = true;
return 1; return 1;
} }
bool editor_mode = false;
int editor_last_ts = 0;
char screen_log[2000];
int screen_log_i = 0;
sFONT *current_font = &Font16;
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();
EPD_4IN2_V2_Display(BlackImage);
DEV_Delay_ms(1000);
printf("Goto Sleep...\r\n"); printf("Goto Sleep...\r\n");
EPD_4IN2_V2_Sleep(); EPD_4IN2_V2_Sleep();
free(BlackImage); free(BlackImage);
BlackImage = NULL; BlackImage = NULL;
DEV_Delay_ms(2000);//important, at least 2s DEV_Delay_ms(2000);//important, at least 2s
screen_on = false;
return 0; return 0;
} }
@@ -64,13 +74,13 @@ void process_command(char *cmd)
if (strcmp(cmd, "init") == 0) { if (strcmp(cmd, "init") == 0) {
epaper_init(); epaper_init();
printf("e-Paper initialized\n"); printf("e-Paper initialized\n");
} else if (strcmp(cmd, "clear") == 0) { } else if (screen_on && strcmp(cmd, "clear") == 0) {
Paint_Clear(WHITE); Paint_Clear(WHITE);
printf("e-Paper cleared\n"); printf("e-Paper cleared\n");
} else if (strcmp(cmd, "display") == 0) { } else if (screen_on && strcmp(cmd, "display") == 0) {
EPD_4IN2_V2_Display(BlackImage); EPD_4IN2_V2_Display(BlackImage);
printf("Display updated\n"); printf("Display updated\n");
} else if (strcmp(cmd, "draw_test") == 0) { } else if (screen_on && strcmp(cmd, "draw_test") == 0) {
Paint_Clear(WHITE); Paint_Clear(WHITE);
Paint_DrawString_EN(10, 0, "www.waveshare.com", &Font24, WHITE, BLACK); Paint_DrawString_EN(10, 0, "www.waveshare.com", &Font24, WHITE, BLACK);
Paint_DrawString_EN(10, 35, "Pico-ePaper-4.2", &Font24, BLACK, WHITE); Paint_DrawString_EN(10, 35, "Pico-ePaper-4.2", &Font24, BLACK, WHITE);
@@ -78,16 +88,16 @@ void process_command(char *cmd)
Paint_DrawString_CN(10, 110, "微雪电子", &Font24CN, BLACK, WHITE); Paint_DrawString_CN(10, 110, "微雪电子", &Font24CN, BLACK, WHITE);
EPD_4IN2_V2_Display(BlackImage); EPD_4IN2_V2_Display(BlackImage);
printf("Draw test complete\n"); printf("Draw test complete\n");
} else if (strncmp(cmd, "draw_text", 9) == 0) { } else if (screen_on && strncmp(cmd, "draw_text", 9) == 0) {
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, &Font24, BLACK, WHITE); Paint_DrawString_EN(x, y, text, current_font, WHITE, BLACK);
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");
} }
} else if (strncmp(cmd, "draw_point", 10) == 0) { } else if (screen_on && strncmp(cmd, "draw_point", 10) == 0) {
int x, y; int x, y;
if (sscanf(cmd, "draw_point %d %d", &x, &y) == 2) { if (sscanf(cmd, "draw_point %d %d", &x, &y) == 2) {
Paint_DrawPoint(x, y, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT); Paint_DrawPoint(x, y, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
@@ -95,7 +105,7 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid draw_point command format. Use: draw_point x y\n"); printf("Invalid draw_point command format. Use: draw_point x y\n");
} }
} else if (strncmp(cmd, "draw_line", 9) == 0) { } else if (screen_on && strncmp(cmd, "draw_line", 9) == 0) {
int x1, y1, x2, y2; int x1, y1, x2, y2;
if (sscanf(cmd, "draw_line %d %d %d %d", &x1, &y1, &x2, &y2) == 4) { if (sscanf(cmd, "draw_line %d %d %d %d", &x1, &y1, &x2, &y2) == 4) {
Paint_DrawLine(x1, y1, x2, y2, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID); Paint_DrawLine(x1, y1, x2, y2, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
@@ -103,7 +113,7 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid draw_line command format. Use: draw_line x1 y1 x2 y2\n"); printf("Invalid draw_line command format. Use: draw_line x1 y1 x2 y2\n");
} }
} else if (strncmp(cmd, "draw_rectangle", 14) == 0) { } else if (screen_on && strncmp(cmd, "draw_rectangle", 14) == 0) {
int x1, y1, x2, y2; int x1, y1, x2, y2;
if (sscanf(cmd, "draw_rectangle %d %d %d %d", &x1, &y1, &x2, &y2) == 4) { if (sscanf(cmd, "draw_rectangle %d %d %d %d", &x1, &y1, &x2, &y2) == 4) {
Paint_DrawRectangle(x1, y1, x2, y2, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY); Paint_DrawRectangle(x1, y1, x2, y2, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
@@ -111,7 +121,7 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid draw_rectangle command format. Use: draw_rectangle x1 y1 x2 y2\n"); printf("Invalid draw_rectangle command format. Use: draw_rectangle x1 y1 x2 y2\n");
} }
} else if (strncmp(cmd, "draw_circle", 11) == 0) { } else if (screen_on && strncmp(cmd, "draw_circle", 11) == 0) {
int x, y, r; int x, y, r;
if (sscanf(cmd, "draw_circle %d %d %d", &x, &y, &r) == 3) { if (sscanf(cmd, "draw_circle %d %d %d", &x, &y, &r) == 3) {
Paint_DrawCircle(x, y, r, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY); Paint_DrawCircle(x, y, r, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
@@ -119,7 +129,7 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid draw_circle command format. Use: draw_circle x y r\n"); printf("Invalid draw_circle command format. Use: draw_circle x y r\n");
} }
} else if (strncmp(cmd, "draw_num", 8) == 0) { } else if (screen_on && strncmp(cmd, "draw_num", 8) == 0) {
int x, y, num; int x, y, num;
if (sscanf(cmd, "draw_num %d %d %d", &x, &y, &num) == 3) { if (sscanf(cmd, "draw_num %d %d %d", &x, &y, &num) == 3) {
Paint_DrawNum(x, y, num, &Font16, BLACK, WHITE); Paint_DrawNum(x, y, num, &Font16, BLACK, WHITE);
@@ -127,7 +137,7 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid draw_num command format. Use: draw_num x y num\n"); printf("Invalid draw_num command format. Use: draw_num x y num\n");
} }
} else if (strncmp(cmd, "set_pixel", 9) == 0) { } else if (screen_on && strncmp(cmd, "set_pixel", 9) == 0) {
int x, y, color; int x, y, color;
if (sscanf(cmd, "set_pixel %d %d %d", &x, &y, &color) == 3) { if (sscanf(cmd, "set_pixel %d %d %d", &x, &y, &color) == 3) {
Paint_SetPixel(x, y, color); Paint_SetPixel(x, y, color);
@@ -135,12 +145,18 @@ void process_command(char *cmd)
} else { } else {
printf("Invalid set_pixel command format. Use: set_pixel x y color\n"); printf("Invalid set_pixel command format. Use: set_pixel x y color\n");
} }
} else if (strcmp(cmd, "close") == 0) { } else if (screen_on && strcmp(cmd, "close") == 0) {
epaper_close(); epaper_close();
printf("e-Paper closed\n"); printf("e-Paper closed\n");
} else if (screen_on && strcmp(cmd, "editor") == 0) {
editor_mode = true;
absolute_time_t time = get_absolute_time();
editor_last_ts = to_ms_since_boot(time);
printf("Editor mode enabled\n");
} else { } else {
printf("Unknown command: %s\n", cmd); printf("Unknown command: %s\n", cmd);
} }
} }
void core1_entry() { void core1_entry() {
@@ -158,35 +174,74 @@ void core1_entry() {
queue_remove_blocking(&q, &c); queue_remove_blocking(&q, &c);
newChar = true; newChar = true;
if (c == '\n' || c == '\r') { if(editor_mode){
cmd_buffer[i] = '\0'; absolute_time_t time = get_absolute_time();
process_command(cmd_buffer); editor_last_ts = to_ms_since_boot(time);
i = 0; if (c == '\n' || c == '\r') {
// Clear the command buffer display area screen_log[screen_log_i++] = '\n';
Paint_ClearWindows(1, 281, 399, 299, WHITE); } else if (c == '\b' || c == 127) { // Handle backspace
break; if (screen_log_i > 0) {
} else if (c == '\b' || c == 127) { // Handle backspace screen_log_i--;
if (i > 0) { }
i--; } else {
if (screen_log_i < (sizeof(screen_log) - 1)) {
screen_log[screen_log_i++] = c;
}
} }
} else { } else {
if (i < (sizeof(cmd_buffer) - 1)) { if (c == '\n' || c == '\r') {
cmd_buffer[i++] = c; 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){ if(newChar){
cmd_buffer[i] = '\0'; if(!screen_on){
//char text[200]; epaper_init();
//sscanf(cmd_buffer, "199[^\n]", text); }
if(editor_mode){
bool overflow = false;
Paint_Clear(WHITE);
screen_log[screen_log_i] = '\0';
overflow = Paint_DrawString_EN(10, 10, screen_log, current_font, WHITE, BLACK);
if(overflow){
while(screen_log[screen_log_i] != '\n' || screen_log_i>1){
screen_log_i--;
}
if(screen_log_i!=0){
int new_i = 0;
while(screen_log[screen_log_i] != '\0'){
screen_log[new_i++] = screen_log[screen_log_i++];
}
screen_log_i = new_i;
}
Paint_Clear(WHITE);
// if overflow reset the screen_log buffer with only the last line
Paint_DrawString_EN(10, 10, screen_log, current_font, WHITE, BLACK);
}
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, 400, 300);
} else {
cmd_buffer[i] = '\0';
// 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, &Font16, WHITE, BLACK);
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, 400, 300);
}
// 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);
} }
} }
} }
@@ -214,6 +269,12 @@ int main()
printf("%c", c); printf("%c", c);
} }
} }
absolute_time_t time = get_absolute_time();
uint32_t ms = to_ms_since_boot(time);
if(editor_last_ts != 0 && editor_mode && (editor_last_ts + 10000 < ms)){
printf("Disabling editor after 10s of inactivity");
editor_mode = false;
}
} }
epaper_close(); epaper_close();