Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:26991d042db7, 2019-04-28 (annotated)
- Committer:
- goymame
- Date:
- Sun Apr 28 00:06:13 2019 +0000
- Revision:
- 1:26991d042db7
- Parent:
- 0:bf6b79d0e255
- Child:
- 2:42f8f6b183ae
first commit;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| goymame | 1:26991d042db7 | 1 | /* mbed Wiegand Library |
| goymame | 1:26991d042db7 | 2 | * Copyright (c) 2017-2019, Gregorio Marquez |
| goymame | 1:26991d042db7 | 3 | * |
| goymame | 1:26991d042db7 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| goymame | 1:26991d042db7 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| goymame | 1:26991d042db7 | 6 | * in the Software without restriction, including without limitation the rights |
| goymame | 1:26991d042db7 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| goymame | 1:26991d042db7 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| goymame | 1:26991d042db7 | 9 | * furnished to do so, subject to the following conditions: |
| goymame | 1:26991d042db7 | 10 | * |
| goymame | 1:26991d042db7 | 11 | * The above copyright notice and this permission notice shall be included in |
| goymame | 1:26991d042db7 | 12 | * all copies or substantial portions of the Software. |
| goymame | 1:26991d042db7 | 13 | * |
| goymame | 1:26991d042db7 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| goymame | 1:26991d042db7 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| goymame | 1:26991d042db7 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| goymame | 1:26991d042db7 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| goymame | 1:26991d042db7 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| goymame | 1:26991d042db7 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| goymame | 1:26991d042db7 | 20 | * THE SOFTWARE. |
| goymame | 1:26991d042db7 | 21 | */ |
| goymame | 1:26991d042db7 | 22 | |
| goymame | 0:bf6b79d0e255 | 23 | #include "mbed.h" |
| goymame | 0:bf6b79d0e255 | 24 | #include "wiegand.h" |
| goymame | 0:bf6b79d0e255 | 25 | |
| goymame | 0:bf6b79d0e255 | 26 | RawSerial serial(USBTX, USBRX); |
| goymame | 0:bf6b79d0e255 | 27 | Thread wiegandThread; |
| goymame | 0:bf6b79d0e255 | 28 | EventQueue* wiegandQueue = new EventQueue (64 * EVENTS_EVENT_SIZE); |
| goymame | 0:bf6b79d0e255 | 29 | |
| goymame | 0:bf6b79d0e255 | 30 | void onTag(void); |
| goymame | 0:bf6b79d0e255 | 31 | |
| goymame | 0:bf6b79d0e255 | 32 | Wiegand wiegandReader(PE_13, PF_15, wiegandQueue, &onTag, 32); |
| goymame | 0:bf6b79d0e255 | 33 | |
| goymame | 0:bf6b79d0e255 | 34 | int main(){ |
| goymame | 0:bf6b79d0e255 | 35 | serial.printf("\r\n******************* Wiegand reader example *******************\r\n"); |
| goymame | 0:bf6b79d0e255 | 36 | wiegandThread.start(callback( wiegandQueue, &EventQueue::dispatch_forever)); |
| goymame | 0:bf6b79d0e255 | 37 | } |
| goymame | 0:bf6b79d0e255 | 38 | |
| goymame | 0:bf6b79d0e255 | 39 | void onTag(void){ |
| goymame | 0:bf6b79d0e255 | 40 | long double rawInt = wiegandReader.getRawInt(); |
| goymame | 0:bf6b79d0e255 | 41 | serial.printf("Integer: %.0Lf\r\n",rawInt); |
| goymame | 0:bf6b79d0e255 | 42 | |
| goymame | 0:bf6b79d0e255 | 43 | unsigned char decDigits = wiegandReader.getDecDigits(); |
| goymame | 0:bf6b79d0e255 | 44 | volatile char* decimalString = new volatile char [decDigits+1]; |
| goymame | 0:bf6b79d0e255 | 45 | memset((char*)decimalString,'\0',decDigits+1); |
| goymame | 0:bf6b79d0e255 | 46 | wiegandReader.getDecString(decimalString); |
| goymame | 0:bf6b79d0e255 | 47 | serial.printf("Decimal String: %s\r\n",decimalString); |
| goymame | 0:bf6b79d0e255 | 48 | delete[] decimalString; |
| goymame | 0:bf6b79d0e255 | 49 | |
| goymame | 0:bf6b79d0e255 | 50 | unsigned char hexDigits = wiegandReader.getHexDigits(); |
| goymame | 0:bf6b79d0e255 | 51 | volatile char* hexadecimalString = new volatile char [hexDigits+1]; |
| goymame | 0:bf6b79d0e255 | 52 | memset((char*)hexadecimalString,'\0',hexDigits+1); |
| goymame | 0:bf6b79d0e255 | 53 | wiegandReader.getHexString(hexadecimalString); |
| goymame | 0:bf6b79d0e255 | 54 | serial.printf("Hexadecimal String: %s\r\n\n",hexadecimalString); |
| goymame | 0:bf6b79d0e255 | 55 | delete[] hexadecimalString; |
| goymame | 0:bf6b79d0e255 | 56 | wiegandReader.reset(); |
| goymame | 0:bf6b79d0e255 | 57 | } |