From a1add6b61b7c8131e6220eccbb18071b0345390f Mon Sep 17 00:00:00 2001 From: Sani7 Date: Sat, 2 Dec 2023 22:19:10 +0100 Subject: [PATCH] tcp_cmd add argb capability to color and bgcolor --- project/Core/Src/tcp_cmd.c | 48 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/project/Core/Src/tcp_cmd.c b/project/Core/Src/tcp_cmd.c index 7b2b236..1b16e3a 100644 --- a/project/Core/Src/tcp_cmd.c +++ b/project/Core/Src/tcp_cmd.c @@ -46,15 +46,15 @@ static void tcp_cmd_print_header(struct tcp_pcb* pcb) { * @param pcb The tcp_pcb struct to write to */ static void tcp_cmd_print_help(struct tcp_pcb* pcb) { - tcp_cmd_write(pcb, "help : shows a list of commands\n" - "clear text/images : clears the text or images on the lcd\n" - "text \"\" : puts text on the lcd\n" - "bgColor : set the background color of the lcd\n" - "color : set the color of the text\n" - "listFiles : shows a list with images in the filesystem\n" - "setImage : put an image on the screen\n" - "setGif : put a gif on the screen\n" - "exit : closes the connection\n"); + tcp_cmd_write(pcb, "help : shows a list of commands\n" + "clear text/images : clears the text or images on the lcd\n" + "text \"\" : puts text on the lcd\n" + "bgColor () : set the background color of the lcd\n" + "color () : set the color of the text\n" + "listFiles : shows a list with images in the filesystem\n" + "setImage : put an image on the screen\n" + "setGif : put a gif on the screen\n" + "exit : closes the connection\n"); } /** @@ -218,7 +218,7 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) { if (argc == 2) { LOG_INFO(TAG, "Setting background color to %s", argv[1]); color_bg = (uint32_t)strtoul(argv[1], NULL, 16); - color_bg |= 0xff000000; + color_bg ^= 0xff000000; return false; } if (argc == 4) { @@ -229,16 +229,27 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) { color_bg |= (uint32_t)strtoul(argv[3], NULL, 10); return false; } + if (argc == 5) { + LOG_INFO(TAG, "Setting text color to %s %s %s %s", argv[1], argv[2], argv[3], argv[4]); + color_txt = 0xff000000; + color_txt ^= (uint32_t)strtoul(argv[1], NULL, 10) << 24; + color_txt |= (uint32_t)strtoul(argv[2], NULL, 10) << 16; + color_txt |= (uint32_t)strtoul(argv[3], NULL, 10) << 8; + color_txt |= (uint32_t)strtoul(argv[4], NULL, 10); + return false; + } LOG_WARN(TAG, "Bad usage of bgcolor"); - tcp_cmd_write(pcb, "Usage: bgcolor \n"); + tcp_cmd_write(pcb, "Usage: bgcolor 0x\n"); + tcp_cmd_write(pcb, "Usage: bgcolor 0x\n"); tcp_cmd_write(pcb, "Usage: bgcolor r g b\n"); + tcp_cmd_write(pcb, "Usage: bgcolor a r g b\n"); return false; } if (strcmp(argv[0], "color") == 0) { if (argc == 2) { LOG_INFO(TAG, "Setting text color to %s", argv[1]); color_txt = (uint32_t)strtoul(argv[1], NULL, 16); - color_txt |= 0xff000000; + color_txt ^= 0xff000000; return false; } if (argc == 4) { @@ -249,9 +260,20 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) { color_txt |= (uint32_t)strtoul(argv[3], NULL, 10); return false; } + if (argc == 5) { + LOG_INFO(TAG, "Setting text color to %s %s %s %s", argv[1], argv[2], argv[3], argv[4]); + color_txt = 0xff000000; + color_txt ^= (uint32_t)strtoul(argv[1], NULL, 10) << 24; + color_txt |= (uint32_t)strtoul(argv[2], NULL, 10) << 16; + color_txt |= (uint32_t)strtoul(argv[3], NULL, 10) << 8; + color_txt |= (uint32_t)strtoul(argv[4], NULL, 10); + return false; + } LOG_WARN(TAG, "Bad usage of color"); - tcp_cmd_write(pcb, "Usage: color 0x\n"); + tcp_cmd_write(pcb, "Usage: color 0x\n"); + tcp_cmd_write(pcb, "Usage: color 0x\n"); tcp_cmd_write(pcb, "Usage: color \n"); + tcp_cmd_write(pcb, "Usage: color \n"); return false; } if (strcmp(argv[0], "listfiles") == 0) {