MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / readFs

Function readFs

src/sd_functions.cpp:248–291  ·  view source on GitHub ↗

** Function name: readFs ** Description: read files/folders from a folder ***************************************************************************************/

Source from the content-addressed store, hash-verified

246** Description: read files/folders from a folder
247***************************************************************************************/
248void readFs(String &folder, std::vector<Option> &opt) {
249 // function using loopOptions
250 opt.clear();
251 if (!setupSdCard()) {
252 // Serial.println("Falha ao iniciar o cartão SD");
253 displayRedStripe("SD not found or not formatted in FAT32");
254 vTaskDelay(2500 / portTICK_PERIOD_MS);
255 return; // Retornar imediatamente em caso de falha
256 }
257 File root = SDM.open(folder);
258 if (!root || !root.isDirectory()) {
259 displayRedStripe("Fail open root");
260 vTaskDelay(2500 / portTICK_PERIOD_MS);
261 SDM.end();
262 sdcardMounted = false;
263 return; // Retornar imediatamente se não for possível abrir o diretório
264 }
265
266 while (true) {
267 bool isDir;
268 String fullPath = root.getNextFileName(&isDir);
269 String nameOnly = fullPath.substring(fullPath.lastIndexOf("/") + 1);
270 if (fullPath == "") { break; }
271 // Serial.printf("Path: %s (isDir: %d)\n", fullPath.c_str(), isDir);
272
273 uint16_t color = FGCOLOR - 0x1111;
274
275 if (noDotFiles && nameOnly.startsWith(".")) { continue; }
276
277 if (!isDir) {
278 int dotIndex = nameOnly.lastIndexOf(".");
279 String ext = dotIndex >= 0 ? nameOnly.substring(dotIndex + 1) : "";
280 ext.toUpperCase();
281 if (onlyBins && !ext.equals("BIN")) { continue; }
282 color = FGCOLOR;
283 } else {
284 nameOnly = "/" + nameOnly; // add / before folder name
285 }
286 opt.push_back({nameOnly, [fullPath]() { fileToUse = fullPath; }, color});
287 }
288 root.close();
289 std::sort(opt.begin(), opt.end(), sortList);
290 opt.push_back({"> Back", [&]() { fileToUse = ""; }, ALCOLOR});
291}
292/*********************************************************************
293** Function: loopSD
294** Where you choose what to do wuth your SD Files

Callers 1

loopSDFunction · 0.85

Calls 5

displayRedStripeFunction · 0.85
closeMethod · 0.80
clearMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected