diff -r 000000000000 -r b74b0e4902c3 main/files.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/files.c Sat Oct 20 13:23:15 2018 +0200 @@ -0,0 +1,92 @@ +/** + * @file files.c + * @brief Files management. + */ + +#include "config.h" + + +extern sButton Buttons[MAXBUTTONS]; +extern int Main_Screen; + +bool Refresh = false; + + + +void Files_Dir(char *path) +{ + char filename[256], tmp[42]; + uint16_t y = 28; + DIR *dir; + struct dirent *de; + struct stat st; + + _bg = TFT_BLACK; + TFT_fillScreen(_bg); + TopMessage(path); + _fg = TFT_WHITE; + TFT_setFont(DEFAULT_FONT, NULL); + + if ((dir = opendir(path))) { + de = readdir(dir); + while (de) { + TFT_print(de->d_name, 2, y); + sprintf(filename, "%s/%s", path, de->d_name); + if (stat(filename, &st) == 0) { + sprintf(tmp, "%ld", st.st_size); + TFT_print(tmp, RIGHT, y); + } + de = readdir(dir); + y += 16; + } + closedir(dir); + } + + Buttons_Add(130, 200, 60, 40, "Ok", 0); + Buttons[0].dark = true; + Buttons_Show(); + + while (true) { + if (Buttons_Scan() == 0) { + Buttons_Clear(); + return; + } + vTaskDelay(50 / portTICK_PERIOD_MS); + } +} + + + +/* + * Files init function, only runs once a new screen is entered. + */ +void Files_Init(void) +{ + switch (Main_Screen) { + case MAIN_TOOLS_FILES: + break; + + default: break; + } +} + + + +/* + * Recipes management loop, non-blocking. + */ +void Files_Loop(void) +{ + switch (Main_Screen) { + + case MAIN_TOOLS_FILES: + Files_Dir("/sdcard/recipe"); + Files_Dir("/sdcard/w/log"); + Main_Screen = MAIN_TOOLS; + break; + + default: break; + } +} + +