Moved reading of SD card data into a dedicated class DataSource.
This commit is contained in:
35
src/data_sources.cpp
Normal file
35
src/data_sources.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "data_sources.h"
|
||||
|
||||
////////////// SDDataSource //////////////
|
||||
SDDataSource::SDDataSource(String file) { _file = SD.open(file, "r"); }
|
||||
SDDataSource::~SDDataSource() { if (_file) _file.close(); }
|
||||
size_t SDDataSource::read(uint8_t* buf, size_t len) { return _file.read(buf, len); }
|
||||
uint8_t SDDataSource::read() { return _file.read(); }
|
||||
size_t SDDataSource::position() { return _file.position(); }
|
||||
void SDDataSource::seek(size_t position) { _file.seek(position); }
|
||||
size_t SDDataSource::size() { return _file.size(); }
|
||||
void SDDataSource::close() { _file.close(); }
|
||||
|
||||
void SDDataSource::skip_id3_tag() {
|
||||
uint32_t original_position = _file.position();
|
||||
uint32_t offset = 0;
|
||||
if (_file.read()=='I' && _file.read()=='D' && _file.read()=='3') {
|
||||
DEBUG("ID3 tag found\n");
|
||||
// Skip ID3 tag version
|
||||
_file.read(); _file.read();
|
||||
byte tags = _file.read();
|
||||
bool footer_present = tags & 0x10;
|
||||
DEBUG("ID3 footer found: %d\n", footer_present);
|
||||
for (byte i=0; i<4; i++) {
|
||||
offset <<= 7;
|
||||
offset |= (0x7F & _file.read());
|
||||
}
|
||||
offset += 10;
|
||||
if (footer_present) offset += 10;
|
||||
DEBUG("ID3 tag length is %d bytes.\n", offset);
|
||||
_file.seek(offset);
|
||||
} else {
|
||||
DEBUG("No ID3 tag found\n");
|
||||
_file.seek(original_position);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user