Skip to content

Commit

Permalink
Fix deleteFolder, Add format SD
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmitasch committed Jul 5, 2024
1 parent 4b71707 commit 82c4559
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Firmware/Bentuino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = olimex
default_envs = creatorclub

[bentuino]
platform = espressif32@~5.0.0
Expand Down Expand Up @@ -183,13 +183,13 @@ build_flags =
-D POWER_WAKEUP_BUTTON_STATE=true
-D USE_LEDSTRIP
-D USE_STREAMING
-D LEDSTRIP_MAX_COUNT=1
-D LEDSTRIP_MAX_COUNT=5
-D LED_DEFAULT_EN_PIN=-1
-D LED_DEFAULT_DATA_PIN=4
-D LED_DEFAULT_CLK_PIN=-1
-D LED_DEFAULT_CLK_PIN=33
-D LED_DEFAULT_COUNT=32
-D LED_DEFAULT_TYPE=WS2812B
-D LED_DEFAULT_COLOR_ORDER=GRB
-D LED_DEFAULT_TYPE=SK9822
-D LED_DEFAULT_COLOR_ORDER=BGR
-D LED_DEFAULT_INVERT_DIRECTION=false
-D LED_DEFAULT_BRIGHTNESS=0.5f
-D LED_MAX_BRIGHTNESS=0.4f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool FilesComponent::deleteFolder(String path)
File entry;
while (entry = dir.openNextFile())
{
String fPath = entry.name();
String fPath = entry.path();

if (entry.isDirectory())
{
Expand Down Expand Up @@ -214,13 +214,13 @@ String FilesComponent::listDir(const char *dirname, uint8_t levels)
NDBG(" DIR : " + String(file.name()));
if (levels)
{
result += listDir(file.name(), levels - 1);
result += listDir(file.path(), levels - 1);
}
}
else
{
NDBG(" FILE: " + String(file.name()));
result += String(file.name()) + ",";
result += String(file.path()) + ",";
NDBG(" SIZE: " + String(file.size()));
}
file = root.openNextFile();
Expand All @@ -229,6 +229,46 @@ String FilesComponent::listDir(const char *dirname, uint8_t levels)
return result;
}

esp_err_t FilesComponent::format_sdcard() {
#ifdef FILES_TYPE_SD

char drv[3] = {'0', ':', 0};
const size_t workbuf_size = 4096;
void* workbuf = NULL;
esp_err_t err = ESP_OK;
ESP_LOGW("sdcard", "Formatting the SD card");

size_t allocation_unit_size = 16 * 1024;
int sector_size_default = 512;

workbuf = ff_memalloc(workbuf_size);
if (workbuf == NULL) {
return ESP_ERR_NO_MEM;
}

size_t alloc_unit_size = esp_vfs_fat_get_allocation_unit_size(
sector_size_default,
allocation_unit_size);

#if (ESP_IDF_VERSION_MAJOR < 5)
FRESULT res = f_mkfs(drv, FM_ANY, alloc_unit_size, workbuf, workbuf_size);
#else
const MKFS_PARM opt = {(BYTE)FM_ANY, 0, 0, 0, alloc_unit_size};
FRESULT res = f_mkfs(drv, &opt, workbuf, workbuf_size);
#endif /* ESP_IDF_VERSION_MAJOR */
if (res != FR_OK) {
err = ESP_FAIL;
ESP_LOGE("sdcard", "f_mkfs failed (%d)", res);
}

free(workbuf);

ESP_LOGI("sdcard", "Successfully formatted the SD card");

return err;
#endif
}

bool FilesComponent::handleCommandInternal(const String &command, var *data, int numData)
{

Expand All @@ -252,6 +292,11 @@ bool FilesComponent::handleCommandInternal(const String &command, var *data, int
sendEvent(FileList, &filesData, 1);
return true;
}
else if (checkCommand(command, "format", numData, 0))
{
NDBG("Formatting SD card.");
format_sdcard();
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void deleteFileIfExists(String path);
String listDir(const char *dirname, uint8_t levels);

bool handleCommandInternal(const String &command, var *data, int numData) override;
esp_err_t format_sdcard();

DeclareComponentEventTypes(UploadStart, UploadProgress, UploadComplete, UploadCancel, FileList);
DeclareComponentEventNames("uploadStart", "uploadProgress", "uploadComplete", "uploadCancel", "list");
Expand Down
2 changes: 2 additions & 0 deletions Firmware/Bentuino/src/UnityIncludes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "SD_MMC.h"
#else
#include "SD.h"
#include "ff.h"
#include "vfs_fat_internal.h"
#endif

#include "FS.h"
Expand Down

0 comments on commit 82c4559

Please sign in to comment.