summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/ble/FSService.cpp17
-rw-r--r--src/components/fs/FS.cpp4
-rw-r--r--src/components/fs/FS.h1
3 files changed, 16 insertions, 6 deletions
diff --git a/src/components/ble/FSService.cpp b/src/components/ble/FSService.cpp
index 2cfd5ccd..2f02cd96 100644
--- a/src/components/ble/FSService.cpp
+++ b/src/components/ble/FSService.cpp
@@ -70,21 +70,26 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
char path[plen+1] = {0};
memcpy(path, header->pathstr, plen);
NRF_LOG_INFO("[FS_S] -> DIR %.10s", path);
- lfs_dir_t dir;
- struct lfs_info info;
+ lfs_dir_t dir = {};
+ struct lfs_info info = {};
- ListDirResponse resp;
+ ListDirResponse resp = {};
resp.command = 0x51; // LISTDIR_ENTRY;
resp.status = 1; // TODO actually use res above!
resp.totalentries = 0;
resp.entry = 0;
+ int sr;
int res = fs.DirOpen(path, &dir);
+
+ NRF_LOG_INFO("[FS_S] ->diropen %d ", res);
while (fs.DirRead(&dir, &info)) {
resp.totalentries++;
+
}
NRF_LOG_INFO("[FS_S] -> %d ", resp.totalentries);
- fs.DirClose(&dir);
- fs.DirOpen(path, &dir);
+
+ fs.DirRewind(&dir);
+
while (fs.DirRead(&dir, &info)) {
switch(info.type){
case LFS_TYPE_REG:
@@ -106,8 +111,10 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
NRF_LOG_INFO("[FS_S] ->Path %s ,", info.name);
auto* om = ble_hs_mbuf_from_flat(&resp,sizeof(ListDirResponse));
ble_gattc_notify_custom(connectionHandle,transferCharacteristicHandle,om);
+ vTaskDelay(1); //Allow stuff to actually go out over the BLE conn
resp.entry++;
}
+ fs.DirClose(&dir);
resp.entry++;
resp.file_size = 0;
resp.path_length = 0;
diff --git a/src/components/fs/FS.cpp b/src/components/fs/FS.cpp
index f287c28e..353193dc 100644
--- a/src/components/fs/FS.cpp
+++ b/src/components/fs/FS.cpp
@@ -89,7 +89,9 @@ int FS::DirClose(lfs_dir_t* lfs_dir) {
int FS::DirRead(lfs_dir_t* dir, lfs_info* info) {
return lfs_dir_read(&lfs, dir, info);
}
-
+int FS::DirRewind(lfs_dir_t* dir) {
+ return lfs_dir_rewind(&lfs, dir);
+}
int FS::DirCreate(const char* path) {
return lfs_mkdir(&lfs, path);
}
diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h
index 28d28d3c..ccff2409 100644
--- a/src/components/fs/FS.h
+++ b/src/components/fs/FS.h
@@ -24,6 +24,7 @@ namespace Pinetime {
int DirOpen(const char* path, lfs_dir_t* lfs_dir);
int DirClose(lfs_dir_t* lfs_dir);
int DirRead(lfs_dir_t* dir, lfs_info* info);
+ int DirRewind(lfs_dir_t* dir);
int DirCreate(const char* path);
int DirDelete(const char* path);