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/llcp.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 | #ifndef __LLCP_H__ |
yihui | 0:88960f3eeb2c | 3 | #define __LLCP_H__ |
yihui | 0:88960f3eeb2c | 4 | |
yihui | 0:88960f3eeb2c | 5 | #include "mac_link.h" |
yihui | 0:88960f3eeb2c | 6 | |
yihui | 0:88960f3eeb2c | 7 | #define LLCP_DEFAULT_TIMEOUT 20000 |
yihui | 0:88960f3eeb2c | 8 | #define LLCP_DEFAULT_DSAP 0x04 |
yihui | 0:88960f3eeb2c | 9 | #define LLCP_DEFAULT_SSAP 0x20 |
yihui | 0:88960f3eeb2c | 10 | |
yihui | 0:88960f3eeb2c | 11 | class LLCP { |
yihui | 0:88960f3eeb2c | 12 | public: |
yihui | 0:88960f3eeb2c | 13 | LLCP(PN532Interface &interface) : link(interface) { |
yihui | 0:88960f3eeb2c | 14 | headerBuf = link.getHeaderBuffer(&headerBufLen); |
yihui | 0:88960f3eeb2c | 15 | ns = 0; |
yihui | 0:88960f3eeb2c | 16 | nr = 0; |
yihui | 0:88960f3eeb2c | 17 | }; |
yihui | 0:88960f3eeb2c | 18 | |
yihui | 0:88960f3eeb2c | 19 | /** |
yihui | 0:88960f3eeb2c | 20 | * @brief Actiave PN532 as a target |
yihui | 0:88960f3eeb2c | 21 | * @param timeout max time to wait, 0 means no timeout |
yihui | 0:88960f3eeb2c | 22 | * @return > 0 success |
yihui | 0:88960f3eeb2c | 23 | * = 0 timeout |
yihui | 0:88960f3eeb2c | 24 | * < 0 failed |
yihui | 0:88960f3eeb2c | 25 | */ |
yihui | 0:88960f3eeb2c | 26 | int8_t activate(uint16_t timeout = 0); |
yihui | 0:88960f3eeb2c | 27 | |
yihui | 0:88960f3eeb2c | 28 | int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 0:88960f3eeb2c | 29 | |
yihui | 0:88960f3eeb2c | 30 | int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 0:88960f3eeb2c | 31 | |
yihui | 0:88960f3eeb2c | 32 | int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 0:88960f3eeb2c | 33 | |
yihui | 0:88960f3eeb2c | 34 | int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 0:88960f3eeb2c | 35 | |
yihui | 0:88960f3eeb2c | 36 | /** |
yihui | 0:88960f3eeb2c | 37 | * @brief write a packet, the packet should be less than (255 - 2) bytes |
yihui | 0:88960f3eeb2c | 38 | * @param header packet header |
yihui | 0:88960f3eeb2c | 39 | * @param hlen length of header |
yihui | 0:88960f3eeb2c | 40 | * @param body packet body |
yihui | 0:88960f3eeb2c | 41 | * @param blen length of body |
yihui | 0:88960f3eeb2c | 42 | * @return true success |
yihui | 0:88960f3eeb2c | 43 | * false failed |
yihui | 0:88960f3eeb2c | 44 | */ |
yihui | 0:88960f3eeb2c | 45 | bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0); |
yihui | 0:88960f3eeb2c | 46 | |
yihui | 0:88960f3eeb2c | 47 | /** |
yihui | 0:88960f3eeb2c | 48 | * @brief read a packet, the packet will be less than (255 - 2) bytes |
yihui | 0:88960f3eeb2c | 49 | * @param buf the buffer to contain the packet |
yihui | 0:88960f3eeb2c | 50 | * @param len lenght of the buffer |
yihui | 0:88960f3eeb2c | 51 | * @return >=0 length of the packet |
yihui | 0:88960f3eeb2c | 52 | * <0 failed |
yihui | 0:88960f3eeb2c | 53 | */ |
yihui | 0:88960f3eeb2c | 54 | int16_t read(uint8_t *buf, uint8_t len); |
yihui | 0:88960f3eeb2c | 55 | |
yihui | 0:88960f3eeb2c | 56 | uint8_t *getHeaderBuffer(uint8_t *len) { |
yihui | 0:88960f3eeb2c | 57 | uint8_t *buf = link.getHeaderBuffer(len); |
yihui | 0:88960f3eeb2c | 58 | len -= 3; // I PDU header has 3 bytes |
yihui | 0:88960f3eeb2c | 59 | return buf; |
yihui | 0:88960f3eeb2c | 60 | }; |
yihui | 0:88960f3eeb2c | 61 | |
yihui | 0:88960f3eeb2c | 62 | private: |
yihui | 0:88960f3eeb2c | 63 | MACLink link; |
yihui | 0:88960f3eeb2c | 64 | uint8_t mode; |
yihui | 0:88960f3eeb2c | 65 | uint8_t ssap; |
yihui | 0:88960f3eeb2c | 66 | uint8_t dsap; |
yihui | 0:88960f3eeb2c | 67 | uint8_t *headerBuf; |
yihui | 0:88960f3eeb2c | 68 | uint8_t headerBufLen; |
yihui | 0:88960f3eeb2c | 69 | uint8_t ns; // Number of I PDU Sent |
yihui | 0:88960f3eeb2c | 70 | uint8_t nr; // Number of I PDU Received |
yihui | 0:88960f3eeb2c | 71 | |
yihui | 0:88960f3eeb2c | 72 | static uint8_t SYMM_PDU[2]; |
yihui | 0:88960f3eeb2c | 73 | }; |
yihui | 0:88960f3eeb2c | 74 | |
yihui | 0:88960f3eeb2c | 75 | #endif // __LLCP_H__ |