57 } |
58 } |
58 } |
59 } |
59 |
60 |
60 |
61 |
61 |
62 |
|
63 /** |
|
64 * @brief File copier. |
|
65 * @param fdir From directory |
|
66 * @param tdir To directory |
|
67 * @param fn Filename |
|
68 */ |
|
69 void FCopy(char *fdir, char *tdir, char *filename) |
|
70 { |
|
71 char fn[33], tn[33], msg[33]; |
|
72 int rc; |
|
73 |
|
74 snprintf(msg, 32, "Copy %s\r\n", filename); |
|
75 TFT_print(msg, 0, LASTY); |
|
76 snprintf(fn, 32, "%s%s", fdir, filename); |
|
77 snprintf(tn, 32, "%s%s", tdir, filename); |
|
78 rc = FileCopy(fn, tn); |
|
79 ESP_LOGI(TAG, "Copy %s to %s rc=%d", fn, tn, rc); |
|
80 } |
|
81 |
|
82 |
|
83 |
62 /* |
84 /* |
63 * Files init function, only runs once a new screen is entered. |
85 * Files init function, only runs once a new screen is entered. |
64 */ |
86 */ |
65 void Files_Init(void) |
87 void Files_Init(void) |
66 { |
88 { |
|
89 bool _loop; |
|
90 DIR *dir; |
|
91 |
67 switch (Main_Screen) { |
92 switch (Main_Screen) { |
68 case MAIN_TOOLS_FILES: |
93 case MAIN_TOOLS_FILES: |
|
94 TopMessage("Bestanden menu"); |
|
95 Buttons_Add( 20, 40,120, 40, "Restore", 0); |
|
96 Buttons_Add(180, 40,120, 40, "Backup", 1); |
|
97 Buttons_Add( 20,120,120, 40, "Directory", 2); |
|
98 Buttons_Add(130, 200, 60, 40, "Ok", 3); |
|
99 Buttons[4].dark = true; |
|
100 Buttons_Show(); |
|
101 break; |
|
102 |
|
103 case MAIN_TOOLS_FILES_DIR: |
|
104 break; |
|
105 |
|
106 case MAIN_TOOLS_FILES_RESTORE: |
|
107 case MAIN_TOOLS_FILES_BACKUP: |
|
108 if (Main_Screen == MAIN_TOOLS_FILES_RESTORE) |
|
109 TopMessage("Restore database"); |
|
110 else |
|
111 TopMessage("Backup database"); |
|
112 Buttons_Add( 40, 100, 80, 40, "Start", 0); |
|
113 Buttons_Add(200, 100, 80, 40, "Stop", 1); |
|
114 Buttons[1].dark = true; |
|
115 Buttons_Show(); |
|
116 SoundPlay(SOUND_Prompt); |
|
117 _loop = true; |
|
118 while (_loop) { |
|
119 switch (Buttons_Scan()) { |
|
120 case 0: |
|
121 _loop = false; |
|
122 break; |
|
123 case 1: |
|
124 _loop = false; |
|
125 Main_Screen = MAIN_TOOLS_FILES; |
|
126 break; |
|
127 default: |
|
128 break; |
|
129 } |
|
130 vTaskDelay(50 / portTICK_PERIOD_MS); |
|
131 } |
|
132 Buttons_Clear(); |
|
133 if (Main_Screen == MAIN_TOOLS_FILES) |
|
134 break; |
|
135 |
|
136 _fg = TFT_YELLOW; |
|
137 TFT_setFont(DEJAVU24_FONT, NULL); |
|
138 if (Main_Screen == MAIN_TOOLS_FILES_RESTORE) { |
|
139 ESP_LOGI(TAG, "Restore database"); |
|
140 TFT_setFont(DEJAVU18_FONT, NULL); |
|
141 TFT_print("Backup:\r\n", 0, 30); |
|
142 _fg = TFT_CYAN; |
|
143 FCopy("/sdcard/etc/", "/spiffs/etc/", "config.conf"); |
|
144 FCopy("/sdcard/etc/", "/spiffs/etc/", "recipe.conf"); |
|
145 FCopy("/sdcard/etc/", "/spiffs/etc/", "equipments.conf"); |
|
146 FCopy("/sdcard/etc/", "/spiffs/etc/", "stations.conf"); |
|
147 FCopy("/sdcard/etc/", "/spiffs/etc/", "runtime.conf"); |
|
148 _fg = TFT_YELLOW; |
|
149 TFT_setFont(DEJAVU24_FONT, NULL); |
|
150 TFT_print("Restore gereed, reset!", CENTER, LASTY + 12); |
|
151 vTaskDelay(2000 / portTICK_PERIOD_MS); |
|
152 esp_restart(); |
|
153 } else { |
|
154 dir = opendir("/sdcard/etc"); |
|
155 if (dir == NULL) { |
|
156 mkdir("/sdcard/etc", 0755); |
|
157 dir = opendir("/sdcard/etc"); |
|
158 } |
|
159 if (dir == NULL) { |
|
160 TFT_print("SD kaart fout", CENTER, CENTER); |
|
161 } else { |
|
162 closedir(dir); |
|
163 ESP_LOGI(TAG, "Backup database"); |
|
164 TFT_setFont(DEJAVU18_FONT, NULL); |
|
165 TFT_print("Backup:\r\n", 0, 30); |
|
166 _fg = TFT_CYAN; |
|
167 FCopy("/spiffs/etc/", "/sdcard/etc/", "config.conf"); |
|
168 FCopy("/spiffs/etc/", "/sdcard/etc/", "recipe.conf"); |
|
169 FCopy("/spiffs/etc/", "/sdcard/etc/", "equipments.conf"); |
|
170 FCopy("/spiffs/etc/", "/sdcard/etc/", "stations.conf"); |
|
171 FCopy("/spiffs/etc/", "/sdcard/etc/", "runtime.conf"); |
|
172 _fg = TFT_YELLOW; |
|
173 TFT_setFont(DEJAVU24_FONT, NULL); |
|
174 TFT_print("Backup gereed.", CENTER, LASTY + 12); |
|
175 } |
|
176 } |
|
177 |
|
178 Buttons_Add(130, 200, 60, 40, "Ok", 0); |
|
179 Buttons[0].dark = true; |
|
180 Buttons_Show(); |
69 break; |
181 break; |
70 |
182 |
71 default: break; |
183 default: break; |
72 } |
184 } |
73 } |
185 } |