add support for storage stats on nrf52
This commit is contained in:
@@ -44,6 +44,20 @@ void DataStore::begin() {
|
|||||||
#include <InternalFileSystem.h>
|
#include <InternalFileSystem.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||||
|
int _countLfsBlock(void *p, lfs_block_t block){
|
||||||
|
lfs_size_t *size = (lfs_size_t*) p;
|
||||||
|
*size += 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lfs_ssize_t _getLfsUsedBlockCount() {
|
||||||
|
lfs_size_t size = 0;
|
||||||
|
lfs_traverse(InternalFS._getFS(), _countLfsBlock, &size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t DataStore::getStorageUsedKb() const {
|
uint32_t DataStore::getStorageUsedKb() const {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
return SPIFFS.usedBytes() / 1024;
|
return SPIFFS.usedBytes() / 1024;
|
||||||
@@ -52,8 +66,13 @@ uint32_t DataStore::getStorageUsedKb() const {
|
|||||||
info.usedBytes = 0;
|
info.usedBytes = 0;
|
||||||
_fs->info(info);
|
_fs->info(info);
|
||||||
return info.usedBytes / 1024;
|
return info.usedBytes / 1024;
|
||||||
|
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||||
|
const lfs_config* config = InternalFS._getFS()->cfg;
|
||||||
|
int usedBlockCount = _getLfsUsedBlockCount();
|
||||||
|
int usedBytes = config->block_size * usedBlockCount;
|
||||||
|
return usedBytes / 1024;
|
||||||
#else
|
#else
|
||||||
return 0; // TODO: InternalFS. method?
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +84,12 @@ uint32_t DataStore::getStorageTotalKb() const {
|
|||||||
info.totalBytes = 0;
|
info.totalBytes = 0;
|
||||||
_fs->info(info);
|
_fs->info(info);
|
||||||
return info.totalBytes / 1024;
|
return info.totalBytes / 1024;
|
||||||
|
#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||||
|
const lfs_config* config = InternalFS._getFS()->cfg;
|
||||||
|
int totalBytes = config->block_size * config->block_count;
|
||||||
|
return totalBytes / 1024;
|
||||||
#else
|
#else
|
||||||
return 0; // TODO: InternalFS. method?
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user