Fix lvgl_open to respect littlefs open errors

This commit is contained in:
Tim Keller 2021-10-26 03:42:34 +00:00
parent f4322841ff
commit 8f46908d38
2 changed files with 10 additions and 11 deletions

View file

@ -156,7 +156,7 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.command = commands::WRITE_PACING; resp.command = commands::WRITE_PACING;
resp.offset = header->offset; resp.offset = header->offset;
resp.modTime = 0; resp.modTime = 0;
int res = fs.FileOpen(&f, filepath, LFS_O_RDWR | LFS_O_CREAT); int res = fs.FileOpen(&f, filepath, LFS_O_WRONLY | LFS_O_CREAT);
resp.status = res ? 0x02 : 0x01; resp.status = res ? 0x02 : 0x01;
fs.FileClose(&f); fs.FileClose(&f);
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset); resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
@ -177,7 +177,6 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
fs.FileWrite(&f, header->data, header->dataSize); fs.FileWrite(&f, header->data, header->dataSize);
fs.FileClose(&f); fs.FileClose(&f);
resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset); resp.freespace = std::min(fs.getSize() - (fs.GetFSSize() * fs.getBlockSize()), fileSize - header->offset);
// NRF_LOG_INFO('[FS_S] Used Blocks -> %u',resp.freespace);
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(WriteResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
@ -222,14 +221,13 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
resp.status = 1; resp.status = 1;
resp.totalentries = 0; resp.totalentries = 0;
resp.entry = 0; resp.entry = 0;
resp.modification_time = 0; // TODO Does LFS actually support TS? resp.modification_time = 0;
if (fs.DirOpen(path, &dir) != 0) { if (fs.DirOpen(path, &dir) != 0) {
resp.status = 0x02; resp.status = 0x02;
auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse)); auto* om = ble_hs_mbuf_from_flat(&resp, sizeof(ListDirResponse));
ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om); ble_gattc_notify_custom(connectionHandle, transferCharacteristicHandle, om);
break; break;
}; };
// Count Total files in directory.
while (fs.DirRead(&dir, &info)) { while (fs.DirRead(&dir, &info)) {
resp.totalentries++; resp.totalentries++;
} }

View file

@ -141,17 +141,18 @@ int FS::SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off,
namespace { namespace {
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) { lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t mode) {
lfs_file_t* file = static_cast<lfs_file_t*>(file_p); lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
FS* filesys = static_cast<FS*>(drv->user_data); FS* filesys = static_cast<FS*>(drv->user_data);
filesys->FileOpen(file, path, LFS_O_RDONLY); int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
if (res == 0) {
if (file->type == 0) { if (file->type == 0) {
return LV_FS_RES_FS_ERR; return LV_FS_RES_FS_ERR;
} else { } else {
return LV_FS_RES_OK; return LV_FS_RES_OK;
} }
} }
return LV_FS_RES_NOT_EX;
}
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) { lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
FS* filesys = static_cast<FS*>(drv->user_data); FS* filesys = static_cast<FS*>(drv->user_data);