Update to setImage command

Added checks to see if file exist in filesystem and if extension is supported (bmp of gif)
This commit is contained in:
Roelandts_Gert
2023-11-20 15:40:57 +01:00
committed by Sander Speetjens
parent 26f2655e3f
commit 398bb2efde

View File

@@ -29,6 +29,8 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
{
int i;
int len;
int file_in_fs;
u16_t len_text;
char *pc;
int check = 0;
@@ -44,6 +46,7 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
char textColorG[3];
char textColorB[3];
char extension[4];
char *endptr;
@@ -124,8 +127,40 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er
for (int i = 0; i < len - 9; i++) {
filename[i] = tcp_buffer[i+9];
}
for (int i = 0; i < 3; i++) {
extension[i] = tcp_buffer[i + len - 3];
}
filename[sizeof(filename)-1] = '\0';
lcd_draw_img_from_fs(filename, 10, 10);
extension[3] = '\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);
file_in_fs = 0;
for (int i = 0; i < number_of_files; i ++) {
if (strcmp(filename, file_list[i].name) == 0) {
file_in_fs = 1;
}
}
// Check which file extension is used and call right function
if (strncmp(extension, "bmp", 3) == 0 && file_in_fs == 1) {
lcd_draw_img_from_fs(filename, 10, 10);
}
else if (strncmp(extension, "gif", 3) == 0 && file_in_fs == 1) {
lcd_draw_gif_from_fs(filename, 10, 10);
}
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{
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 ) {