Skip to content

Commit

Permalink
fix delete folder in firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Jun 22, 2024
1 parent ceac7c0 commit 75308e3
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 90 deletions.
136 changes: 85 additions & 51 deletions Firmware/Bentuino/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@
"includePath": [
"D:/Projects/Dev/BenTo/Firmware/Bentuino/include",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/M5GFX/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/lib/SD/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/FastAccelStepper/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/WebSockets/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/FastAccelStepper/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/WebSockets/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ESP Async WebServer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/AsyncTCP/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ArtnetWifi/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ESP32Servo/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/SimplexNoise",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Wasm3/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/arduino-timer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit DotStar",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ESP Async WebServer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/AsyncTCP/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ArtnetWifi/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ESP32Servo/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/SimplexNoise",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Wasm3/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/arduino-timer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit DotStar",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/OSC",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/OSC",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/FS/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ArduinoJson/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ArduinoJson/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BusIO",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BusIO",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BNO055",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BNO055/utility",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BNO055",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BNO055/utility",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit Unified Sensor",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit NeoPixel",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit Unified Sensor",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit NeoPixel",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_trace",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_update",
Expand Down Expand Up @@ -126,32 +127,33 @@
"path": [
"D:/Projects/Dev/BenTo/Firmware/Bentuino/include",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/M5GFX/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/lib/SD/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/FastAccelStepper/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/WebSockets/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/FastAccelStepper/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/WebSockets/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ESP Async WebServer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/AsyncTCP/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ArtnetWifi/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ESP32Servo/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/SimplexNoise",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Wasm3/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/arduino-timer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit DotStar",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ESP Async WebServer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/AsyncTCP/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ArtnetWifi/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ESP32Servo/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/SimplexNoise",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Wasm3/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/arduino-timer/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit DotStar",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/ESPmDNS/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/OSC",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/OSC",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/SPIFFS/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/FS/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/ArduinoJson/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/ArduinoJson/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/WiFi/src",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/Preferences/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BusIO",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BusIO",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BNO055",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit BNO055/utility",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BNO055",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit BNO055/utility",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit Unified Sensor",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/motor/Adafruit NeoPixel",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit Unified Sensor",
"D:/Projects/Dev/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/Adafruit NeoPixel",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/config",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_trace",
"C:/Users/bkupe/.platformio/packages/framework-arduinoespressif32/tools/sdk/include/app_update",
Expand Down Expand Up @@ -240,7 +242,7 @@
},
"defines": [
"PLATFORMIO=60115",
"ARDUINO_FEATHER_ESP32",
"ARDUINO_ESP32_DEV",
"ARDUINO_BENTUINO",
"USE_SERIAL",
"USE_SERVER",
Expand All @@ -250,22 +252,54 @@
"CONFIG_ASYNC_TCP_USE_WDT=0",
"USE_WIFI",
"USE_OSC",
"BENTUINO_M5SERVO",
"USE_SERIAL",
"USE_SERVER",
"WS_MAX_QUEUED_MESSAGES=64",
"USE_ASYNC_WEBSOCKET=0",
"CONFIG_ASYNC_TCP_RUNNING_CORE=1",
"CONFIG_ASYNC_TCP_USE_WDT=0",
"USE_WIFI",
"USE_OSC",
"BENTUINO_CREATORCLUB",
"USE_POWER",
"POWER_KEEP_PIN=12",
"POWER_WAKEUP_BUTTON=32",
"POWER_WAKEUP_BUTTON_STATE=true",
"USE_LEDSTRIP",
"USE_STREAMING",
"LEDSTRIP_MAX_COUNT=1",
"LED_DEFAULT_EN_PIN=27",
"LED_DEFAULT_DATA_PIN=25",
"LED_DEFAULT_CLK_PIN=26",
"LED_DEFAULT_COUNT=32",
"LED_DEFAULT_TYPE=SK9822",
"LED_DEFAULT_COLOR_ORDER=BGR",
"LED_DEFAULT_INVERT_DIRECTION=true",
"LED_DEFAULT_BRIGHTNESS=0.5f",
"LED_MAX_BRIGHTNESS=0.4f",
"LED_MAX_COUNT=32",
"PLAYBACK_USE_ALPHA",
"PLAYBACK_MAX_SCRIPTS=32",
"USE_FX",
"USE_BUTTON",
"BUTTON_MAX_COUNT=1",
"BUTTON_DEFAULT_PIN=32",
"USE_IO",
"BUTTON_MAX_COUNT=2",
"BUTTON_DEFAULT_PIN=37",
"USE_DC_MOTOR",
"DC_MOTOR_DEFAULT_EN_PIN=26",
"DC_MOTOR_DEFAULT_DIR1_PIN=36",
"DC_MOTOR_DEFAULT_DIR2_PIN=0",
"IO_MAX_COUNT=1",
"IO_DEFAULT_PIN=17",
"IO_DEFAULT_MODE=IOComponent::PinMode::A_OUTPUT",
"USE_BATTERY",
"BATTERY_DEFAULT_PIN=35",
"BATTERY_DEFAULT_CHARGE_PIN=-1",
"BATTERY_DEFAUT_RAW_MIN=222",
"BATTERY_DEFAULT_RAW_MAX=335",
"BATTERY_DEFAULT_LOW_VOLTAGE=3.5f",
"USE_FILES",
"USE_SCRIPT",
"FILES_DEFAULT_SDSPEED=27000000",
"FILES_DEFAULT_SD_EN=16",
"FILES_DEFAULT_SD_POWER_VALUE=LOW",
"FILES_DEFAULT_SD_MISO=19",
"FILES_DEFAULT_SD_MOSI=13",
"FILES_DEFAULT_SD_SCK=14",
"FILES_DEFAULT_SD_CS=15",
"USE_MOTION",
"IMU_DEFAULT_INT=33",
"IMU_DEFAULT_SDA=23",
"IMU_DEFAULT_SCL=22",
"IMU_DEFAULT_ADDR=0x28",
"ESP32",
"ESP_PLATFORM",
"F_CPU=240000000L",
Expand All @@ -274,7 +308,7 @@
"ARDUINO=10805",
"ARDUINO_ARCH_ESP32",
"ARDUINO_VARIANT=\"esp32\"",
"ARDUINO_BOARD=\"Adafruit ESP32 Feather\"",
"ARDUINO_BOARD=\"Espressif ESP32 Dev Module\"",
""
],
"cStandard": "gnu99",
Expand Down
3 changes: 2 additions & 1 deletion Firmware/Bentuino/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"cinttypes": "cpp",
"regex": "cpp",
"ratio": "cpp",
"thread": "cpp"
"thread": "cpp",
"list": "cpp"
},
"cmake.sourceDirectory": "D:/Documents/Perso/Projects/BenTo/Firmware/Bentuino/.pio/libdeps/creatorclub/FastAccelStepper"
}
4 changes: 3 additions & 1 deletion Firmware/Bentuino/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = motor
default_envs = creatorclub


[bentuino]
platform = [email protected]
platform_packages = [email protected]
Expand Down
75 changes: 48 additions & 27 deletions Firmware/Bentuino/src/Component/components/files/FilesComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,61 @@ File FilesComponent::openFile(String fileName, bool forWriting, bool deleteIfExi
return f;
}

bool FilesComponent::deleteFolder(String path)
{
if (!isInit)
return false;

bool result = false;

File dir = SD.open(path);

File entry;
while (entry = dir.openNextFile())
{
String fPath = entry.name();

if (entry.isDirectory())
{
NDBG("Deleting folder " + fPath);

result = deleteFolder(fPath);
if (!result)
{
NDBG("Failed to delete folder " + fPath);
return false;
}

if (useInternalMemory)
result = SPIFFS.rmdir(fPath);
else
result = SD.rmdir(fPath);
}
else
{
NDBG("Deleting file " + fPath);

if (useInternalMemory)
result = SPIFFS.remove(fPath);
else
result = SD.remove(fPath);
}
}

return result;
}

void FilesComponent::deleteFileIfExists(String path)
{

if (!isInit)
return;

NDBG("Deleting file " + path);

if (useInternalMemory)
{

if (SPIFFS.exists(path))
SPIFFS.remove(path);
}
Expand Down Expand Up @@ -170,33 +217,7 @@ bool FilesComponent::handleCommandInternal(const String &command, var *data, int
}
else if (checkCommand(command, "deleteFolder", numData, 0))
{
if (numData > 0)
{
NDBG("Deleting folder " + data[0].stringValue());
if (useInternalMemory)
{
SPIFFS.rmdir(data[0].stringValue());
}
else
{
SD.rmdir(data[0].stringValue());
}
}
else
{
NDBG("Deleting all files");
if (useInternalMemory)
{
SPIFFS.rmdir("/");
}
else
{
bool success = SD.rmdir("/");
if (!success)
NDBG("Error deleting all files");
}
}

deleteFolder(numData > 0 ? data[0].stringValue() : "/");
return true;
}
else if (checkCommand(command, "list", numData, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DeclareIntParam(sdCS, FILES_DEFAULT_SD_CS);
DeclareIntParam(sdSpeed, FILES_DEFAULT_SDSPEED);

File openFile(String fileName, bool forWriting = false, bool deleteIfExists = true);
bool deleteFolder(String path);
void deleteFileIfExists(String path);
String listDir(const char *dirname, uint8_t levels);

Expand Down
2 changes: 1 addition & 1 deletion Source/Prop/Prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Prop :
virtual void uploadFileQueue();
virtual void uploadFile(FileToUpload f);

virtual void deleteAllFiles() {}
virtual void deleteFolder(const String& path = "/") {}

virtual void updatePlaybackModeOnProp();
virtual void setPlaybackEnabled(bool value) {}
Expand Down
10 changes: 6 additions & 4 deletions Source/Prop/PropManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ PropManager::PropManager() :
loadAll = playbackCC.addTrigger("Load All", "Load playback on all devices that can play");
playAll = playbackCC.addTrigger("Play All", "Play playback on all devices that can play");
stopAll = playbackCC.addTrigger("Stop All", "Stop playback on all devices that can stop");
deleteAllFiles = playbackCC.addTrigger("Delete All Files", "Delete all files on all devices");
deleteAllPlayback = playbackCC.addTrigger("Delete All Playback Files", "Delete all playback files on all devices");
deleteAllScripts = playbackCC.addTrigger("Delete All Embedded Scripts", "Delete all Wasm scripts on all devices");

loop = playbackCC.addBoolParameter("Loop Playback", "If checked, this will tell the player to loop the playing", false);
addChildControllableContainer(&playbackCC);

Expand Down Expand Up @@ -117,7 +119,7 @@ void PropManager::setupReceiver()
String s = "Local IPs:";
for (auto& ip : ips) s += String("\n > ") + ip;


NLOG(niceName, s);
}

Expand Down Expand Up @@ -283,7 +285,7 @@ void PropManager::onControllableFeedbackUpdate(ControllableContainer* cc, Contro
{
for (auto& pr : items) pr->playbackMode->setValue(playbackMode->boolValue());
}
else if (c == deleteAllFiles)
else if (c == deleteAllPlayback || c == deleteAllScripts)
{
AlertWindow::showAsync(
MessageBoxOptions().withIconType(AlertWindow::WarningIcon)
Expand All @@ -299,7 +301,7 @@ void PropManager::onControllableFeedbackUpdate(ControllableContainer* cc, Contro
{
if (BentoProp* bp = dynamic_cast<BentoProp*>(p))
{
bp->deleteAllFiles();
bp->deleteFolder(c == deleteAllPlayback ? "/playback" : "/scripts");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Prop/PropManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class PropManager :
Trigger* loadAll;
Trigger* playAll;
Trigger* stopAll;
Trigger* deleteAllFiles;
Trigger* deleteAllPlayback;
Trigger* deleteAllScripts;
BoolParameter* loop;

BoolParameter* autoAddNetworkProps;
Expand Down
Loading

0 comments on commit 75308e3

Please sign in to comment.