ID12RFID library, quickly modified to use interrupt driven reception instead so it doesn\'t block

Dependents:   m3pi_WiiRacing m3pi_RFIDReader

Committer:
simon
Date:
Mon Apr 11 23:02:00 2011 +0000
Revision:
0:a740ea2424e5

        

Who changed what in which revision?

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