Sat, 20 Oct 2018 13:23:15 +0200
Initial checkin brewboard
0 | 1 | /** |
2 | * @file files.c | |
3 | * @brief Files management. | |
4 | */ | |
5 | ||
6 | #include "config.h" | |
7 | ||
8 | ||
9 | extern sButton Buttons[MAXBUTTONS]; | |
10 | extern int Main_Screen; | |
11 | ||
12 | bool Refresh = false; | |
13 | ||
14 | ||
15 | ||
16 | void Files_Dir(char *path) | |
17 | { | |
18 | char filename[256], tmp[42]; | |
19 | uint16_t y = 28; | |
20 | DIR *dir; | |
21 | struct dirent *de; | |
22 | struct stat st; | |
23 | ||
24 | _bg = TFT_BLACK; | |
25 | TFT_fillScreen(_bg); | |
26 | TopMessage(path); | |
27 | _fg = TFT_WHITE; | |
28 | TFT_setFont(DEFAULT_FONT, NULL); | |
29 | ||
30 | if ((dir = opendir(path))) { | |
31 | de = readdir(dir); | |
32 | while (de) { | |
33 | TFT_print(de->d_name, 2, y); | |
34 | sprintf(filename, "%s/%s", path, de->d_name); | |
35 | if (stat(filename, &st) == 0) { | |
36 | sprintf(tmp, "%ld", st.st_size); | |
37 | TFT_print(tmp, RIGHT, y); | |
38 | } | |
39 | de = readdir(dir); | |
40 | y += 16; | |
41 | } | |
42 | closedir(dir); | |
43 | } | |
44 | ||
45 | Buttons_Add(130, 200, 60, 40, "Ok", 0); | |
46 | Buttons[0].dark = true; | |
47 | Buttons_Show(); | |
48 | ||
49 | while (true) { | |
50 | if (Buttons_Scan() == 0) { | |
51 | Buttons_Clear(); | |
52 | return; | |
53 | } | |
54 | vTaskDelay(50 / portTICK_PERIOD_MS); | |
55 | } | |
56 | } | |
57 | ||
58 | ||
59 | ||
60 | /* | |
61 | * Files init function, only runs once a new screen is entered. | |
62 | */ | |
63 | void Files_Init(void) | |
64 | { | |
65 | switch (Main_Screen) { | |
66 | case MAIN_TOOLS_FILES: | |
67 | break; | |
68 | ||
69 | default: break; | |
70 | } | |
71 | } | |
72 | ||
73 | ||
74 | ||
75 | /* | |
76 | * Recipes management loop, non-blocking. | |
77 | */ | |
78 | void Files_Loop(void) | |
79 | { | |
80 | switch (Main_Screen) { | |
81 | ||
82 | case MAIN_TOOLS_FILES: | |
83 | Files_Dir("/sdcard/recipe"); | |
84 | Files_Dir("/sdcard/w/log"); | |
85 | Main_Screen = MAIN_TOOLS; | |
86 | break; | |
87 | ||
88 | default: break; | |
89 | } | |
90 | } | |
91 | ||
92 |