From 05839052fbbc2e81c5f7ab8b85404c3cd18822bb Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 9 Aug 2020 11:21:45 -0700 Subject: [PATCH] Add FatFS file source (#289) Thanks to Marc Madaule for the patch adding FatFS for the ESP32 as a file source. --- src/AudioFileSourceFATFS.h | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/AudioFileSourceFATFS.h diff --git a/src/AudioFileSourceFATFS.h b/src/AudioFileSourceFATFS.h new file mode 100644 index 0000000..88e43f0 --- /dev/null +++ b/src/AudioFileSourceFATFS.h @@ -0,0 +1,64 @@ +/* + AudioFileSourceFS + Input Arduion "file" to be used by AudioGenerator + + Copyright (C) 2017 Earle F. Philhower, III + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _AUDIOFILESOURCEFATFS_H +#define _AUDIOFILESOURCEFATFS_H + +#ifdef ESP32 + +#include +#include +#include + +#include "AudioFileSource.h" +#include "AudioFileSourceFS.h" + +/* + AudioFileSource for FAT filesystem. + */ +class AudioFileSourceFATFS : public AudioFileSourceFS +{ + public: + AudioFileSourceFATFS() : AudioFileSourceFS(FFat) {}; + AudioFileSourceFATFS(const char *filename) : AudioFileSourceFS(FFat) { + // We call open() ourselves because calling AudioFileSourceFS(FFat, filename) + // would call the parent open() and we do not want that + open(filename); + }; + + virtual bool open(const char *filename) override { + // make sure that the FATFS filesystem has been mounted + if (!FFat.begin()) { + audioLogger->printf_P(PSTR("Unable to initialize FATFS filesystem\n")); + return false; + } else { + // now that the fielsystem has been mounted, we can call the regular parent open() function + return AudioFileSourceFS::open(filename); + } + }; + + // Others are inherited from base +}; + +#endif + + +#endif +