Playing and controlling MP3s works great. \o/

This commit is contained in:
2019-08-06 20:50:11 +02:00
parent 2a7dd5d8a1
commit b8d4d6bb92
12 changed files with 432 additions and 193 deletions

View File

@ -1,42 +1,16 @@
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include "config.h"
#include "buttons.h"
#include "controller.h"
#include "player.h"
#include "sd_card.h"
#include "spi_master.h"
Buttons* buttons;
Controller* controller;
Player* player;
SDCard* sd;
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
void setup() {
delay(500);
Serial.begin(74880);
Serial.println("Starting.");
@ -44,12 +18,22 @@ void setup() {
SPI.begin();
SPIMaster::init();
sd = new SDCard();
player = new Player(sd);
controller = new Controller(player, sd);
buttons = new Buttons(controller);
SPIMaster::enable(PIN_SD_CS);
if (SD.begin(PIN_SD_CS)) {
Serial.println("SD card initialized.");
} else {
Serial.println("Could not initialize SD card. Halting.");
while(1);
}
player = new Player();
controller = new Controller(player);
//player->play_album("12345678");
}
void loop() {
bool more_data_needed = player->loop();
if (more_data_needed) return;
controller->loop();
}