adding custom fonts and editor mode with tab
This commit is contained in:
+54
-31
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef M_PI
|
||||
@@ -17,9 +18,11 @@
|
||||
#include "GUI_Paint.h"
|
||||
#include "fonts.h"
|
||||
#include "EPD_4in2_V2.h"
|
||||
#include "acme_5_outlines_font.h"
|
||||
|
||||
//Create a new image cache
|
||||
UBYTE *BlackImage;
|
||||
UBYTE *EditorImage;
|
||||
|
||||
queue_t q;
|
||||
|
||||
@@ -47,6 +50,10 @@ int epaper_init()
|
||||
printf("Failed to apply for black memory...\r\n");
|
||||
return -1;
|
||||
}
|
||||
if((EditorImage = (UBYTE *)malloc(Imagesize)) == NULL) {
|
||||
printf("Failed to apply for editor memory...\r\n");
|
||||
return -1;
|
||||
}
|
||||
printf("Paint_NewImage\r\n");
|
||||
Paint_NewImage(BlackImage, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE);
|
||||
screen_on = true;
|
||||
@@ -88,7 +95,7 @@ bool editor_mode = false;
|
||||
uint32_t editor_last_ts = 0;
|
||||
char screen_log[2000];
|
||||
int screen_log_i = 0;
|
||||
sFONT *current_font = &Font16;
|
||||
sFONT *current_font = &Font12;
|
||||
UBYTE editor_bg_color = WHITE;
|
||||
UBYTE editor_fg_color = BLACK;
|
||||
|
||||
@@ -110,11 +117,20 @@ int epaper_close()
|
||||
|
||||
void process_command(char *cmd)
|
||||
{
|
||||
printf("Processing command: %s\n", cmd);
|
||||
if(!editor_mode) printf("Processing command: %s\n", cmd);
|
||||
Paint_NewImage(BlackImage, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE);
|
||||
if (strcmp(cmd, "init") == 0) {
|
||||
epaper_init();
|
||||
printf("e-Paper initialized\n");
|
||||
} else if (screen_on && strcmp(cmd, "clear") == 0) {
|
||||
} else if (screen_on && strcmp(cmd, "clear") == 0 && (cmd[5] == ' ' || cmd[5] == '\0')) {
|
||||
if(editor_mode){
|
||||
screen_log_i = 0;
|
||||
screen_log[0] = '\0';
|
||||
} else {
|
||||
Paint_Clear(WHITE);
|
||||
printf("e-Paper cleared\n");
|
||||
}
|
||||
} else if (screen_on && strcmp(cmd, "clear_draw") == 0) {
|
||||
Paint_Clear(WHITE);
|
||||
printf("e-Paper cleared\n");
|
||||
} else if (screen_on && strcmp(cmd, "display") == 0) {
|
||||
@@ -241,13 +257,14 @@ void process_command(char *cmd)
|
||||
screen_log_i = 0;
|
||||
screen_log[0] = '\0';
|
||||
}
|
||||
editor_mode = true;
|
||||
absolute_time_t time = get_absolute_time();
|
||||
editor_last_ts = to_ms_since_boot(time);
|
||||
// editor_mode = true;
|
||||
// absolute_time_t time = get_absolute_time();
|
||||
// editor_last_ts = to_ms_since_boot(time);
|
||||
printf("Editor mode enabled (%s background)\n", invert_flag != 0 ? "black" : "white");
|
||||
} else {
|
||||
printf("Unknown command: %s\n", cmd);
|
||||
if(!editor_mode) printf("Unknown command: %s\n", cmd);
|
||||
}
|
||||
if(editor_mode) Paint_NewImage(EditorImage, EPD_4IN2_V2_WIDTH, EPD_4IN2_V2_HEIGHT, 0, WHITE);
|
||||
|
||||
}
|
||||
|
||||
@@ -258,6 +275,7 @@ void core1_entry() {
|
||||
|
||||
char cmd_buffer[256];
|
||||
int i = 0;
|
||||
bool display_image_on_editor = false;
|
||||
|
||||
while (true) {
|
||||
bool newChar = false;
|
||||
@@ -267,8 +285,9 @@ void core1_entry() {
|
||||
newChar = true;
|
||||
|
||||
if(editor_mode){
|
||||
absolute_time_t time = get_absolute_time();
|
||||
editor_last_ts = to_ms_since_boot(time);
|
||||
// absolute_time_t time = get_absolute_time();
|
||||
// editor_last_ts = to_ms_since_boot(time);
|
||||
display_image_on_editor = false;
|
||||
if (c == '\n' || c == '\r') {
|
||||
screen_log[screen_log_i++] = '\n';
|
||||
} else if (c == '\b' || c == 127) { // Handle backspace
|
||||
@@ -280,22 +299,26 @@ void core1_entry() {
|
||||
screen_log[screen_log_i++] = c;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (c == '\n' || c == '\r') {
|
||||
cmd_buffer[i] = '\0';
|
||||
process_command(cmd_buffer);
|
||||
i = 0;
|
||||
// Clear the command buffer display area
|
||||
}
|
||||
if (c == '\n' || c == '\r') {
|
||||
cmd_buffer[i] = '\0';
|
||||
process_command(cmd_buffer);
|
||||
i = 0;
|
||||
// Clear the command buffer display area
|
||||
if(!editor_mode){
|
||||
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;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (c == '\b' || c == 127) { // Handle backspace
|
||||
if (i > 0) {
|
||||
i--;
|
||||
}
|
||||
} else if (c == '\t'){
|
||||
editor_mode = !editor_mode;
|
||||
//display_image_on_editor = true;
|
||||
} else {
|
||||
if (i < (sizeof(cmd_buffer) - 1)) {
|
||||
cmd_buffer[i++] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,7 +348,7 @@ void core1_entry() {
|
||||
// if overflow reset the screen_log buffer with only the last line
|
||||
Paint_DrawString_EN(10, 10, screen_log, current_font, editor_bg_color, editor_fg_color);
|
||||
}
|
||||
EPD_4IN2_V2_PartialDisplay(BlackImage, 0, 0, 400, 300);
|
||||
EPD_4IN2_V2_PartialDisplay(EditorImage, 0, 0, 400, 300);
|
||||
} else {
|
||||
cmd_buffer[i] = '\0';
|
||||
// Update the command buffer display
|
||||
@@ -373,12 +396,12 @@ int main()
|
||||
}
|
||||
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;
|
||||
editor_bg_color = WHITE;
|
||||
editor_fg_color = BLACK;
|
||||
}
|
||||
//if(editor_last_ts != 0 && editor_mode && (editor_last_ts + 10000 < ms)){
|
||||
// printf("Disabling editor after 10s of inactivity");
|
||||
// editor_mode = false;
|
||||
// editor_bg_color = WHITE;
|
||||
// editor_fg_color = BLACK;
|
||||
//}
|
||||
}
|
||||
|
||||
epaper_close();
|
||||
|
||||
Reference in New Issue
Block a user