Skip to content

Commit

Permalink
Add a way to control the type of the SdFat file being used
Browse files Browse the repository at this point in the history
This change introduce a new USE_SDFAT_FAT32 preprocessor variable that can be set to control the compilation of the library. When set, the library will use the File32 and SdFat32 types from the SdFat library rather than the default File and SdFat whose meaning is context dependant.

This serves two purposes:
- when an Arduino core has an FS.h header then currently the code will not compile because the SdFat and File classes are not defined.
- the default SdFat File type on modern core is a typedef for SdFat FsFile type, which has a subset of the interface of the File32 one, which also prevent some existing code from compiling.

This change is a no-op for people who don’t define the new variable, so it should not break any existing code.
  • Loading branch information
mkende committed Jul 17, 2024
1 parent 2f39e70 commit 51dd451
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Adafruit_VS1053.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) {
// must be at the end of the file
if (_loopPlayback) {
// play in loop
#if defined(USE_SDFAT_FAT32)
char fileName[32];
if (currentTrack.getName(fileName, 32) && isMP3File(fileName)) {
#else
if (isMP3File(currentTrack.name())) {
#endif
currentTrack.seek(mp3_ID3Jumper(currentTrack));
} else {
currentTrack.seek(0);
Expand Down
7 changes: 6 additions & 1 deletion Adafruit_VS1053.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

#include <Adafruit_SPIDevice.h>

#if defined(PREFER_SDFAT_LIBRARY)
#if defined(PREFER_SDFAT_LIBRARY) || defined(USE_SDFAT_FAT32)
#include <SdFat.h>
#if defined(USE_SDFAT_FAT32)
extern SdFat32 SD;
typedef File32 File;
#else
extern SdFat SD;
#endif
#else
#include <SD.h>
#endif
Expand Down

0 comments on commit 51dd451

Please sign in to comment.