diff --git a/device/main/AudioPlayer.cpp b/device/main/AudioPlayer.cpp index 5632e8c..ac24783 100644 --- a/device/main/AudioPlayer.cpp +++ b/device/main/AudioPlayer.cpp @@ -7,6 +7,8 @@ AudioPlayer::AudioPlayer() { playerHandle = setup_player(NULL, NULL); esp_player_init(playerHandle); + + esp_audio_vol_set(playerHandle, 10); } void AudioPlayer::play(char* uri) { diff --git a/device/main/CMakeLists.txt b/device/main/CMakeLists.txt index bdce93c..f4c64e0 100644 --- a/device/main/CMakeLists.txt +++ b/device/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "Networking.cpp" "main.cpp" "WebInterface.cpp" "RFIDInterface.cpp" "audio_setup.c" "AudioPlayer.cpp" +idf_component_register(SRCS "Networking.cpp" "main.cpp" "WebInterface.cpp" "RFIDInterface.cpp" "audio_setup.c" "AudioPlayer.cpp" "TagPlayerControl.cpp" INCLUDE_DIRS ".") diff --git a/device/main/RFIDInterface.cpp b/device/main/RFIDInterface.cpp index 97d4b83..59b3875 100644 --- a/device/main/RFIDInterface.cpp +++ b/device/main/RFIDInterface.cpp @@ -19,10 +19,10 @@ static char* getLastTagId() { RFIDInterface::RFIDInterface() { startConfig = (rc522_start_args_t){ - .miso_io = 26, - .mosi_io = 25, + .miso_io = 12, + .mosi_io = 13, .sck_io = 23, - .sda_io = 5, + .sda_io = 18, .callback = [](uint8_t* sn) { // serial number is always 5 bytes long ESP_LOGI(TAG, "Tag: %#x %#x %#x %#x %#x", sn[0], sn[1], sn[2], sn[3], sn[4] diff --git a/device/main/TagPlayerControl.cpp b/device/main/TagPlayerControl.cpp new file mode 100644 index 0000000..0f42ba9 --- /dev/null +++ b/device/main/TagPlayerControl.cpp @@ -0,0 +1,52 @@ +#include "TagPlayerControl.hpp" + +#include "AudioPlayer.hpp" + +#include +#include +#include + +#include + +static const char* TAG = "TagPlayerControl"; + +TagPlayerControl::TagPlayerControl(AudioPlayer* player) { + audioPlayer = player; +} + +void TagPlayerControl::onTagChanged(char* tagId) { + std::string filePath = "/sdcard/internal/"; + filePath.append(tagId); + + std::fstream file(filePath); + + if (! file) { + ESP_LOGE(TAG, "Error opening file for tag %s", tagId); + + char* error_name; + + switch (errno) + { + case EACCES: + ESP_LOGE(TAG, "EACCESS"); + break; + case ENOENT: + ESP_LOGE(TAG, "ENOENT"); + break; + default: + ESP_LOGE(TAG, "not parsed"); + } + return; + } + + std::string line; + std::string content; + + while(getline(file, line)) { + content.append(line); + } + + audioPlayer->play((char*)(content.c_str())); + + file.close(); +} \ No newline at end of file diff --git a/device/main/TagPlayerControl.hpp b/device/main/TagPlayerControl.hpp new file mode 100644 index 0000000..a23ff78 --- /dev/null +++ b/device/main/TagPlayerControl.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "AudioPlayer.hpp" + +class TagPlayerControl { + AudioPlayer* audioPlayer; + + public: + TagPlayerControl(AudioPlayer* player); + void onTagChanged(char* tagId); +}; \ No newline at end of file diff --git a/device/main/WebInterface.cpp b/device/main/WebInterface.cpp index 0280563..e15a2db 100644 --- a/device/main/WebInterface.cpp +++ b/device/main/WebInterface.cpp @@ -40,7 +40,7 @@ void WebInterface::initSD() { esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg); // Initialize SD Card peripheral - if (audio_board_sdcard_init(set, SD_MODE_4_LINE) == ESP_FAIL) { + if (audio_board_sdcard_init(set, SD_MODE_1_LINE) == ESP_FAIL) { ESP_LOGE(TAG, "Sdcard not mounted"); } else { ESP_LOGI(TAG, "SDCard mounted"); diff --git a/device/main/WebInterface.hpp b/device/main/WebInterface.hpp index 7192fa2..a4acd53 100644 --- a/device/main/WebInterface.hpp +++ b/device/main/WebInterface.hpp @@ -11,9 +11,9 @@ class WebInterface { void start(); void finishResourceRegistrations(); void registerResource(httpd_uri_t* config); + void initSD(); private: - void initSD(); httpd_handle_t start_webserver(); void registerFileServer(); //esp_err_t hello_get_handler(httpd_req_t *req); diff --git a/device/main/main.cpp b/device/main/main.cpp index fe12280..64dd565 100644 --- a/device/main/main.cpp +++ b/device/main/main.cpp @@ -4,6 +4,9 @@ #include "WebInterface.hpp" #include "RFIDInterface.hpp" #include "AudioPlayer.hpp" +#include "TagPlayerControl.hpp" + +#include extern "C" { void app_main(); @@ -16,14 +19,21 @@ RFIDInterface rfid; void app_main(void) { initArduino(); - networking.connectWifi(); + webInterface.initSD(); + + /* networking.connectWifi(); webInterface.start(); rfid.registerWebResources(&webInterface); webInterface.finishResourceRegistrations(); - +*/ AudioPlayer audioPlayer; // initialize here, because the ctor does init stuff that fails when executed before `app_main()` - audioPlayer.play("file://sdcard/howcanwehangontoadream.mp3"); rfid.start(); + + TagPlayerControl tagPlayerControl(&audioPlayer); + + rfid.registerTagChangeCallback([&tagPlayerControl](char* tagId) { + tagPlayerControl.onTagChanged(tagId); + }); }