to colorize a colorful pixel with a simple touch using nfc technology
Dependencies: Chainable_RGB_LED mbed
use Arch, NFC Shield and Grove - Chainable RGB LED to DIY a touch pixel. Then use an Android with NFC support to colorize it.
The project is on https://github.com/Seeed-Studio/TouchPixel
Diff: nfc/NfcTag.cpp
- Revision:
- 0:88960f3eeb2c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nfc/NfcTag.cpp Fri Dec 27 01:46:32 2013 +0000 @@ -0,0 +1,127 @@ +#include <NfcTag.h> +#include <string.h> +#include <PN532_debug.h> + +NfcTag::NfcTag() +{ + _uid = 0; + _uidLength = 0; + _tagType = "Unknown"; + _ndefMessage = (NdefMessage*)NULL; +} + +NfcTag::NfcTag(uint8_t *uid, unsigned int uidLength) +{ + _uid = uid; + _uidLength = uidLength; + _tagType = "Unknown"; + _ndefMessage = (NdefMessage*)NULL; +} + +NfcTag::NfcTag(uint8_t *uid, unsigned int uidLength, string tagType) +{ + _uid = uid; + _uidLength = uidLength; + _tagType = tagType; + _ndefMessage = (NdefMessage*)NULL; +} + +NfcTag::NfcTag(uint8_t *uid, unsigned int uidLength, string tagType, NdefMessage& ndefMessage) +{ + _uid = uid; + _uidLength = uidLength; + _tagType = tagType; + _ndefMessage = new NdefMessage(ndefMessage); +} + +// I don't like this version, but it will use less memory +NfcTag::NfcTag(uint8_t *uid, unsigned int uidLength, string tagType, const uint8_t *ndefData, const int ndefDataLength) +{ + _uid = uid; + _uidLength = uidLength; + _tagType = tagType; + _ndefMessage = new NdefMessage(ndefData, ndefDataLength); +} + +NfcTag::~NfcTag() +{ + delete _ndefMessage; +} + +NfcTag& NfcTag::operator=(const NfcTag& rhs) +{ + if (this != &rhs) + { + delete _ndefMessage; + _uid = rhs._uid; + _uidLength = rhs._uidLength; + _tagType = rhs._tagType; + // TODO do I need a copy here? + _ndefMessage = rhs._ndefMessage; + } + return *this; +} + +uint8_t NfcTag::getUidLength() +{ + return _uidLength; +} + +void NfcTag::getUid(uint8_t *uid, unsigned int uidLength) +{ + memcpy(_uid, uid, uidLength); +} + +string NfcTag::getUidString() +{ + string uidString = ""; +#if 0 + for (int i = 0; i < _uidLength; i++) + { + if (i > 0) + { + uidString += " "; + } + + if (_uid[i] < 0xF) + { + uidString += "0"; + } + + uidString += string((unsigned int)_uid[i], 16); + } + uidString.toUpperCase(); +#endif + return uidString; +} + +string NfcTag::getTagType() +{ + return _tagType; +} + +bool NfcTag::hasNdefMessage() +{ + return (_ndefMessage != NULL); +} + +NdefMessage NfcTag::getNdefMessage() +{ + return *_ndefMessage; +} + +void NfcTag::print() +{ + DMSG("NFC Tag - "); + DMSG_INT(_tagType); + DMSG("UID - "); + DMSG(getUidString().c_str()); + if (_ndefMessage == NULL) + { + DMSG("\nNo NDEF Message"); + } + else + { + _ndefMessage->print(); + } +}