Example of the usage of the mbed-os-wiegand library.

Dependencies:   mbed-os-wiegand

Committer:
goymame
Date:
Sun Apr 28 00:03:56 2019 +0000
Revision:
0:bf6b79d0e255
Child:
1:26991d042db7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
goymame 0:bf6b79d0e255 1 #include "mbed.h"
goymame 0:bf6b79d0e255 2 #include "wiegand.h"
goymame 0:bf6b79d0e255 3
goymame 0:bf6b79d0e255 4 RawSerial serial(USBTX, USBRX);
goymame 0:bf6b79d0e255 5 Thread wiegandThread;
goymame 0:bf6b79d0e255 6 EventQueue* wiegandQueue = new EventQueue (64 * EVENTS_EVENT_SIZE);
goymame 0:bf6b79d0e255 7
goymame 0:bf6b79d0e255 8 void onTag(void);
goymame 0:bf6b79d0e255 9
goymame 0:bf6b79d0e255 10 Wiegand wiegandReader(PE_13, PF_15, wiegandQueue, &onTag, 32);
goymame 0:bf6b79d0e255 11
goymame 0:bf6b79d0e255 12 int main(){
goymame 0:bf6b79d0e255 13 serial.printf("\r\n******************* Wiegand reader example *******************\r\n");
goymame 0:bf6b79d0e255 14 wiegandThread.start(callback( wiegandQueue, &EventQueue::dispatch_forever));
goymame 0:bf6b79d0e255 15 }
goymame 0:bf6b79d0e255 16
goymame 0:bf6b79d0e255 17 void onTag(void){
goymame 0:bf6b79d0e255 18 long double rawInt = wiegandReader.getRawInt();
goymame 0:bf6b79d0e255 19 serial.printf("Integer: %.0Lf\r\n",rawInt);
goymame 0:bf6b79d0e255 20
goymame 0:bf6b79d0e255 21 unsigned char decDigits = wiegandReader.getDecDigits();
goymame 0:bf6b79d0e255 22 volatile char* decimalString = new volatile char [decDigits+1];
goymame 0:bf6b79d0e255 23 memset((char*)decimalString,'\0',decDigits+1);
goymame 0:bf6b79d0e255 24 wiegandReader.getDecString(decimalString);
goymame 0:bf6b79d0e255 25 serial.printf("Decimal String: %s\r\n",decimalString);
goymame 0:bf6b79d0e255 26 delete[] decimalString;
goymame 0:bf6b79d0e255 27
goymame 0:bf6b79d0e255 28 unsigned char hexDigits = wiegandReader.getHexDigits();
goymame 0:bf6b79d0e255 29 volatile char* hexadecimalString = new volatile char [hexDigits+1];
goymame 0:bf6b79d0e255 30 memset((char*)hexadecimalString,'\0',hexDigits+1);
goymame 0:bf6b79d0e255 31 wiegandReader.getHexString(hexadecimalString);
goymame 0:bf6b79d0e255 32 serial.printf("Hexadecimal String: %s\r\n\n",hexadecimalString);
goymame 0:bf6b79d0e255 33 delete[] hexadecimalString;
goymame 0:bf6b79d0e255 34 wiegandReader.reset();
goymame 0:bf6b79d0e255 35 }