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;
|
||||
void _check_rfid();
|
||||
void _check_serial();
|
||||
uint32_t _get_rfid_card_uid();
|
||||
uint32_t _last_rfid_card_uid = 0;
|
||||
Player* _player;
|
||||
unsigned long _last_rfid_scan_at = 0;
|
||||
public:
|
||||
|
@ -21,16 +21,37 @@ void Controller::loop() {
|
||||
_check_serial();
|
||||
}
|
||||
|
||||
void Controller::_check_rfid() {
|
||||
uint32_t Controller::_get_rfid_card_uid() {
|
||||
SPIMaster::enable(PIN_RC522_CS);
|
||||
if (!_rfid->PICC_IsNewCardPresent()) {
|
||||
return;
|
||||
}
|
||||
if (!_rfid->PICC_ReadCardSerial()) {
|
||||
return;
|
||||
if (!_rfid->PICC_IsNewCardPresent()) {
|
||||
return 0;
|
||||
}
|
||||
if (!_rfid->PICC_ReadCardSerial()) {
|
||||
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();
|
||||
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() {
|
||||
|
@ -191,12 +191,12 @@ std::list<String> Player::_files_in_dir(String path) {
|
||||
while (entry = dir.openNextFile()) {
|
||||
String filename = entry.name();
|
||||
if (!entry.isDirectory() &&
|
||||
!filename.startsWith(".") &&
|
||||
!filename.startsWith(".") &&
|
||||
( filename.endsWith(".mp3") ||
|
||||
filename.endsWith(".ogg") ||
|
||||
filename.endsWith(".wma") ||
|
||||
filename.endsWith(".mp4") ||
|
||||
filename.endsWith(".mpa")) {
|
||||
filename.endsWith(".mpa"))) {
|
||||
//Serial.printf("Adding file %s\n", filename.c_str());
|
||||
result.push_back(path + filename);
|
||||
} else {
|
||||
@ -211,6 +211,7 @@ std::list<String> Player::_files_in_dir(String path) {
|
||||
}
|
||||
|
||||
bool Player::play_album(String album) {
|
||||
//if (_state==playing) stop();
|
||||
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);
|
||||
return play_song(album, s.index, s.position);
|
||||
@ -269,7 +270,7 @@ void Player::_play_file(String file, uint32_t file_offset) {
|
||||
Serial.println("Resetting SS_DO_NOT_JUMP...");
|
||||
_write_control_register(SCI_STATUS, _read_control_register(SCI_STATUS) & ~SS_DO_NOT_JUMP);
|
||||
delay(100);
|
||||
|
||||
|
||||
_refills = 0;
|
||||
_skip_to = file_offset;
|
||||
if (_skip_to>0) _mute();
|
||||
@ -358,7 +359,7 @@ void Player::_refill() {
|
||||
_finish_stopping();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_finish_stopping();
|
||||
bool result = play_song(_playing_album, _playing_index + 1);
|
||||
if (!result) {
|
||||
@ -387,8 +388,8 @@ void Player::_refill() {
|
||||
|
||||
bool Player::_refill_needed() {
|
||||
return _state==playing ||
|
||||
_state==stopping ||
|
||||
_state==system_sound_while_playing ||
|
||||
_state==stopping ||
|
||||
_state==system_sound_while_playing ||
|
||||
_state==system_sound_while_stopped;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user