Merge 82e6f846bc427c130a3ca9ecf0b4d27214699d4e into c39f253a7dabbc193a8d7d310fb8777dca0ab8f1
This commit is contained in:
commit
6a3473a4a4
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <SdFat.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class SDCardManager {
|
||||
public:
|
||||
@ -40,6 +41,13 @@ class SDCardManager {
|
||||
bool openFileForWrite(const char* moduleName, const String& path, FsFile& file);
|
||||
bool removeDir(const char* path);
|
||||
|
||||
/**
|
||||
* Format the SD card as FAT32/exFAT (auto-selected based on size)
|
||||
* @param pr Optional Print destination for progress output (e.g., &Serial)
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
bool format(Print* pr = nullptr);
|
||||
|
||||
static SDCardManager& getInstance() { return instance; }
|
||||
|
||||
private:
|
||||
|
||||
@ -275,3 +275,30 @@ bool SDCardManager::removeDir(const char* path) {
|
||||
|
||||
return sd.rmdir(path);
|
||||
}
|
||||
|
||||
bool SDCardManager::format(Print* pr) {
|
||||
if (!initialized) {
|
||||
if (pr) pr->println("[SD] SDCardManager: not initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] [SD] Starting format...\n", millis());
|
||||
if (pr) pr->println("[SD] Formatting card, please wait...");
|
||||
|
||||
// SdFat's format() method handles FAT16/FAT32/exFAT selection automatically
|
||||
// based on card size (<=32GB = FAT, >32GB = exFAT)
|
||||
bool success = sd.format(pr);
|
||||
|
||||
if (success) {
|
||||
Serial.printf("[%lu] [SD] Format succeeded, re-initializing...\n", millis());
|
||||
if (pr) pr->println("[SD] Format complete, remounting...");
|
||||
// Re-initialize after format to mount the new filesystem
|
||||
initialized = false;
|
||||
success = begin();
|
||||
} else {
|
||||
Serial.printf("[%lu] [SD] Format failed\n", millis());
|
||||
if (pr) pr->println("[SD] Format failed!");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user