esmp3/src/main.cpp

71 lines
1.4 KiB
C++

#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <MCP23S17/MCP23S17.h>
#include "config.h"
#include "controller.h"
#include "player.h"
#include "spi_master.h"
#include "http_server.h"
#include <ESP8266FtpServer.h>
Controller* controller;
Player* player;
MCP* mcp;
HTTPServer* http_server;
FtpServer* ftp_server;
void setup() {
delay(500);
Serial.begin(74880);
INFO("Starting.\n");
#ifdef VERSION
INFO("ESMP3 version %s\n", VERSION);
#else
INFO("ESMP3, version unknown\n");
#endif
INFO("Initializing...\n");
DEBUG("Setting up SPI...\n");
SPI.begin();
SPIMaster::init();
INFO("SPI initialized.\n");
DEBUG("Setting up MCP...\n");
SPIMaster::enable(PIN_MCP);
mcp = new MCP(0, PIN_MCP);
INFO("MCP initialized.");
DEBUG("Setting up SD card...\n");
SPIMaster::enable(PIN_SD_CS);
if (SD.begin(PIN_SD_CS)) {
INFO("SD card initialized.\n");
} else {
ERROR("Could not initialize SD card.\n");
}
DEBUG("Initializing Player and Controller...\n");
player = new Player(mcp);
controller = new Controller(player, mcp);
INFO("Player and controller initialized.\n");
DEBUG("Setting up WiFi and web server...\n");
http_server = new HTTPServer(player, controller);
ftp_server = new FtpServer();
ftp_server->begin("user", "pass");
INFO("Initialization completed.\n");
}
void loop() {
bool more_data_needed = player->loop();
if (more_data_needed) return;
controller->loop();
http_server->loop();
ftp_server->handleFTP();
}