2019-08-02 21:48:36 +00:00
|
|
|
#include "controller.h"
|
2019-08-06 18:50:11 +00:00
|
|
|
#include "spi_master.h"
|
2019-08-02 21:48:36 +00:00
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
Controller::Controller(Player* p) {
|
|
|
|
_player = p;
|
|
|
|
_rfid = new MFRC522(PIN_RC522_CS, MFRC522::UNUSED_PIN);
|
|
|
|
|
|
|
|
SPIMaster::enable(PIN_RC522_CS);
|
|
|
|
Serial.println("Initializing MFRC522...");
|
|
|
|
_rfid->PCD_Init();
|
|
|
|
_rfid->PCD_DumpVersionToSerial();
|
|
|
|
SPIMaster::disable();
|
2019-08-02 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
void Controller::loop() {
|
|
|
|
_check_rfid();
|
|
|
|
_check_serial();
|
2019-08-02 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
void Controller::_check_rfid() {
|
|
|
|
SPIMaster::enable(PIN_RC522_CS);
|
|
|
|
if (!_rfid->PICC_IsNewCardPresent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_rfid->PICC_ReadCardSerial()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_rfid->PICC_DumpToSerial(&(_rfid->uid));
|
|
|
|
SPIMaster::disable();
|
2019-08-02 21:48:36 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
void Controller::_check_serial() {
|
|
|
|
if (Serial.available() > 0) {
|
|
|
|
char c = Serial.read();
|
|
|
|
if (c == 'n') {
|
|
|
|
_player->track_next();
|
|
|
|
} else if (c=='p') {
|
|
|
|
_player->track_prev();
|
|
|
|
} else if (c=='s') {
|
|
|
|
_player->stop();
|
|
|
|
} else if (c=='+') {
|
|
|
|
_player->vol_up();
|
|
|
|
} else if (c=='-') {
|
|
|
|
_player->vol_down();
|
|
|
|
} else if (c==' ') {
|
|
|
|
_player->play_album("12345678");
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 21:48:36 +00:00
|
|
|
}
|