Skip to content

Commit 0212537

Browse files
Add default support for ESP-WROVER-B and dynamic art cache sizing
1 parent 342816e commit 0212537

File tree

7 files changed

+80
-9
lines changed

7 files changed

+80
-9
lines changed

platformio.ini

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ build_flags =
4343
-D SMOOTH_FONT=1
4444
-D SPI_FREQUENCY=27000000
4545
-I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/**
46-
extra_scripts = pre:generate_compile_time.py
47-
;board_build.partitions = no_ota.csv
48-
board_build.partitions = partitions/custom_no_ota.csv
46+
extra_scripts = pre:generate_compile_time.py
47+
; no_ota.csv is 4MB ESP32-WROVER-B compatible. limits art cache to 10 albums.
48+
board_build.partitions = no_ota.csv
49+
; custom_no_ota.csv is 8MB Flash ESP32-WROVER-E compatible. art cache supports 60 albums.
50+
; board_build.partitions = partitions/custom_no_ota.csv
4951
board_build.filesystem = littlefs
5052
lib_deps =
5153
arkhipenko/TaskScheduler @ ^3.8.5

src/SCFileIO.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ bool SCFileIO::initialize()
9898

9999
}
100100

101+
/*
102+
** ===================================================================
103+
** getPartitionSize()
104+
** Returns the total size in bytes of the mounted LittleFS partition.
105+
**
106+
** Returns:
107+
** Size of the partition in bytes. Returns 0 if the value can't be retrieved
108+
** or the semaphore acquisition fails.
109+
** ===================================================================
110+
*/
111+
size_t SCFileIO::getPartitionSize()
112+
{
113+
if (!takeSemaphore())
114+
{
115+
spLogE(LOGTAG_FILEIO, "Failed to acquire semaphore for getPartitionSize().");
116+
return 0;
117+
}
118+
119+
size_t partitionSize = LittleFS.totalBytes(); // No need for FSInfo
120+
121+
giveSemaphore();
122+
return partitionSize;
123+
}
124+
101125
/*
102126
** ===================================================================
103127
** open()

src/SCFileIO.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class SCFileIO
3434
// Initializes the semaphore. Must be called before using the class.
3535
bool initialize();
3636

37+
// Get partition size
38+
size_t getPartitionSize();
39+
3740
// Opens a file safely using LittleFS
3841
File open(const char *path, const char *mode);
3942

src/SpotifyArtMgr.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ SpotifyArtMgr* SpotifyArtMgr::getInstance()
141141
if (gInstance == nullptr)
142142
{
143143
gInstance = new SpotifyArtMgr();
144+
// figure out if configured with more than 4MB of file space
145+
gInstance->determineCacheSize();
144146
// populate the index to last run
145147
String filePath = String(gCacheFileroot) + ".txt";
146148
SCFileIO::getInstance().hexDump(LOGTAG_CACHE, filePath.c_str());
@@ -655,6 +657,43 @@ void SpotifyArtMgr::saveCacheIndex()
655657
//SCFileIO::getInstance().listFiles();
656658
}
657659

660+
/*
661+
** ===================================================================
662+
** determineCacheSize()
663+
** Determines the maximum number of album art files to cache based
664+
** on the size of the LittleFS partition. If the partition is at
665+
** least 3,000,000 bytes, this is assumed to be a custom partition
666+
** layout and the cache size is increased to 60. Otherwise, the
667+
** default cache size (typically 10) is used.
668+
**
669+
** This method should be called during initialization to adjust the
670+
** cache size dynamically based on the hardware configuration.
671+
**
672+
** Notes:
673+
** - SCFileIO::getPartitionSize() is used to obtain the partition size
674+
** in a thread-safe manner.
675+
** - A partition size >= 3,000,000 bytes indicates use of the custom
676+
** no_ota.csv layout with a larger cache capacity.
677+
** - The default cache size should be initialized before this is called.
678+
**
679+
** ===================================================================
680+
*/
681+
682+
void SpotifyArtMgr::determineCacheSize()
683+
{
684+
size_t partitionSize = SCFileIO::getInstance().getPartitionSize();
685+
686+
if (partitionSize >= 3000000)
687+
{
688+
_maxCacheSize = 60;
689+
spLogI(LOGTAG_CACHE, "Custom partition detected (size: %zu). Setting max cache size to 60.", partitionSize);
690+
}
691+
else
692+
{
693+
spLogI(LOGTAG_CACHE, "Standard partition detected (size: %zu). Using default cache size: %zu.", partitionSize, _maxCacheSize);
694+
}
695+
}
696+
658697
/*
659698
** ===================================================================
660699
** loadCacheIndex()
@@ -795,6 +834,8 @@ void SpotifyArtMgr::loadCacheIndex()
795834
** ===================================================================
796835
** printCacheIndex()
797836
** Logs the current cache state in a formatted and readable format.
837+
** Check code for log levels used.
838+
**
798839
** The log includes:
799840
** - List of URLs and their associated file names in the LRU order.
800841
** - The calculated checksum for the cache state.
@@ -825,7 +866,7 @@ void SpotifyArtMgr::loadCacheIndex()
825866
void SpotifyArtMgr::printCacheIndex(const char* tag)
826867
{
827868
spLogD(tag, "------------------------------------------------------------------------------------------");
828-
spLogI(tag, "Cache:");
869+
spLogD(tag, "Cache:");
829870

830871
// If the cache is empty, indicate that
831872
if (_cacheList.empty())
@@ -843,7 +884,7 @@ void SpotifyArtMgr::printCacheIndex(const char* tag)
843884
auto it = _urlToFileMap.find(url);
844885
if (it != _urlToFileMap.end())
845886
{
846-
spLogI(tag, " \"%s\": \"%s\"", url.c_str(), it->second.c_str());
887+
spLogD(tag, " \"%s\": \"%s\"", url.c_str(), it->second.c_str());
847888
serializedData += url + ":" + it->second + "\n";
848889
}
849890
else

src/SpotifyArtMgr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class SpotifyArtMgr
8989
SpotifyArtMgr();
9090

9191
// Private methods
92+
void determineCacheSize();
9293
void loadCacheIndex();
9394
bool downloadFile(String url, String filename);
9495
String generateLocalFileName();
@@ -101,7 +102,7 @@ class SpotifyArtMgr
101102
static SpotifyArtMgr* gInstance;
102103

103104
// Cache configuration
104-
size_t _maxCacheSize = 60; // Default maximum cache size
105+
size_t _maxCacheSize = 10; // Default maximum cache size
105106

106107
SemaphoreHandle_t xSemaphoreArtFetchCompleted = xSemaphoreCreateMutex();;
107108
bool _isDownloadPending = false;

src/Vault.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void Vault::initialize()
116116
if (!LittleFS.exists(USER_INI_PATH))
117117
{
118118
_useHardcodedValues = true;
119-
spLogV(LOGTAG_VAULT, "%s does not exist. Using hardcoded credentials.", USER_INI_PATH);
119+
spLogI(LOGTAG_VAULT, "%s does not exist. Using hardcoded credentials.", USER_INI_PATH);
120120
return;
121121
}
122122

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ void setupLogging()
329329
logger.setLogLevel(LOGTAG_HEAP, ESP_LOG_INFO);
330330
//logger.setLogLevel(LOGTAG_TRACE, ESP_LOG_INFO);
331331
logger.setLogLevel(LOGTAG_FILEIO, ESP_LOG_INFO);
332-
// logger.setLogLevel(LOGTAG_CACHE, ESP_LOG_DEBUG);
333-
logger.setLogLevel(LOGTAG_VAULT, ESP_LOG_VERBOSE);
332+
logger.setLogLevel(LOGTAG_CACHE, ESP_LOG_INFO);
333+
logger.setLogLevel(LOGTAG_VAULT, ESP_LOG_INFO);
334334

335335
// Supress logs for ESP32 components
336336
logger.setLogLevel("ssl_client", ESP_LOG_NONE);

0 commit comments

Comments
 (0)