You can now have INFO output, but not DEBUG output. Added support for commands via Serial.
This commit is contained in:
@ -6,10 +6,13 @@ Controller::Controller(Player* p) {
|
||||
_rfid = new MFRC522(PIN_RC522_CS, MFRC522::UNUSED_PIN);
|
||||
|
||||
SPIMaster::enable(PIN_RC522_CS);
|
||||
Serial.println("Initializing MFRC522...");
|
||||
DEBUG("Initializing RC522...");
|
||||
_rfid->PCD_Init();
|
||||
_rfid->PCD_DumpVersionToSerial();
|
||||
#ifdef SHOW_DEBUG
|
||||
_rfid->PCD_DumpVersionToSerial();
|
||||
#endif
|
||||
SPIMaster::disable();
|
||||
INFO("RC522 initialized.\n");
|
||||
}
|
||||
|
||||
void Controller::loop() {
|
||||
@ -38,39 +41,78 @@ uint32_t Controller::_get_rfid_card_uid() {
|
||||
|
||||
void Controller::_check_rfid() {
|
||||
uint32_t uid = _get_rfid_card_uid();
|
||||
//Serial.printf("Found card: %08x\n", uid);
|
||||
if (uid != _last_rfid_card_uid) {
|
||||
if (uid > 0) {
|
||||
Serial.printf("New RFID card uid: %08x\n", uid);
|
||||
// Play
|
||||
String s_uid = String(uid, HEX);
|
||||
_player->play_album(s_uid);
|
||||
} else {
|
||||
Serial.println("No more RFID card.");
|
||||
// Stop
|
||||
_player->stop();
|
||||
}
|
||||
_last_rfid_card_uid = uid;
|
||||
if (uid > 0) {
|
||||
INFO("New RFID card uid: %08x\n", uid);
|
||||
String s_uid = String(uid, HEX);
|
||||
_player->play_album(s_uid);
|
||||
} else {
|
||||
INFO("No more RFID card.");
|
||||
_player->stop();
|
||||
}
|
||||
_last_rfid_card_uid = uid;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
} else if (c=='q') {
|
||||
_player->play_system_sound("12345678/Biene Maja.mp3");
|
||||
Serial.printf("%c", c);
|
||||
if (c==10 || c==13) {
|
||||
if (_serial_buffer.length()>0) {
|
||||
_execute_serial_command(_serial_buffer);
|
||||
_serial_buffer = String();
|
||||
}
|
||||
} else {
|
||||
_serial_buffer.concat(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::_execute_serial_command(String cmd) {
|
||||
DEBUG("Executing command: %s", cmd.c_str());
|
||||
|
||||
if (cmd.equals("ls")) {
|
||||
_execute_command_ls("/");
|
||||
} else if (cmd.startsWith("ls ")) {
|
||||
_execute_command_ls(cmd.substring(3));
|
||||
} else if (cmd.startsWith("play ")) {
|
||||
_player->play_album(cmd.substring(5));
|
||||
} else if (cmd.startsWith("sys ")) {
|
||||
_player->play_system_sound(cmd.substring(4));
|
||||
} else if (cmd.equals("stop")) {
|
||||
_player->stop();
|
||||
} else if (cmd.equals("help")) {
|
||||
_execute_command_help();
|
||||
} else if (cmd.equals("-")) {
|
||||
_player->vol_down();
|
||||
} else if (cmd.equals("+")) {
|
||||
_player->vol_up();
|
||||
} else if (cmd.equals("p")) {
|
||||
_player->track_prev();
|
||||
} else if (cmd.equals("n")) {
|
||||
_player->track_next();
|
||||
} else {
|
||||
ERROR("Unknown command: %s\n", cmd.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void Controller::_execute_command_ls(String path) {
|
||||
INFO("Listing contents of %s:\n", path.c_str());
|
||||
std::list<String> files = _player->ls(path);
|
||||
for(std::list<String>::iterator it=files.begin(); it!=files.end(); it++) {
|
||||
INFO(" %s\n", (*it).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::_execute_command_help() {
|
||||
INFO("Valid commands are:");
|
||||
INFO(" help - Displays this help\n");
|
||||
INFO(" ls [dir] - Lists the contents of [dir] or, if not given, of /\n");
|
||||
INFO(" play [id] - Plays the album with the given id\n");
|
||||
INFO(" sys [file]- Plays the file as system sound\n");
|
||||
INFO(" stop - Stops playback\n");
|
||||
INFO(" - / + - Decrease or increase the volume\n");
|
||||
INFO(" p / n - Previous or next track\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user