Fixed RFID scanning and implemented calling actions on Player.
This commit is contained in:
parent
393db24175
commit
417421ae31
@ -11,6 +11,8 @@ private:
|
|||||||
bool _rfid_enabled = true;
|
bool _rfid_enabled = true;
|
||||||
void _check_rfid();
|
void _check_rfid();
|
||||||
void _check_serial();
|
void _check_serial();
|
||||||
|
uint32_t _get_rfid_card_uid();
|
||||||
|
uint32_t _last_rfid_card_uid = 0;
|
||||||
Player* _player;
|
Player* _player;
|
||||||
unsigned long _last_rfid_scan_at = 0;
|
unsigned long _last_rfid_scan_at = 0;
|
||||||
public:
|
public:
|
||||||
|
@ -21,16 +21,37 @@ void Controller::loop() {
|
|||||||
_check_serial();
|
_check_serial();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::_check_rfid() {
|
uint32_t Controller::_get_rfid_card_uid() {
|
||||||
SPIMaster::enable(PIN_RC522_CS);
|
SPIMaster::enable(PIN_RC522_CS);
|
||||||
|
if (!_rfid->PICC_ReadCardSerial()) {
|
||||||
if (!_rfid->PICC_IsNewCardPresent()) {
|
if (!_rfid->PICC_IsNewCardPresent()) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!_rfid->PICC_ReadCardSerial()) {
|
if (!_rfid->PICC_ReadCardSerial()) {
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
_rfid->PICC_DumpToSerial(&(_rfid->uid));
|
}
|
||||||
|
uint32_t uid = _rfid->uid.uidByte[0]<<24 | _rfid->uid.uidByte[1]<<16 | _rfid->uid.uidByte[2]<<8 | _rfid->uid.uidByte[3];
|
||||||
SPIMaster::disable();
|
SPIMaster::disable();
|
||||||
|
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::_check_serial() {
|
void Controller::_check_serial() {
|
||||||
|
@ -196,7 +196,7 @@ std::list<String> Player::_files_in_dir(String path) {
|
|||||||
filename.endsWith(".ogg") ||
|
filename.endsWith(".ogg") ||
|
||||||
filename.endsWith(".wma") ||
|
filename.endsWith(".wma") ||
|
||||||
filename.endsWith(".mp4") ||
|
filename.endsWith(".mp4") ||
|
||||||
filename.endsWith(".mpa")) {
|
filename.endsWith(".mpa"))) {
|
||||||
//Serial.printf("Adding file %s\n", filename.c_str());
|
//Serial.printf("Adding file %s\n", filename.c_str());
|
||||||
result.push_back(path + filename);
|
result.push_back(path + filename);
|
||||||
} else {
|
} else {
|
||||||
@ -211,6 +211,7 @@ std::list<String> Player::_files_in_dir(String path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Player::play_album(String album) {
|
bool Player::play_album(String album) {
|
||||||
|
//if (_state==playing) stop();
|
||||||
album_state s = _last_tracks[album.c_str()];
|
album_state s = _last_tracks[album.c_str()];
|
||||||
Serial.printf("Last index for album %s was %d,%d\n", album.c_str(), s.index, s.position);
|
Serial.printf("Last index for album %s was %d,%d\n", album.c_str(), s.index, s.position);
|
||||||
return play_song(album, s.index, s.position);
|
return play_song(album, s.index, s.position);
|
||||||
|
Loading…
Reference in New Issue
Block a user