Skip to content

Commit 3a2b088

Browse files
committed
Testing Storage: OK
1 parent b39d476 commit 3a2b088

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

lib/storage/storage.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ static const char *const TAG = "STORAGE";
3030
/**
3131
* Lists files and directories at path.
3232
*/
33-
static void listFiles(const char *const dirname)
33+
static void listFiles(const char *const dirname, const std::shared_ptr<fs::FS> fs)
3434
{
3535
std::cout << "Directory: '" << dirname << "'" << std::endl;
36-
File root = FFat.open(dirname);
36+
File root = fs->open(dirname);
3737
if (!root || !root.isDirectory())
3838
{
3939
ESP_LOGE(TAG, "Error: '%s' is not a directory!\n", dirname);
@@ -75,6 +75,7 @@ class FileSystemSwitcher
7575
void requestState(const bool fileSystemActive)
7676
{
7777
requestFileSystemActive = fileSystemActive;
78+
ESP_LOGD(TAG, "request new state: %s", fileSystemActive ? "true" : "false");
7879
stateChangeRequested.notify_all();
7980
}
8081

@@ -88,6 +89,7 @@ class FileSystemSwitcher
8889
while (true)
8990
{
9091
std::unique_lock fs_state_lock{fileSystemState_mutex};
92+
ESP_LOGD(TAG, "waiting for state change request");
9193
stateChangeRequested.wait(fs_state_lock,
9294
[this]() { return requestFileSystemActive != fileSystemIsActive; });
9395
if (fileSystemIsActive = requestFileSystemActive)
@@ -96,14 +98,14 @@ class FileSystemSwitcher
9698
usbMsc.mediaPresent(false);
9799
FFat.end(); // invalidate cache
98100
assert(FFat.begin()); // update data
99-
listFiles("/");
100101
}
101102
else
102103
{
103104
ESP_LOGD(TAG, "unmount FS");
104105
FFat.end(); // flush and unmount
105106
usbMsc.mediaPresent(true);
106107
}
108+
stateChanged.notify_all();
107109
}
108110
}
109111

@@ -228,3 +230,9 @@ void Storage::end()
228230
usbIsRunning = false;
229231
FFat.end();
230232
}
233+
234+
void Storage::test()
235+
{
236+
auto fs_p = fileSystemSwitcher.getFileSystem_locking();
237+
listFiles("/", fs_p);
238+
}

lib/storage/storage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ struct Storage
55
{
66
static void begin();
77
static void end();
8+
static void test();
89
static std::size_t size();
910
};

src/main.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include <Arduino.h>
2+
#include <chrono>
23
#include <esp32-hal-log.h>
34
#include <esp_err.h>
45
#include <iostream>
56
#include <storage.hpp>
7+
#include <thread>
8+
9+
using namespace std::chrono_literals;
610

711
#if ARDUINO_USB_CDC_ON_BOOT == 1
812
#define HWSerial Serial0
@@ -16,7 +20,7 @@ void setup()
1620
{
1721
HWSerial.begin(115200);
1822
HWSerial.setDebugOutput(true);
19-
delay(300); // in order to give the serial monitor time to start
23+
delay(3000); // in order to give the serial monitor time to start
2024
std::cout << "Started program" << std::endl;
2125
ESP_LOGE(TAG, "Example error");
2226
ESP_LOGW(TAG, "Example warning");
@@ -28,11 +32,6 @@ void setup()
2832

2933
void loop()
3034
{
31-
// put your main code here, to run repeatedly:
32-
static uint32_t lastTrigger = 0;
33-
if (millis() - lastTrigger > 1000)
34-
{
35-
std::cout << "." << std::flush;
36-
lastTrigger = millis();
37-
}
35+
Storage::test();
36+
std::this_thread::sleep_for(3s);
3837
}

0 commit comments

Comments
 (0)