Jose Marquez
/
mbed-os-wiegand-example
Example of the usage of the mbed-os-wiegand library.
main.cpp
- Committer:
- goymame
- Date:
- 2019-04-28
- Revision:
- 1:26991d042db7
- Parent:
- 0:bf6b79d0e255
- Child:
- 2:42f8f6b183ae
File content as of revision 1:26991d042db7:
/* mbed Wiegand Library * Copyright (c) 2017-2019, Gregorio Marquez * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "mbed.h" #include "wiegand.h" RawSerial serial(USBTX, USBRX); Thread wiegandThread; EventQueue* wiegandQueue = new EventQueue (64 * EVENTS_EVENT_SIZE); void onTag(void); Wiegand wiegandReader(PE_13, PF_15, wiegandQueue, &onTag, 32); int main(){ serial.printf("\r\n******************* Wiegand reader example *******************\r\n"); wiegandThread.start(callback( wiegandQueue, &EventQueue::dispatch_forever)); } void onTag(void){ long double rawInt = wiegandReader.getRawInt(); serial.printf("Integer: %.0Lf\r\n",rawInt); unsigned char decDigits = wiegandReader.getDecDigits(); volatile char* decimalString = new volatile char [decDigits+1]; memset((char*)decimalString,'\0',decDigits+1); wiegandReader.getDecString(decimalString); serial.printf("Decimal String: %s\r\n",decimalString); delete[] decimalString; unsigned char hexDigits = wiegandReader.getHexDigits(); volatile char* hexadecimalString = new volatile char [hexDigits+1]; memset((char*)hexadecimalString,'\0',hexDigits+1); wiegandReader.getHexString(hexadecimalString); serial.printf("Hexadecimal String: %s\r\n\n",hexadecimalString); delete[] hexadecimalString; wiegandReader.reset(); }