11#include < Arduino.h>
22#include " DataStore.h"
33
4+ #if defined(EXTRAFS) || defined(SPIFLASH)
5+ #define MAX_BLOBRECS 100
6+ #else
7+ #define MAX_BLOBRECS 20
8+ #endif
9+
410DataStore::DataStore (FILESYSTEM& fs, mesh::RTCClock& clock) : _fs(&fs), _clock(&clock),
511#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
612 identity_store (fs, " " )
@@ -41,7 +47,9 @@ void DataStore::begin() {
4147#elif defined(RP2040_PLATFORM)
4248 #include < LittleFS.h>
4349#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
44- #include < InternalFileSystem.h>
50+ // #include <InternalFileSystem.h> // disabled for now, leaving here for dual fs branch
51+ #include < CustomLFS.h>
52+ #include < CustomLFS_SPIFlash.h>
4553#endif
4654
4755#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
@@ -51,9 +59,9 @@ int _countLfsBlock(void *p, lfs_block_t block){
5159 return 0 ;
5260}
5361
54- lfs_ssize_t _getLfsUsedBlockCount () {
62+ lfs_ssize_t _getLfsUsedBlockCount (FILESYSTEM* fs ) {
5563 lfs_size_t size = 0 ;
56- lfs_traverse (InternalFS. _getFS (), _countLfsBlock, &size);
64+ lfs_traverse (fs-> _getFS (), _countLfsBlock, &size);
5765 return size;
5866}
5967#endif
@@ -67,8 +75,8 @@ uint32_t DataStore::getStorageUsedKb() const {
6775 _fs->info (info);
6876 return info.usedBytes / 1024 ;
6977#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
70- const lfs_config* config = InternalFS. _getFS ()->cfg ;
71- int usedBlockCount = _getLfsUsedBlockCount ();
78+ const lfs_config* config = _fs-> _getFS ()->cfg ;
79+ int usedBlockCount = _getLfsUsedBlockCount (_fs );
7280 int usedBytes = config->block_size * usedBlockCount;
7381 return usedBytes / 1024 ;
7482#else
@@ -85,7 +93,7 @@ uint32_t DataStore::getStorageTotalKb() const {
8593 _fs->info (info);
8694 return info.totalBytes / 1024 ;
8795#elif defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
88- const lfs_config* config = InternalFS. _getFS ()->cfg ;
96+ const lfs_config* config = _fs-> _getFS ()->cfg ;
8997 int totalBytes = config->block_size * config->block_count ;
9098 return totalBytes / 1024 ;
9199#else
@@ -109,6 +117,7 @@ bool DataStore::removeFile(const char* filename) {
109117
110118bool DataStore::formatFileSystem () {
111119#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
120+ // InternalFS.format(); // leaving as placeholder to remind for dual fs branch
112121 return _fs->format ();
113122#elif defined(RP2040_PLATFORM)
114123 return LittleFS.format ();
@@ -336,7 +345,7 @@ void DataStore::checkAdvBlobFile() {
336345 if (file) {
337346 BlobRec zeroes;
338347 memset (&zeroes, 0 , sizeof (zeroes));
339- for (int i = 0 ; i < 20 ; i++) { // pre-allocate to fixed size
348+ for (int i = 0 ; i < MAX_BLOBRECS ; i++) { // pre-allocate to fixed size
340349 file.write ((uint8_t *) &zeroes, sizeof (zeroes));
341350 }
342351 file.close ();
0 commit comments