Compare commits

..

No commits in common. "1bb358c961e313c9ff49b50a31007f81d363401e" and "b6dc04920a6101a51d1a3e530a27c348fd72b228" have entirely different histories.

3 changed files with 68 additions and 44 deletions

View File

@ -16,9 +16,8 @@ public:
virtual void seek(size_t position) = 0; virtual void seek(size_t position) = 0;
virtual size_t size() = 0; virtual size_t size() = 0;
virtual void close() = 0; virtual void close() = 0;
virtual void skip_id3_tag() {};
virtual bool usable() = 0; virtual bool usable() = 0;
virtual int peek(int offset) = 0;
void skip_id3_tag();
}; };
class SDDataSource : public DataSource { class SDDataSource : public DataSource {
@ -33,8 +32,8 @@ public:
void seek(size_t position); void seek(size_t position);
size_t size(); size_t size();
void close(); void close();
void skip_id3_tag();
bool usable(); bool usable();
int peek(int offset=0);
}; };
class HTTPSDataSource : public DataSource { class HTTPSDataSource : public DataSource {
@ -55,4 +54,5 @@ public:
void close(); void close();
bool usable(); bool usable();
int peek(int offset=0); int peek(int offset=0);
void skip_id3_tag();
}; };

View File

@ -11,16 +11,21 @@
[platformio] [platformio]
default_envs = esp32 default_envs = esp32
[env] [extra]
lib_deps =
63 ; MFRC522
https://github.com/me-no-dev/ESPAsyncWebServer.git
ArduinoJSON
6691 ; TinyXML
[env:esp32]
platform = espressif32 platform = espressif32
board = esp-wrover-kit board = esp-wrover-kit
framework = arduino framework = arduino
upload_speed = 512000 upload_speed = 512000
lib_deps = build_flags=!./build_version.sh
63 ; MFRC522 lib_deps = ${extra.lib_deps}
https://github.com/me-no-dev/ESPAsyncWebServer.git upload_port = /dev/cu.SLAB_USBtoUART
64 ; ArduinoJSON
6691 ; TinyXML
monitor_speed = 115200 monitor_speed = 115200
board_build.embed_files = board_build.embed_files =
src/webinterface/timezones.json.gz src/webinterface/timezones.json.gz
@ -30,8 +35,10 @@ board_build.embed_files =
extra_scripts = extra_scripts =
post:tools/post_build.py post:tools/post_build.py
[env:esp32]
build_flags=!./build_version.sh
upload_port = /dev/cu.SLAB_USBtoUART
[env:deploy] [env:deploy]
platform = espressif32
board = esp-wrover-kit
framework = arduino
lib_deps = ${extra.lib_deps}
board_build.embed_txtfiles = src/index.html
board_build.partitions = partitions.csv

View File

@ -1,29 +1,5 @@
#include "data_sources.h" #include "data_sources.h"
void DataSource::skip_id3_tag() {
if (peek(0)=='I' && peek(1)=='D' && peek(2)=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag marker
read(); read(); read();
// Skip ID3 tag version
read(); read();
byte tags = read();
bool footer_present = tags & 0x10;
DEBUG("ID3 footer found: %d\n", footer_present);
uint32_t offset = 0;
for (byte i=0; i<4; i++) {
offset <<= 7;
offset |= (0x7F & read());
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
seek(offset);
} else {
DEBUG("No ID3 tag found\n");
}
}
////////////// SDDataSource ////////////// ////////////// SDDataSource //////////////
SDDataSource::SDDataSource(String file) { _file = SD.open(file, "r"); } SDDataSource::SDDataSource(String file) { _file = SD.open(file, "r"); }
SDDataSource::~SDDataSource() { if (_file) _file.close(); } SDDataSource::~SDDataSource() { if (_file) _file.close(); }
@ -34,16 +10,33 @@ void SDDataSource::seek(size_t position) { _file.seek(position); }
size_t SDDataSource::size() { return _file.size(); } size_t SDDataSource::size() { return _file.size(); }
void SDDataSource::close() { _file.close(); } void SDDataSource::close() { _file.close(); }
bool SDDataSource::usable() { return _file; } bool SDDataSource::usable() { return _file; }
int SDDataSource::peek(int offset) {
if (offset==0) return _file.peek(); void SDDataSource::skip_id3_tag() {
size_t start_position = _file.position(); uint32_t original_position = _file.position();
_file.seek(start_position + offset); uint32_t offset = 0;
int result = _file.peek(); if (_file.read()=='I' && _file.read()=='D' && _file.read()=='3') {
_file.seek(start_position); DEBUG("ID3 tag found\n");
return result; // 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);
}
} }
////////////// HTTPSDataSource ////////////// ////////////// HTTPSDataSource //////////////
HTTPSDataSource::HTTPSDataSource(String url, uint32_t offset) { HTTPSDataSource::HTTPSDataSource(String url, uint32_t offset) {
_url = url; _url = url;
@ -69,3 +62,27 @@ void HTTPSDataSource::seek(size_t position) { _http->close(); delete _http; _ini
size_t HTTPSDataSource::size() { return _http->getSize(); } size_t HTTPSDataSource::size() { return _http->getSize(); }
void HTTPSDataSource::close() { _http->close(); } void HTTPSDataSource::close() { _http->close(); }
int HTTPSDataSource::peek(int offset) { return _http->peek(offset); } int HTTPSDataSource::peek(int offset) { return _http->peek(offset); }
void HTTPSDataSource::skip_id3_tag() {
uint32_t offset = 0;
if (_http->peek(0)=='I' && _http->peek(1)=='D' && _http->peek(2)=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag marker
_http->read(); _http->read(); _http->read();
// Skip ID3 tag version
_http->read(); _http->read();
byte tags = _http->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 & _http->read());
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
seek(offset);
} else {
DEBUG("No ID3 tag found\n");
}
}