Strooom / PN7150

Library/Driver for NXP PN7150 NFC device
Other
24 stars 24 forks source link

Added a getRWState #9

Closed DavidTruyens closed 4 years ago

DavidTruyens commented 4 years ago

Added this function: ReaderWriterState getRWState();

Which makes it possible to trigger events like a sound.

In this example I uses a charliewing from adafruit to test the behaviour:

void loop()
{
  theReaderWriter.run(); // give the application object some CPU time to do its job. This is a non-blocking function
  ReaderWriterState newState = theReaderWriter.getRWState();
  if (OldState != newState)
  {
    OldState = newState;
    switch (newState)
    {
    case ReaderWriterState::initializing:
      Serial.println("initializing");
      drawSad();
      break;
    case ReaderWriterState::singleTagPresent:
      Serial.println("single tag present");
      drawSmily();
      break;
    case ReaderWriterState::multipleTagsPresent:
      Serial.println("multiple tags present");
      drawSmily();
      break;
    case ReaderWriterState::noTagPresent:
      Serial.println("not tag present");
      drawNeutral();
      break;
    default:
      drawNeutral();
      Serial.println("exeption");
      break;
    }
  }
}
Strooom commented 4 years ago

Thanks David! I merged your pull request. I will make two changes to it :

  1. will rename to getState io. getRWState. As this is a member of readerWriter, it should be clear its this state being read.
  2. I will make the function const. Doing so makes sure that this function can only read stuff from readerWriter, but not change anything. It's just a small best practice for C++ (https://www.tutorialspoint.com/const-member-functions-in-cplusplus)