Changed from ESP8266 to ESP32. Works much better.

HTTP server is disabled (for now).
This commit is contained in:
2019-11-11 05:32:41 +01:00
parent 2ea2ec479a
commit d799448c97
15 changed files with 273 additions and 204 deletions

View File

@ -2,12 +2,10 @@
#include "player.h"
#include "spi_master.h"
#include "tools.h"
//Player::_spi_settings
Player::Player(Adafruit_MCP23017* m, SPIMaster* s) {
_mcp = m;
Player::Player(SPIMaster* s) {
_spi = s;
PIN_VS1053_XRESET_SETUP();
PIN_VS1053_XRESET(HIGH);
@ -288,7 +286,8 @@ String Player::_find_album_dir(String id) {
File entry;
String result = String("");
while ((result.length()==0) && (entry = root.openNextFile())) {
String name = entry.name();
String name = entry.name() + 1;
TRACE("Checking if '%s' startsWith '%s'...\n", name.c_str(), id.c_str());
if (entry.isDirectory() && (name.startsWith(id_with_divider) || name.equals(id))) {
result = name;
}
@ -301,15 +300,20 @@ String Player::_find_album_dir(String id) {
std::list<String> Player::_files_in_dir(String path) {
_spi->select_sd();
DEBUG("Examining folder %s...\n", path.c_str());
TRACE("Examining folder %s...\n", path.c_str());
if (!path.startsWith("/")) path = String("/") + path;
if (!path.endsWith("/")) path.concat("/");
//if (!path.endsWith("/")) path.concat("/");
std::list<String> result;
if (!SD.exists(path)) return result;
if (!SD.exists(path)) {
DEBUG("Could not open path '%s'.\n", path.c_str());
_spi->select_sd(false);
return result;
}
File dir = SD.open(path);
File entry;
while (entry = dir.openNextFile()) {
String filename = entry.name();
filename = filename.substring(path.length() + 1);
if (!entry.isDirectory() &&
!filename.startsWith(".") &&
( filename.endsWith(".mp3") ||
@ -317,8 +321,8 @@ std::list<String> Player::_files_in_dir(String path) {
filename.endsWith(".wma") ||
filename.endsWith(".mp4") ||
filename.endsWith(".mpa"))) {
TRACE(" Adding entry %s\n", filename.c_str());
result.push_back(path + filename);
TRACE(" Adding entry %s\n", entry.name());
result.push_back(entry.name());
} else {
TRACE(" Ignoring entry %s\n", filename.c_str());
}
@ -410,11 +414,13 @@ void Player::_play_file(String file, uint32_t file_offset) {
_write_control_register(SCI_STATUS, _read_control_register(SCI_STATUS) & ~SS_DO_NOT_JUMP);
delay(100);
_spi->select_sd();
if (file_offset == 0) {
_file.seek(_id3_tag_offset(_file));
}
_refills = 0;
_current_play_position = _file.position();
_spi->select_sd(false);
_skip_to = file_offset;
if (_skip_to>0) _mute();
else _speaker_on();
@ -541,7 +547,9 @@ void Player::_refill() {
if ((status & SS_DO_NOT_JUMP) == 0) {
DEBUG("Skipping to %d.\n", _skip_to);
_flush(2048, _get_endbyte());
_spi->select_sd();
_file.seek(_skip_to);
_spi->select_sd(false);
_skip_to = 0;
_unmute();
}