Skip to content

Commit 351da67

Browse files
committed
WIP
1 parent ab0a115 commit 351da67

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

lib/storage/storage.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <Arduino.h>
2+
13
#include "storage.hpp"
24
#include <FFat.h>
35
#include <USB.h>
@@ -7,15 +9,6 @@
79
#include <esp_partition.h>
810
#include <string>
911

10-
#if ARDUINO_USB_CDC_ON_BOOT == 1
11-
#define HWSerial Serial0
12-
#define USBSerial Serial
13-
#else
14-
#define HWSerial Serial
15-
#include <USBCDC.h>
16-
USBCDC USBSerial;
17-
#endif
18-
1912
#if defined(ARDUINO_USB_MODE)
2013
static_assert(ARDUINO_USB_MODE == 0, "USB must be in OTG mode");
2114
#endif
@@ -110,7 +103,7 @@ std::size_t Storage::size()
110103

111104
bool Storage::begin(const bool formatFsOnFail, const char *const partitionLabel)
112105
{
113-
ESP_LOGI(TAG, "Starting storage...");
106+
ESP_LOGD(TAG, "Starting storage...");
114107
partition = check_ffat_partition(partitionLabel);
115108

116109
if (!partition)
@@ -129,6 +122,7 @@ bool Storage::begin(const bool formatFsOnFail, const char *const partitionLabel)
129122
}
130123
ESP_LOGI(TAG, "Storage has a size of %u bytes.", size());
131124
ESP_LOGI(TAG, "Storage mounted at '%s'.", basePath.c_str());
125+
fileSystemIsReady = true;
132126

133127
// setup USB Mass Storage Class
134128
usbMsc.vendorID("TTS"); // max 8 chars
@@ -138,14 +132,11 @@ bool Storage::begin(const bool formatFsOnFail, const char *const partitionLabel)
138132
// Set callback
139133
usbMsc.onRead(usbMsc_onRead);
140134
usbMsc.onWrite(usbMsc_onWrite);
141-
// usbMsc is ready for read/write
142-
usbMsc.mediaPresent(true);
143-
if (!usbMsc.begin(FFat.totalBytes() / blockSize, blockSize))
135+
if (!usbMsc.begin(size() / blockSize, blockSize))
144136
{
145137
ESP_LOGE(TAG, "USB MSC initialization failed!");
146138
return false;
147139
}
148-
fileSystemIsReady = true;
149140

150141
// subscribe to USB events
151142
USB.onEvent(ARDUINO_USB_STARTED_EVENT, callbackUsbStarted);

src/main.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ struct TestStorage : Storage
2222
*/
2323
static void listFiles(const char *const dirname)
2424
{
25-
// auto FFat = getFileSystem();
25+
auto FFat = getFileSystem();
2626
HWSerial.printf("Directory: '%s'\n", dirname);
2727
File root = FFat.open(dirname);
2828
if (!root || !root.isDirectory())
2929
{
30-
ESP_LOGE(TAG, "'%s' is not a directory!\n", dirname);
30+
ESP_LOGE(TAG, "'%s' is not a directory!", dirname);
3131
root.close();
3232
return;
3333
}
@@ -36,10 +36,12 @@ struct TestStorage : Storage
3636
while (file)
3737
{
3838
HWSerial.printf(" %s (%s, %d Bytes)\n", file.name(), file.isDirectory() ? "d" : "f", file.size());
39+
file.close();
3940
file = root.openNextFile();
4041
}
4142
file.close();
4243
root.close();
44+
HWSerial.println("end of directory");
4345
}
4446
};
4547

0 commit comments

Comments
 (0)