esmp3/src/main.cpp

50 lines
971 B
C++
Raw Normal View History

2019-08-02 21:48:36 +00:00
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <MCP23S17/MCP23S17.h>
2019-08-02 21:48:36 +00:00
#include "config.h"
#include "controller.h"
#include "player.h"
#include "spi_master.h"
2019-08-02 21:48:36 +00:00
Controller* controller;
Player* player;
MCP* mcp;
2019-08-02 21:48:36 +00:00
void setup() {
delay(500);
Serial.begin(74880);
INFO("Starting.\n");
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. Halting.\n");
while(1);
}
player = new Player(mcp);
controller = new Controller(player, mcp);
INFO("Initialization completed.\n");
2019-08-02 21:48:36 +00:00
}
void loop() {
bool more_data_needed = player->loop();
if (more_data_needed) return;
2019-08-02 21:48:36 +00:00
controller->loop();
2019-08-02 21:48:36 +00:00
}