Adds play/pause by tag support.

This commit is contained in:
Simon Weidacher
2021-12-26 14:00:30 +01:00
parent 5007de4456
commit 80321e8c6a
5 changed files with 31 additions and 9 deletions

View File

@@ -12,5 +12,10 @@ AudioPlayer::AudioPlayer() {
} }
void AudioPlayer::play(char* uri) { void AudioPlayer::play(char* uri) {
esp_player_music_stop();
esp_player_sdcard_music_play(uri, 0); esp_player_sdcard_music_play(uri, 0);
}
void AudioPlayer::pause() {
esp_player_music_pause();
} }

View File

@@ -6,4 +6,5 @@ class AudioPlayer {
public: public:
AudioPlayer(); AudioPlayer();
void play(char* uri); void play(char* uri);
void pause();
}; };

View File

@@ -23,17 +23,20 @@ RFIDInterface::RFIDInterface() {
.mosi_io = 13, .mosi_io = 13,
.sck_io = 23, .sck_io = 23,
.sda_io = 18, .sda_io = 18,
.callback = [](uint8_t* sn) { // serial number is always 5 bytes long .callback = [](uint8_t* sn) {
ESP_LOGI(TAG, "Tag: %#x %#x %#x %#x %#x", if (sn == NULL) {
sn[0], sn[1], sn[2], sn[3], sn[4] ESP_LOGI(TAG, "Tag removed");
);
sprintf(lastTagId, "%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]); if (callback) {
callback(NULL);
}
} else { // serial number is always 5 bytes long
sprintf(lastTagId, "%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]);
ESP_LOGI(TAG, "tag id: %s", lastTagId);
ESP_LOGI(TAG, "sprintf tag id: %s", lastTagId); if (callback) {
callback(getLastTagId());
if (callback) { }
callback(getLastTagId());
} }
} }
}; };

View File

@@ -15,6 +15,15 @@ TagPlayerControl::TagPlayerControl(AudioPlayer* player) {
} }
void TagPlayerControl::onTagChanged(char* tagId) { void TagPlayerControl::onTagChanged(char* tagId) {
if (tagId == NULL) {
// tag has been removed. stop playback
audioPlayer->pause();
} else {
playTag(tagId);
}
}
void TagPlayerControl::playTag(char* tagId) {
std::string filePath = "/sdcard/internal/"; std::string filePath = "/sdcard/internal/";
filePath.append(tagId); filePath.append(tagId);

View File

@@ -7,5 +7,9 @@ class TagPlayerControl {
public: public:
TagPlayerControl(AudioPlayer* player); TagPlayerControl(AudioPlayer* player);
void onTagChanged(char* tagId); void onTagChanged(char* tagId);
private:
void playTag(char* tagId);
}; };