ID12RFID with interrupts
Fork of ID12RFID by
ID12RFID.h@2:b801dd21f6cc, 2014-12-03 (annotated)
- Committer:
- jnagendran3
- Date:
- Wed Dec 03 22:39:10 2014 +0000
- Revision:
- 2:b801dd21f6cc
- Parent:
- 1:f04afa911cf5
Additional code for generating interrupts.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:f04afa911cf5 | 1 | /* mbed ID12 RFID Library |
simon | 1:f04afa911cf5 | 2 | * Copyright (c) 2007-2010, sford, http://mbed.org |
simon | 1:f04afa911cf5 | 3 | * |
simon | 1:f04afa911cf5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 1:f04afa911cf5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
simon | 1:f04afa911cf5 | 6 | * in the Software without restriction, including without limitation the rights |
simon | 1:f04afa911cf5 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 1:f04afa911cf5 | 8 | * copies of the Software, and to permit persons to whom the Software is |
simon | 1:f04afa911cf5 | 9 | * furnished to do so, subject to the following conditions: |
simon | 1:f04afa911cf5 | 10 | * |
simon | 1:f04afa911cf5 | 11 | * The above copyright notice and this permission notice shall be included in |
simon | 1:f04afa911cf5 | 12 | * all copies or substantial portions of the Software. |
simon | 1:f04afa911cf5 | 13 | * |
simon | 1:f04afa911cf5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 1:f04afa911cf5 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 1:f04afa911cf5 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 1:f04afa911cf5 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 1:f04afa911cf5 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 1:f04afa911cf5 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 1:f04afa911cf5 | 20 | * THE SOFTWARE. |
simon | 1:f04afa911cf5 | 21 | */ |
simon | 1:f04afa911cf5 | 22 | |
simon | 1:f04afa911cf5 | 23 | #ifndef MBED_ID12RFID_H |
simon | 1:f04afa911cf5 | 24 | #define MBED_ID12RFID_H |
simon | 1:f04afa911cf5 | 25 | |
simon | 1:f04afa911cf5 | 26 | #include "mbed.h" |
simon | 1:f04afa911cf5 | 27 | |
simon | 1:f04afa911cf5 | 28 | /** An interface for the ID-12 RFID reader device |
simon | 1:f04afa911cf5 | 29 | * |
simon | 1:f04afa911cf5 | 30 | * @code |
simon | 1:f04afa911cf5 | 31 | * // Print RFID tag numbers |
simon | 1:f04afa911cf5 | 32 | * |
simon | 1:f04afa911cf5 | 33 | * #include "mbed.h" |
simon | 1:f04afa911cf5 | 34 | * #include "ID12RFID.h" |
simon | 1:f04afa911cf5 | 35 | * |
simon | 1:f04afa911cf5 | 36 | * ID12RFID rfid(p10); // serial rx |
simon | 1:f04afa911cf5 | 37 | * |
simon | 1:f04afa911cf5 | 38 | * int main() { |
simon | 1:f04afa911cf5 | 39 | * while(1) { |
simon | 1:f04afa911cf5 | 40 | * if(rfid.readable()) { |
simon | 1:f04afa911cf5 | 41 | * printf("RFID Tag number : %d\n", rfid.read()); |
simon | 1:f04afa911cf5 | 42 | * } |
simon | 1:f04afa911cf5 | 43 | * } |
simon | 1:f04afa911cf5 | 44 | * } |
simon | 1:f04afa911cf5 | 45 | * @endcode |
simon | 1:f04afa911cf5 | 46 | */ |
simon | 1:f04afa911cf5 | 47 | class ID12RFID { |
simon | 1:f04afa911cf5 | 48 | |
simon | 1:f04afa911cf5 | 49 | public: |
simon | 1:f04afa911cf5 | 50 | /** Create an ID12 RFID interface, connected to the specified Serial rx port |
simon | 1:f04afa911cf5 | 51 | * |
simon | 1:f04afa911cf5 | 52 | * @param rx Recieve pin |
simon | 1:f04afa911cf5 | 53 | */ |
simon | 1:f04afa911cf5 | 54 | ID12RFID(PinName rx); |
simon | 1:f04afa911cf5 | 55 | |
simon | 1:f04afa911cf5 | 56 | /** Non blocking function to determine if an ID has been received |
simon | 1:f04afa911cf5 | 57 | * |
simon | 1:f04afa911cf5 | 58 | * @return Non zero value when the device is readable |
simon | 1:f04afa911cf5 | 59 | */ |
simon | 1:f04afa911cf5 | 60 | int readable(); |
simon | 1:f04afa911cf5 | 61 | |
simon | 1:f04afa911cf5 | 62 | /** A blocking function that will return a tag ID when available |
simon | 1:f04afa911cf5 | 63 | * |
simon | 1:f04afa911cf5 | 64 | * @return The ID tag value |
simon | 1:f04afa911cf5 | 65 | */ |
simon | 1:f04afa911cf5 | 66 | int read(); |
jnagendran3 | 2:b801dd21f6cc | 67 | |
jnagendran3 | 2:b801dd21f6cc | 68 | void setInterrupt(void (fptr)()); |
simon | 1:f04afa911cf5 | 69 | |
simon | 1:f04afa911cf5 | 70 | private: |
simon | 1:f04afa911cf5 | 71 | Serial _rfid; |
simon | 1:f04afa911cf5 | 72 | |
simon | 1:f04afa911cf5 | 73 | }; |
simon | 1:f04afa911cf5 | 74 | |
simon | 1:f04afa911cf5 | 75 | #endif |