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 c313f6eb72
commit 2d1f049444
14 changed files with 249 additions and 180 deletions

View File

@ -2,11 +2,10 @@
#include "spi_master.h"
#include "config.h"
Controller::Controller(Player* p, Adafruit_MCP23017* m, SPIMaster* s) {
Controller::Controller(Player* p, SPIMaster* s) {
_player = p;
_mcp = m;
_spi = s;
_rfid = new MFRC522(D0, MFRC522::UNUSED_PIN);
_rfid = new MFRC522(17, MFRC522::UNUSED_PIN);
BTN_NEXT_SETUP();
BTN_PREV_SETUP();

View File

@ -1,3 +1,4 @@
/*
#include "http_server.h"
HTTPServer::HTTPServer(Player* p, Controller* c) {
@ -121,3 +122,4 @@ void HTTPServer::loop() {
_http_server->handleClient();
MDNS.update();
}
*/

View File

@ -1,8 +1,7 @@
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <WiFi.h>
#include "config.h"
#include "controller.h"
#include "player.h"
@ -13,8 +12,7 @@
Controller* controller;
Player* player;
Adafruit_MCP23017* mcp;
HTTPServer* http_server;
//HTTPServer* http_server;
FtpServer* ftp_server;
MQTTClient* mqtt_client;
unsigned long last_mqtt_report = 0;
@ -22,7 +20,7 @@ unsigned long last_mqtt_report = 0;
void setup() {
delay(500);
Serial.begin(74880);
/*Serial.println("Starting...");
Serial.println("Starting...");
Serial.println("Started.");
INFO("Starting.\n");
#ifdef VERSION
@ -32,30 +30,10 @@ void setup() {
#endif
INFO("Initializing...\n");
DEBUG("Setting up MCP...\n");*/
Wire.begin();
Wire.setClock(1700000);
uint8_t addr = MCP23017_ADDRESS + MCP_I2C_ADDR;
while(true) {
Wire.beginTransmission(addr);
byte status = Wire.endTransmission();
if (status==0) {
DEBUG("I2C device found.");
break;
}
DEBUG("No I2C device found.");
delay(100);
}
mcp = new Adafruit_MCP23017();
mcp->begin(MCP_I2C_ADDR);
INFO("MCP initialized.\n");
DEBUG("Setting up SPI...\n");
SPI.begin();
SPI.setHwCs(false);
SPIMaster* spi = new SPIMaster(mcp);
SPIMaster* spi = new SPIMaster();
INFO("SPI initialized.\n");
DEBUG("Setting up SD card...\n");
@ -68,8 +46,8 @@ void setup() {
spi->select_sd(false);
DEBUG("Initializing Player and Controller...\n");
player = new Player(mcp, spi);
controller = new Controller(player, mcp, spi);
player = new Player(spi);
controller = new Controller(player, spi);
INFO("Player and controller initialized.\n");
DEBUG("Connecting to wifi \"%s\"...\n", WIFI_SSID);
@ -83,12 +61,12 @@ void setup() {
INFO("WiFi connected.\n");
mqtt_client = new MQTTClient();
MDNS.begin("esmp3");
//MDNS.begin("esmp3");
controller->set_mqtt_client(mqtt_client);
DEBUG("Setting up WiFi and web server...\n");
http_server = new HTTPServer(player, controller);
//http_server = new HTTPServer(player, controller);
ftp_server = new FtpServer();
ftp_server->begin("user", "pass");
@ -101,7 +79,7 @@ void loop() {
if (more_data_needed) return;
controller->loop();
http_server->loop();
//http_server->loop();
ftp_server->handleFTP();
mqtt_client->loop();
if ((last_mqtt_report + 10000 < millis()) || last_mqtt_report > millis()) {

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();
}