Added clear support and cleaned up code

This commit is contained in:
Roelandts_Gert
2023-11-22 17:12:24 +01:00
committed by Sander Speetjens
parent f11f71020d
commit e852d29824

View File

@@ -9,49 +9,40 @@
uint32_t result_txt = 0xff000000;
uint32_t result_bg = 0xff000000;
static void echo_close (struct tcp_pcb *pcb )
{
static void echo_close(struct tcp_pcb* pcb) {
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_close(pcb);
}
static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err )
{
static err_t echo_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
int i;
int len;
int file_in_fs;
u16_t len_text;
char *pc;
int check = 0;
char *pc;
char tcp_buffer[1024];
char text[256];
char colorR[3];
char colorG[3];
char colorB[3];
char color_r[3];
char color_g[3];
char color_b[3];
char textColorR[3];
char textColorG[3];
char textColorB[3];
char text_color_r[3];
char text_color_g[3];
char text_color_b[3];
char extension[4];
char *endptr;
if ( err == ERR_OK && p != NULL )
{
if (err == ERR_OK && p != NULL) {
tcp_recved(pcb, p->tot_len);
pc = (char*)p->payload;
len = p->tot_len;
len_text = len - 3;
for( i=0; i<len; i++ )
{
for (i = 0; i < len; i++) {
tcp_buffer[i] = pc[i];
}
@@ -65,58 +56,51 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
"setImage : veranderd te afbeelding (naam_afbeelding)\r\n"
"exit : sluit de verbinding\r\n", 354, 0);
tcp_output(pcb);
}
else if( strncmp(tcp_buffer, "text ", 5) == 0 ) {
} else if (strncmp(tcp_buffer, "text ", 5) == 0) {
for (i = 0; i < len - 4; i++) {
text[i] = tcp_buffer[i + 5];
}
text[i - 1] = '\0';
lcd_clear_text(void);
lcd_display_text(text, 10, 10, result_txt, result_bg, LCD_FONT16);
lcd_clear_text();
lcd_display_text(text, 10, 10, result_txt, LCD_FONT16);
check = 1;
}
else if( strncmp(tcp_buffer, "color", 5) == 0 ) {
} else if (strncmp(tcp_buffer, "color", 5) == 0) {
for (i = 0; i < 3; i++) {
colorR[i] = tcp_buffer[i + 6];
colorG[i] = tcp_buffer[i + 10];
colorB[i] = tcp_buffer[i + 14];
color_r[i] = tcp_buffer[i + 6];
color_g[i] = tcp_buffer[i + 10];
color_b[i] = tcp_buffer[i + 14];
}
result_txt |= strtoul(colorR, &endptr, 10) << 16;
result_txt |= strtoul(colorG, &endptr, 10) << 8;
result_txt |= strtoul(colorB, &endptr, 10);
result_bg |= strtoul(color_r, &endptr, 10) << 16;
result_bg |= strtoul(color_g, &endptr, 10) << 8;
result_bg |= strtoul(color_b, &endptr, 10);
check = 1;
}
else if( strncmp(tcp_buffer, "textColor", 9) == 0 ) {
} else if (strncmp(tcp_buffer, "textColor", 9) == 0) {
for (i = 0; i < 3; i++) {
textColorR[i] = tcp_buffer[i + 10];
textColorG[i] = tcp_buffer[i + 14];
textColorB[i] = tcp_buffer[i + 18];
text_color_r[i] = tcp_buffer[i + 10];
text_color_g[i] = tcp_buffer[i + 14];
text_color_b[i] = tcp_buffer[i + 18];
}
result_bg |= strtoul(textColorR, &endptr, 10) << 16;
result_bg |= strtoul(textColorG, &endptr, 10) << 8;
result_bg |= strtoul(textColorB, &endptr, 10);
result_txt |= strtoul(text_color_r, &endptr, 10) << 16;
result_txt |= strtoul(text_color_g, &endptr, 10) << 8;
result_txt |= strtoul(text_color_b, &endptr, 10);
check = 1;
}
else if( strncmp(tcp_buffer, "listImages", 10) == 0 ) {
} else if (strncmp(tcp_buffer, "listImages", 10) == 0) {
size_t number_of_files = llfs_file_count();
llfs_file_t file_list[number_of_files];
number_of_files = llfs_file_list(file_list, number_of_files, NULL);
for (int i = 0; i < number_of_files; i++) {
tcp_write(pcb, file_list[i].name, strlen(file_list[i].name), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
tcp_write(pcb, "\r\n", 2, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
}
check = 1;
}
else if( strncmp(tcp_buffer, "setImage", 8) == 0 ) {
} else if (strncmp(tcp_buffer, "setImage", 8) == 0) {
char filename[len - 8];
for (int i = 0; i < len - 9; i++) {
filename[i] = tcp_buffer[i + 9];
@@ -140,26 +124,21 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
}
}
// Check which file extension is used and call right function
if (strncmp(extension, "bmp", 3) == 0 && file_in_fs == 1) {
lcd_clear_images(void);
lcd_clear_images();
lcd_draw_img_from_fs(filename, 10, 10);
}
else if (strncmp(extension, "gif", 3) == 0 && file_in_fs == 1) {
lcd_clear_images(void);
} else if (strncmp(extension, "gif", 3) == 0 && file_in_fs == 1) {
lcd_clear_images();
lcd_draw_gif_from_fs(filename, 10, 10);
}
else if (file_in_fs == 0){
} else if (file_in_fs == 0) {
tcp_write(pcb, "File NOT in filesystem\n\r", 24, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
}
else{
} else {
tcp_write(pcb, "Extension NOT supported\n\r", 25, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
}
check = 1;
}
else if( strncmp(tcp_buffer, "exit", 4) == 0 ) {
} else if (strncmp(tcp_buffer, "exit", 4) == 0) {
echo_close(pcb);
check = 1;
}
@@ -176,14 +155,11 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
//tcp_write( pcb, tcp_buffer, len, 0 );
tcp_sent(pcb, NULL);
}
else
{
} else {
pbuf_free(p);
}
if( err == ERR_OK && p == NULL )
{
if (err == ERR_OK && p == NULL) {
echo_close(pcb);
}
if (strncmp(tcp_buffer, "\r\n", 2) != 0) {
@@ -193,8 +169,7 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
return ERR_OK;
}
static err_t echo_accept(void *arg, struct tcp_pcb *pcb, err_t err )
{
static err_t echo_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
tcp_setprio(pcb, TCP_PRIO_MIN);
@@ -209,8 +184,7 @@ static err_t echo_accept(void *arg, struct tcp_pcb *pcb, err_t err )
return ERR_OK;
}
void echo_init( void )
{
void echo_init(void) {
struct tcp_pcb *tcp_pcb;
tcp_pcb = tcp_new();
tcp_bind(tcp_pcb, IP_ADDR_ANY, 23);