@ -8,6 +8,7 @@
# include "Queues.h"
# include "System.h"
# include "Port.h"
# include "AudioPlayer.h"
# ifdef RFID_READER_TYPE_PN5180
# include <PN5180.h>
@ -52,6 +53,12 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
static PN5180ISO15693 nfc15693 ( RFID_CS , RFID_BUSY , RFID_RST ) ;
static uint32_t lastTimeDetected14443 = 0 ;
static uint32_t lastTimeDetected15693 = 0 ;
# ifdef PAUSE_WHEN_RFID_REMOVED
static byte lastValidcardId [ cardIdSize ] ;
static bool cardAppliedCurrentRun = false ;
static bool cardAppliedLastRun = false ;
bool sameCardReapplied = false ;
# endif
static uint8_t stateMachine = RFID_PN5180_STATE_INIT ;
static byte cardId [ cardIdSize ] , lastCardId [ cardIdSize ] ;
uint8_t uid [ 10 ] ;
@ -83,13 +90,18 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
cardReceived = true ;
stateMachine = RFID_PN5180_NFC14443_STATE_ACTIVE ;
lastTimeDetected14443 = millis ( ) ;
//Serial.println("14443");
# ifdef PAUSE_WHEN_RFID_REMOVED
cardAppliedCurrentRun = true ;
# endif
} else {
// Reset to dummy-value if no card is there
// Necessary to differentiate between "card is still applied" and "card is re-applied again after removal"
// lastTimeDetected14443 is used to prevent "new card detection with old card" with single events where no card was detected
if ( ! lastTimeDetected14443 | | ( millis ( ) - lastTimeDetected14443 > = 400 ) ) {
lastTimeDetected14443 = 0 ;
# ifdef PAUSE_WHEN_RFID_REMOVED
cardAppliedCurrentRun = false ;
# endif
for ( uint8_t i = 0 ; i < cardIdSize ; i + + ) {
lastCardId [ i ] = 0 ;
}
@ -119,11 +131,16 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
cardReceived = true ;
stateMachine = RFID_PN5180_NFC15693_STATE_ACTIVE ;
lastTimeDetected15693 = millis ( ) ;
//Serial.println("15693");
# ifdef PAUSE_WHEN_RFID_REMOVED
cardAppliedCurrentRun = true ;
# endif
} else {
// lastTimeDetected15693 is used to prevent "new card detection with old card" with single events where no card was detected
if ( ! lastTimeDetected15693 | | ( millis ( ) - lastTimeDetected15693 > = 400 ) ) {
lastTimeDetected15693 = 0 ;
# ifdef PAUSE_WHEN_RFID_REMOVED
cardAppliedCurrentRun = false ;
# endif
for ( uint8_t i = 0 ; i < cardIdSize ; i + + ) {
lastCardId [ i ] = 0 ;
}
@ -133,6 +150,13 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
}
}
# ifdef PAUSE_WHEN_RFID_REMOVED
if ( ! cardAppliedCurrentRun & & cardAppliedLastRun & & ! gPlayProperties . pausePlay ) { // Card removed => pause
AudioPlayer_TrackControlToQueueSender ( PAUSEPLAY ) ;
}
cardAppliedLastRun = cardAppliedCurrentRun ;
# endif
// send card to queue
if ( cardReceived ) {
memcpy ( cardId , uid , cardIdSize ) ;
@ -151,6 +175,12 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
memcpy ( lastCardId , cardId , cardIdSize ) ;
# ifdef PAUSE_WHEN_RFID_REMOVED
if ( memcmp ( ( const void * ) lastValidcardId , ( const void * ) cardId , sizeof ( cardId ) ) = = 0 ) {
sameCardReapplied = true ;
}
# endif
Log_Print ( ( char * ) FPSTR ( rfidTagDetected ) , LOGLEVEL_NOTICE ) ;
snprintf ( Log_Buffer , Log_BufferLength , " (%s) ID: " , ( RFID_PN5180_NFC14443_STATE_ACTIVE = = stateMachine ) ? " ISO-14443 " : " ISO-15693 " ) ;
Log_Print ( Log_Buffer , LOGLEVEL_NOTICE ) ;
@ -166,7 +196,19 @@ extern unsigned long Rfid_LastRfidCheckTimestamp;
cardIdString + = num ;
}
# ifdef PAUSE_WHEN_RFID_REMOVED
if ( ! sameCardReapplied ) { // Don't allow to send card to queue if it's the same card again...
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 ) {
AudioPlayer_TrackControlToQueueSender ( PAUSEPLAY ) ; // ... play/pause instead
}
}
memcpy ( lastValidcardId , uid , cardIdSize ) ;
# else
xQueueSend ( gRfidCardQueue , cardIdString . c_str ( ) , 0 ) ; // If PAUSE_WHEN_RFID_REMOVED isn't active, every card-apply leads to new playlist-generation
# endif
}
if ( stateMachine = = RFID_PN5180_NFC14443_STATE_ACTIVE ) { // If 14443 is active, bypass 15693 as next check (performance)