|
|
@ -255,7 +255,9 @@ AsyncEventSource events("/events"); |
|
|
|
#endif
|
|
|
|
|
|
|
|
TaskHandle_t mp3Play; |
|
|
|
TaskHandle_t rfid; |
|
|
|
#ifdef RFID_READER_TYPE_PN5180
|
|
|
|
TaskHandle_t rfid; |
|
|
|
#endif
|
|
|
|
TaskHandle_t fileStorageTaskHandle; |
|
|
|
|
|
|
|
#ifdef NEOPIXEL_ENABLE
|
|
|
@ -420,7 +422,11 @@ bool processJsonRequest(char *_serialJson); |
|
|
|
void randomizePlaylist (char *str[], const uint32_t count); |
|
|
|
char ** returnPlaylistFromWebstream(const char *_webUrl); |
|
|
|
char ** returnPlaylistFromSD(File _fileOrDirectory); |
|
|
|
void rfidScanner(void *parameter); |
|
|
|
#ifdef RFID_READER_TYPE_PN5180
|
|
|
|
void rfidScanner(void *parameter); |
|
|
|
#else
|
|
|
|
void rfidScanner(void); |
|
|
|
#endif
|
|
|
|
void sleepHandler(void) ; |
|
|
|
void sortPlaylist(const char** arr, int n); |
|
|
|
bool startsWith(const char *str, const char *pre); |
|
|
@ -1433,6 +1439,7 @@ size_t nvsRfidWriteWrapper (const char *_rfidCardId, const char *_track, const u |
|
|
|
// Function to play music as task
|
|
|
|
void playAudio(void *parameter) { |
|
|
|
static Audio audio; |
|
|
|
uint8_t settleCount = 0; |
|
|
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); |
|
|
|
audio.setVolume(initVolume); |
|
|
|
audio.forceMono(playProperties.currentPlayMono); |
|
|
@ -1848,11 +1855,6 @@ void playAudio(void *parameter) { |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
// If error occured: remove playlist from ESPuino
|
|
|
|
if ((playProperties.playMode != NO_PLAYLIST) && !audio.isRunning() && !playProperties.pausePlay) { |
|
|
|
playProperties.trackFinished = true; |
|
|
|
} |
|
|
|
|
|
|
|
audio.loop(); |
|
|
|
if (playProperties.playlistFinished || playProperties.pausePlay) { |
|
|
|
vTaskDelay(portTICK_PERIOD_MS*10); // Waste some time if playlist is not active
|
|
|
@ -1860,6 +1862,19 @@ void playAudio(void *parameter) { |
|
|
|
lastTimeActiveTimestamp = millis(); // Refresh if playlist is active so uC will not fall asleep due to reaching inactivity-time
|
|
|
|
} |
|
|
|
|
|
|
|
if (audio.isRunning()) { |
|
|
|
settleCount = 0; |
|
|
|
} |
|
|
|
|
|
|
|
// If error occured: remove playlist from ESPuino
|
|
|
|
if (playProperties.playMode != NO_PLAYLIST && playProperties.playMode != BUSY && !audio.isRunning() && !playProperties.pausePlay) { |
|
|
|
if (settleCount++ == 50) { // Hack to give audio some time to settle down after playlist was generated
|
|
|
|
playProperties.playlistFinished = true; |
|
|
|
playProperties.playMode = NO_PLAYLIST; |
|
|
|
settleCount = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
esp_task_wdt_reset(); // Don't forget to feed the dog!
|
|
|
|
} |
|
|
|
vTaskDelete(NULL); |
|
|
@ -1867,25 +1882,22 @@ void playAudio(void *parameter) { |
|
|
|
|
|
|
|
|
|
|
|
#if defined RFID_READER_TYPE_MFRC522_SPI || defined RFID_READER_TYPE_MFRC522_I2C
|
|
|
|
// Instructs RFID-scanner to scan for new RFID-tags
|
|
|
|
void rfidScanner(void *parameter) { |
|
|
|
// Instructs RFID-scanner to scan for new RFID-tags using RC522 (running as function)
|
|
|
|
void rfidScanner(void) { |
|
|
|
byte cardId[cardIdSize]; |
|
|
|
char *cardIdString; |
|
|
|
|
|
|
|
for (;;) { |
|
|
|
esp_task_wdt_reset(); |
|
|
|
vTaskDelay(10); |
|
|
|
if ((millis() - lastRfidCheckTimestamp) >= RFID_SCAN_INTERVAL) { |
|
|
|
lastRfidCheckTimestamp = millis(); |
|
|
|
// Reset the loop if no new card is present on the sensor/reader. This saves the entire process when idle.
|
|
|
|
|
|
|
|
if (!mfrc522.PICC_IsNewCardPresent()) { |
|
|
|
continue; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Select one of the cards
|
|
|
|
if (!mfrc522.PICC_ReadCardSerial()) { |
|
|
|
continue; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
|
|
|
@ -1903,7 +1915,7 @@ void rfidScanner(void *parameter) { |
|
|
|
#ifdef NEOPIXEL_ENABLE
|
|
|
|
showLedError = true; |
|
|
|
#endif
|
|
|
|
continue; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t n = 0; |
|
|
@ -1922,17 +1934,14 @@ void rfidScanner(void *parameter) { |
|
|
|
} |
|
|
|
} |
|
|
|
xQueueSend(rfidCardQueue, &cardIdString, 0); |
|
|
|
// free(cardIdString);
|
|
|
|
} |
|
|
|
} |
|
|
|
vTaskDelete(NULL); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef RFID_READER_TYPE_PN5180
|
|
|
|
// Instructs RFID-scanner to scan for new RFID-tags using PN5180
|
|
|
|
// Instructs RFID-scanner to scan for new RFID-tags using PN5180 (running as task)
|
|
|
|
// Runs as task (instead of function) because it takes about 230 ms (IDLE) and 500 ms (non-IDLE)
|
|
|
|
void rfidScanner(void *parameter) { |
|
|
|
static PN5180ISO14443 nfc14443(RFID_CS, RFID_BUSY, RFID_RST); |
|
|
|
static PN5180ISO15693 nfc15693(RFID_CS, RFID_BUSY, RFID_RST); |
|
|
@ -4798,6 +4807,7 @@ void setup() { |
|
|
|
Serial.println(F(" | |___ ___) | | __/ | |_| | | | | | | | | (_) |")); |
|
|
|
Serial.println(F(" |_____| |____/ |_| \\__,_| |_| |_| |_| \\___/ ")); |
|
|
|
Serial.println(F(" Rfid-controlled musicplayer\n")); |
|
|
|
Serial.println(F(" Rev 20210402-1\n")); |
|
|
|
// print wake-up reason
|
|
|
|
printWakeUpReason(); |
|
|
|
#ifdef PN5180_ENABLE_LPCD
|
|
|
@ -5068,16 +5078,18 @@ void setup() { |
|
|
|
timerAlarmWrite(timer, 10000, true); // 100 Hz
|
|
|
|
timerAlarmEnable(timer); |
|
|
|
|
|
|
|
// Create tasks
|
|
|
|
#ifdef RFID_READER_TYPE_PN5180
|
|
|
|
// Create task for rfid
|
|
|
|
xTaskCreatePinnedToCore( |
|
|
|
rfidScanner, /* Function to implement the task */ |
|
|
|
"rfidhandling", /* Name of the task */ |
|
|
|
2000, /* Stack size in words */ |
|
|
|
1500, /* Stack size in words */ |
|
|
|
NULL, /* Task input parameter */ |
|
|
|
1, /* Priority of the task */ |
|
|
|
&rfid, /* Task handle. */ |
|
|
|
0 /* Core where the task should run */ |
|
|
|
); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Activate internal pullups for all enabled buttons
|
|
|
|
#ifdef BUTTON_0_ENABLE
|
|
|
@ -5171,6 +5183,9 @@ void bluetoothHandler(void) { |
|
|
|
#endif
|
|
|
|
|
|
|
|
void loop() { |
|
|
|
#ifndef RFID_READER_TYPE_PN5180
|
|
|
|
rfidScanner(); // PN5180 runs as task; RC522 as function
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BLUETOOTH_ENABLE
|
|
|
|
if(operationMode == OPMODE_BLUETOOTH) { |
|
|
|