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
nfc/emulatetag.h@0:88960f3eeb2c, 2013-12-27 (annotated)
- Committer:
- yihui
- Date:
- Fri Dec 27 01:46:32 2013 +0000
- Revision:
- 0:88960f3eeb2c
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:88960f3eeb2c | 1 | /**************************************************************************/ |
yihui | 0:88960f3eeb2c | 2 | /*! |
yihui | 0:88960f3eeb2c | 3 | @file emulatetag.h |
yihui | 0:88960f3eeb2c | 4 | @author Armin Wieser |
yihui | 0:88960f3eeb2c | 5 | @license BSD |
yihui | 0:88960f3eeb2c | 6 | |
yihui | 0:88960f3eeb2c | 7 | Implemented using NFC forum documents & library of libnfc |
yihui | 0:88960f3eeb2c | 8 | */ |
yihui | 0:88960f3eeb2c | 9 | /**************************************************************************/ |
yihui | 0:88960f3eeb2c | 10 | |
yihui | 0:88960f3eeb2c | 11 | #ifndef __EMULATETAG_H__ |
yihui | 0:88960f3eeb2c | 12 | #define __EMULATETAG_H__ |
yihui | 0:88960f3eeb2c | 13 | |
yihui | 0:88960f3eeb2c | 14 | #include "PN532.h" |
yihui | 0:88960f3eeb2c | 15 | |
yihui | 0:88960f3eeb2c | 16 | #define NDEF_MAX_LENGTH 128 // altough ndef can handle up to 0xfffe in size, arduino cannot. |
yihui | 0:88960f3eeb2c | 17 | typedef enum {COMMAND_COMPLETE, TAG_NOT_FOUND, FUNCTION_NOT_SUPPORTED, MEMORY_FAILURE, END_OF_FILE_BEFORE_REACHED_LE_BYTES} responseCommand; |
yihui | 0:88960f3eeb2c | 18 | |
yihui | 0:88960f3eeb2c | 19 | class EmulateTag{ |
yihui | 0:88960f3eeb2c | 20 | |
yihui | 0:88960f3eeb2c | 21 | public: |
yihui | 0:88960f3eeb2c | 22 | EmulateTag(PN532Interface &interface) : pn532(interface), uidPtr(0), tagWrittenByInitiator(false), tagWriteable(true), updateNdefCallback(0) { } |
yihui | 0:88960f3eeb2c | 23 | |
yihui | 0:88960f3eeb2c | 24 | bool init(); |
yihui | 0:88960f3eeb2c | 25 | |
yihui | 0:88960f3eeb2c | 26 | bool emulate(const uint16_t tgInitAsTargetTimeout = 0); |
yihui | 0:88960f3eeb2c | 27 | |
yihui | 0:88960f3eeb2c | 28 | /* |
yihui | 0:88960f3eeb2c | 29 | * @param uid pointer to byte array of length 3 (uid is 4 bytes - first byte is fixed) or zero for uid |
yihui | 0:88960f3eeb2c | 30 | */ |
yihui | 0:88960f3eeb2c | 31 | void setUid(uint8_t* uid = 0); |
yihui | 0:88960f3eeb2c | 32 | |
yihui | 0:88960f3eeb2c | 33 | void setNdefFile(const uint8_t* ndef, const int16_t ndefLength); |
yihui | 0:88960f3eeb2c | 34 | |
yihui | 0:88960f3eeb2c | 35 | void getContent(uint8_t** buf, uint16_t* length){ |
yihui | 0:88960f3eeb2c | 36 | *buf = ndef_file + 2; // first 2 bytes = length |
yihui | 0:88960f3eeb2c | 37 | *length = (ndef_file[0] << 8) + ndef_file[1]; |
yihui | 0:88960f3eeb2c | 38 | } |
yihui | 0:88960f3eeb2c | 39 | |
yihui | 0:88960f3eeb2c | 40 | bool writeOccured(){ |
yihui | 0:88960f3eeb2c | 41 | return tagWrittenByInitiator; |
yihui | 0:88960f3eeb2c | 42 | } |
yihui | 0:88960f3eeb2c | 43 | |
yihui | 0:88960f3eeb2c | 44 | void setTagWriteable(bool setWriteable){ |
yihui | 0:88960f3eeb2c | 45 | tagWriteable = setWriteable; |
yihui | 0:88960f3eeb2c | 46 | } |
yihui | 0:88960f3eeb2c | 47 | |
yihui | 0:88960f3eeb2c | 48 | uint8_t* getNdefFilePtr(){ |
yihui | 0:88960f3eeb2c | 49 | return ndef_file; |
yihui | 0:88960f3eeb2c | 50 | } |
yihui | 0:88960f3eeb2c | 51 | |
yihui | 0:88960f3eeb2c | 52 | uint8_t getNdefMaxLength(){ |
yihui | 0:88960f3eeb2c | 53 | return NDEF_MAX_LENGTH; |
yihui | 0:88960f3eeb2c | 54 | } |
yihui | 0:88960f3eeb2c | 55 | |
yihui | 0:88960f3eeb2c | 56 | void attach(void (*func)(uint8_t *buf, uint16_t length)) { |
yihui | 0:88960f3eeb2c | 57 | updateNdefCallback = func; |
yihui | 0:88960f3eeb2c | 58 | }; |
yihui | 0:88960f3eeb2c | 59 | |
yihui | 0:88960f3eeb2c | 60 | private: |
yihui | 0:88960f3eeb2c | 61 | PN532 pn532; |
yihui | 0:88960f3eeb2c | 62 | uint8_t ndef_file[NDEF_MAX_LENGTH]; |
yihui | 0:88960f3eeb2c | 63 | uint8_t* uidPtr; |
yihui | 0:88960f3eeb2c | 64 | bool tagWrittenByInitiator; |
yihui | 0:88960f3eeb2c | 65 | bool tagWriteable; |
yihui | 0:88960f3eeb2c | 66 | void (*updateNdefCallback)(uint8_t *ndef, uint16_t length); |
yihui | 0:88960f3eeb2c | 67 | |
yihui | 0:88960f3eeb2c | 68 | void setResponse(responseCommand cmd, uint8_t* buf, uint8_t* sendlen, uint8_t sendlenOffset = 0); |
yihui | 0:88960f3eeb2c | 69 | }; |
yihui | 0:88960f3eeb2c | 70 | |
yihui | 0:88960f3eeb2c | 71 | #endif |