This library reads Wiegand, saving it into a buffer, calling a callback function after it is full or a timeout is reached.
Dependents: mbed-os-wiegand-example
This library reads Wiegand, saving it into a buffer, calling a callback function after it is full or a timeout is reached. Data can be extracted as :
- Raw
- Base 10 Integer
- Base 10 String
- Base 16 String
Always call reset after saving Wiegand data.
It automatically calibrates the timeout during the first reading unless specified.
Timeout can be set using setTimout, units are in milliseconds (first call stopCalibrating()).
EventQueue is required for deferring from ISR, it is possible to dispatch the EventQueue from the mainQueue or any other thread.
wiegand.h@1:5217baef72fd, 2019-04-27 (annotated)
- Committer:
- goymame
- Date:
- Sat Apr 27 23:53:14 2019 +0000
- Revision:
- 1:5217baef72fd
- Parent:
- 0:4929608f96d0
- Child:
- 2:2c72a6b13593
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
goymame | 1:5217baef72fd | 1 | /* mbed Wiegand Library |
goymame | 1:5217baef72fd | 2 | * Copyright (c) 2017-2019, Gregorio Marquez |
goymame | 1:5217baef72fd | 3 | * |
goymame | 1:5217baef72fd | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
goymame | 1:5217baef72fd | 5 | * of this software and associated documentation files (the "Software"), to deal |
goymame | 1:5217baef72fd | 6 | * in the Software without restriction, including without limitation the rights |
goymame | 1:5217baef72fd | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
goymame | 1:5217baef72fd | 8 | * copies of the Software, and to permit persons to whom the Software is |
goymame | 1:5217baef72fd | 9 | * furnished to do so, subject to the following conditions: |
goymame | 1:5217baef72fd | 10 | * |
goymame | 1:5217baef72fd | 11 | * The above copyright notice and this permission notice shall be included in |
goymame | 1:5217baef72fd | 12 | * all copies or substantial portions of the Software. |
goymame | 1:5217baef72fd | 13 | * |
goymame | 1:5217baef72fd | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
goymame | 1:5217baef72fd | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
goymame | 1:5217baef72fd | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
goymame | 1:5217baef72fd | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
goymame | 1:5217baef72fd | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
goymame | 1:5217baef72fd | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
goymame | 1:5217baef72fd | 20 | * THE SOFTWARE. |
goymame | 1:5217baef72fd | 21 | */ |
goymame | 1:5217baef72fd | 22 | |
goymame | 0:4929608f96d0 | 23 | #ifndef MBED_MICIO_H |
goymame | 0:4929608f96d0 | 24 | #define MBED_MICIO_H |
goymame | 0:4929608f96d0 | 25 | |
goymame | 0:4929608f96d0 | 26 | #include "mbed.h" |
goymame | 0:4929608f96d0 | 27 | |
goymame | 0:4929608f96d0 | 28 | /* |
goymame | 1:5217baef72fd | 29 | This library reads Wiegand, saving it into a buffer, calling a callback function after it is full or a timeout is reached. |
goymame | 0:4929608f96d0 | 30 | Data can be extracted as : |
goymame | 0:4929608f96d0 | 31 | * Raw -- For manipulation |
goymame | 0:4929608f96d0 | 32 | * Base 10 Integer |
goymame | 0:4929608f96d0 | 33 | * Base 10 String |
goymame | 0:4929608f96d0 | 34 | * Base 16 String |
goymame | 1:5217baef72fd | 35 | Always call reset after saving Wiegand data. |
goymame | 1:5217baef72fd | 36 | It automatically calibrates the timeout during the first reading unless specified. |
goymame | 1:5217baef72fd | 37 | Timeout can be set using setTimout, units are in milliseconds (first call stopCalibrating()). |
goymame | 0:4929608f96d0 | 38 | EventQueue is required for deferring from ISR, it is possible to dispatch the EventQueue from the mainQueue or any other thread. |
goymame | 0:4929608f96d0 | 39 | */ |
goymame | 0:4929608f96d0 | 40 | |
goymame | 0:4929608f96d0 | 41 | class Wiegand { |
goymame | 0:4929608f96d0 | 42 | private: |
goymame | 0:4929608f96d0 | 43 | Callback<void(void)> _callback; |
goymame | 0:4929608f96d0 | 44 | InterruptIn _d0; |
goymame | 0:4929608f96d0 | 45 | InterruptIn _d1; |
goymame | 0:4929608f96d0 | 46 | EventQueue* _eventQueue; |
goymame | 0:4929608f96d0 | 47 | Timer _interPulseGapTimer; |
goymame | 0:4929608f96d0 | 48 | Timeout _timeout; |
goymame | 0:4929608f96d0 | 49 | |
goymame | 0:4929608f96d0 | 50 | bool _autoCalibration; |
goymame | 0:4929608f96d0 | 51 | unsigned char _bits; |
goymame | 0:4929608f96d0 | 52 | volatile unsigned char _bitsRead; |
goymame | 0:4929608f96d0 | 53 | uint8_t* _buffer; |
goymame | 0:4929608f96d0 | 54 | unsigned char _bufferSize; |
goymame | 0:4929608f96d0 | 55 | unsigned char _decDigits; |
goymame | 0:4929608f96d0 | 56 | bool _firstReading; |
goymame | 0:4929608f96d0 | 57 | unsigned char _hexDigits; |
goymame | 0:4929608f96d0 | 58 | volatile int* _interPulseGapBuffer; |
goymame | 0:4929608f96d0 | 59 | unsigned int _transmissionTimeout; |
goymame | 0:4929608f96d0 | 60 | |
goymame | 0:4929608f96d0 | 61 | void _data0ISR(void); |
goymame | 0:4929608f96d0 | 62 | void _data0ISRRise(void); |
goymame | 0:4929608f96d0 | 63 | void _data1ISR(void); |
goymame | 0:4929608f96d0 | 64 | void _data1ISRRise(void); |
goymame | 0:4929608f96d0 | 65 | void _onWiegandISR(void); |
goymame | 0:4929608f96d0 | 66 | void _onWiegandNonISR(void); |
goymame | 0:4929608f96d0 | 67 | void _shift_left(volatile unsigned char *ar, int size, int shift); |
goymame | 0:4929608f96d0 | 68 | |
goymame | 0:4929608f96d0 | 69 | public: |
goymame | 0:4929608f96d0 | 70 | Wiegand(PinName d0, PinName d1, EventQueue* eventQueue, Callback<void(void)> wiegandCallback, unsigned char bits); |
goymame | 0:4929608f96d0 | 71 | ~Wiegand(); |
goymame | 0:4929608f96d0 | 72 | |
goymame | 0:4929608f96d0 | 73 | void calibrateTimeout(void); |
goymame | 0:4929608f96d0 | 74 | unsigned char getDecDigits(); |
goymame | 0:4929608f96d0 | 75 | void getDecString(volatile char* decString); |
goymame | 0:4929608f96d0 | 76 | unsigned char getHexDigits(); |
goymame | 0:4929608f96d0 | 77 | void getHexString(volatile char* hexString); |
goymame | 0:4929608f96d0 | 78 | uint8_t* getRaw(void); |
goymame | 0:4929608f96d0 | 79 | long double getRawInt(void); |
goymame | 0:4929608f96d0 | 80 | unsigned int getTimeout(void); |
goymame | 0:4929608f96d0 | 81 | void reset(void); |
goymame | 0:4929608f96d0 | 82 | void setTimeout(unsigned int time); |
goymame | 0:4929608f96d0 | 83 | void startCalibrating(void); |
goymame | 0:4929608f96d0 | 84 | void stopCalibrating(void); |
goymame | 0:4929608f96d0 | 85 | }; |
goymame | 0:4929608f96d0 | 86 | |
goymame | 0:4929608f96d0 | 87 | #endif |