@ -8,6 +8,7 @@
# include "Queues.h"
# include "System.h"
# include "Port.h"
# include <esp_task_wdt.h>
# include "AudioPlayer.h"
# ifdef RFID_READER_TYPE_PN5180
@ -32,7 +33,7 @@
extern unsigned long Rfid_LastRfidCheckTimestamp ;
# ifdef RFID_READER_TYPE_PN5180
static void Rfid_Read ( void ) ;
static void Rfid_Task ( void * parameter ) ;
void Rfid_Init ( void ) {
# ifdef PN5180_ENABLE_LPCD
@ -42,29 +43,43 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
gpio_hold_dis ( gpio_num_t ( RFID_RST ) ) ; // RST
pinMode ( RFID_IRQ , INPUT ) ;
# endif
xTaskCreatePinnedToCore (
Rfid_Task , /* Function to implement the task */
" rfid " , /* Name of the task */
1536 , /* Stack size in words */
NULL , /* Task input parameter */
2 | portPRIVILEGE_BIT , /* Priority of the task */
NULL , /* Task handle. */
0 /* Core where the task should run */
) ;
}
void Rfid_Cyclic ( void ) {
Rfid_Read ( ) ;
vTaskDelay ( 5u ) ;
// Not necessary as cyclic stuff performed by task Rfid_Task()
}
void Rfid_Read ( void ) {
void Rfid_Task ( void * parameter ) {
static PN5180ISO14443 nfc14443 ( RFID_CS , RFID_BUSY , RFID_RST ) ;
static PN5180ISO15693 nfc15693 ( RFID_CS , RFID_BUSY , RFID_RST ) ;
static uint32_t lastTimeDetected14443 = 0 ;
static uint32_t lastTimeDetected15693 = 0 ;
uint32_t lastTimeDetected14443 = 0 ;
uint32_t lastTimeDetected15693 = 0 ;
# ifdef PAUSE_WHEN_RFID_REMOVED
static byte lastValidcardId [ cardIdSize ] ;
static bool cardAppliedCurrentRun = false ;
static bool cardAppliedLastRun = false ;
bool sameCardReapplied = false ;
byte lastValidcardId [ cardIdSize ] ;
bool cardAppliedCurrentRun = false ;
bool cardAppliedLastRun = false ;
# endif
static uint8_t stateMachine = RFID_PN5180_STATE_INIT ;
uint8_t stateMachine = RFID_PN5180_STATE_INIT ;
static byte cardId [ cardIdSize ] , lastCardId [ cardIdSize ] ;
uint8_t uid [ 10 ] ;
for ( ; ; ) {
vTaskDelay ( portTICK_RATE_MS * 10u ) ;
String cardIdString ;
bool cardReceived = false ;
# ifdef PAUSE_WHEN_RFID_REMOVED
bool sameCardReapplied = false ;
# endif
if ( RFID_PN5180_STATE_INIT = = stateMachine ) {
nfc14443 . begin ( ) ;
@ -84,6 +99,8 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
// 1. check for an ISO-14443 card
} else if ( RFID_PN5180_NFC14443_STATE_RESET = = stateMachine ) {
nfc14443 . reset ( ) ;
//snprintf(Log_Buffer, Log_BufferLength, "%u", uxTaskGetStackHighWaterMark(NULL));
//Log_Println(Log_Buffer, LOGLEVEL_DEBUG);
} else if ( RFID_PN5180_NFC14443_STATE_SETUPRF = = stateMachine ) {
nfc14443 . setupRF ( ) ;
} else if ( RFID_PN5180_NFC14443_STATE_READCARD = = stateMachine ) {
@ -152,8 +169,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
# ifdef PAUSE_WHEN_RFID_REMOVED
if ( ! cardAppliedCurrentRun & & cardAppliedLastRun & & ! gPlayProperties . pausePlay ) { // Card removed => pause
if ( ! cardAppliedCurrentRun & & cardAppliedLastRun & & ! gPlayProperties . pausePlay & & System_GetOperationMode ( ) ! = OPMODE_BLUETOOTH ) { // Card removed => pause
AudioPlayer_TrackControlToQueueSender ( PAUSEPLAY ) ;
Log_Println ( ( char * ) FPSTR ( rfidTagRemoved ) , LOGLEVEL_NOTICE ) ;
}
cardAppliedLastRun = cardAppliedCurrentRun ;
# endif
@ -167,10 +185,10 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
// reset state machine
if ( RFID_PN5180_NFC14443_STATE_ACTIVE = = stateMachine ) {
stateMachine = RFID_PN5180_NFC14443_STATE_RESET ;
return ;
continue ;
} else if ( RFID_PN5180_NFC15693_STATE_ACTIVE = = stateMachine ) {
stateMachine = RFID_PN5180_NFC15693_STATE_RESET ;
return ;
continue ;
}
}
@ -202,8 +220,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
xQueueSend ( gRfidCardQueue , cardIdString . c_str ( ) , 0 ) ;
} else {
// If pause-button was pressed while card was not applied, playback could be active. If so: don't pause when card is reapplied again as the desired functionality would be reversed in this case.
if ( gPlayProperties . pausePlay ) {
if ( gPlayProperties . pausePlay & & System_GetOperationMode ( ) ! = OPMODE_BLUETOOTH ) {
AudioPlayer_TrackControlToQueueSender ( PAUSEPLAY ) ; // ... play/pause instead
Log_Println ( ( char * ) FPSTR ( rfidTagReapplied ) , LOGLEVEL_NOTICE ) ;
}
}
memcpy ( lastValidcardId , uid , cardIdSize ) ;
@ -212,9 +231,9 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
# endif
}
if ( stateMachine = = RFID_PN5180_NFC14443_STATE_ACTIVE ) { // If 14443 is active, bypass 15693 as next check (performance)
if ( RFID_PN5180_NFC14443_STATE_ACTIVE = = stateMachine ) { // If 14443 is active, bypass 15693 as next check (performance)
stateMachine = RFID_PN5180_NFC14443_STATE_RESET ;
} else if ( stateMachine = = RFID_PN5180_NFC15693_STATE_ACTIVE ) { // If 15693 is active, bypass 14443 as next check (performance)
} else if ( RFID_PN5180_NFC15693_STATE_ACTIVE = = stateMachine ) { // If 15693 is active, bypass 14443 as next check (performance)
stateMachine = RFID_PN5180_NFC15693_STATE_RESET ;
} else {
stateMachine + + ;
@ -223,6 +242,7 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
}
}
}
void Rfid_Exit ( void ) {
// goto low power card detection mode
@ -292,5 +312,4 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
# endif
}
# endif