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.

Committer:
goymame
Date:
Thu May 16 22:12:19 2019 +0000
Revision:
3:ea5e0ab156b5
Parent:
2:2c72a6b13593
New update bits function

Who changed what in which revision?

UserRevisionLine numberNew 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 2:2c72a6b13593 43 Callback<void(Wiegand* wiegandReader)> _callback;
goymame 2:2c72a6b13593 44
goymame 0:4929608f96d0 45 InterruptIn _d0;
goymame 0:4929608f96d0 46 InterruptIn _d1;
goymame 0:4929608f96d0 47 EventQueue* _eventQueue;
goymame 0:4929608f96d0 48 Timer _interPulseGapTimer;
goymame 0:4929608f96d0 49 Timeout _timeout;
goymame 0:4929608f96d0 50
goymame 0:4929608f96d0 51 bool _autoCalibration;
goymame 0:4929608f96d0 52 unsigned char _bits;
goymame 0:4929608f96d0 53 volatile unsigned char _bitsRead;
goymame 0:4929608f96d0 54 uint8_t* _buffer;
goymame 0:4929608f96d0 55 unsigned char _bufferSize;
goymame 0:4929608f96d0 56 unsigned char _decDigits;
goymame 0:4929608f96d0 57 bool _firstReading;
goymame 0:4929608f96d0 58 unsigned char _hexDigits;
goymame 2:2c72a6b13593 59 unsigned char _id;
goymame 0:4929608f96d0 60 volatile int* _interPulseGapBuffer;
goymame 0:4929608f96d0 61 unsigned int _transmissionTimeout;
goymame 0:4929608f96d0 62
goymame 0:4929608f96d0 63 void _data0ISR(void);
goymame 0:4929608f96d0 64 void _data0ISRRise(void);
goymame 0:4929608f96d0 65 void _data1ISR(void);
goymame 0:4929608f96d0 66 void _data1ISRRise(void);
goymame 0:4929608f96d0 67 void _onWiegandISR(void);
goymame 0:4929608f96d0 68 void _onWiegandNonISR(void);
goymame 0:4929608f96d0 69 void _shift_left(volatile unsigned char *ar, int size, int shift);
goymame 0:4929608f96d0 70
goymame 0:4929608f96d0 71 public:
goymame 3:ea5e0ab156b5 72 Wiegand(PinName d0, PinName d1, EventQueue* eventQueue, unsigned char i=0);
goymame 0:4929608f96d0 73 ~Wiegand();
goymame 0:4929608f96d0 74
goymame 2:2c72a6b13593 75 void attach(Callback<void(Wiegand *WiegandObj)> wiegandCallback);
goymame 0:4929608f96d0 76 void calibrateTimeout(void);
goymame 0:4929608f96d0 77 unsigned char getDecDigits();
goymame 0:4929608f96d0 78 void getDecString(volatile char* decString);
goymame 0:4929608f96d0 79 unsigned char getHexDigits();
goymame 0:4929608f96d0 80 void getHexString(volatile char* hexString);
goymame 2:2c72a6b13593 81 unsigned char getId();
goymame 0:4929608f96d0 82 uint8_t* getRaw(void);
goymame 0:4929608f96d0 83 long double getRawInt(void);
goymame 0:4929608f96d0 84 unsigned int getTimeout(void);
goymame 0:4929608f96d0 85 void reset(void);
goymame 0:4929608f96d0 86 void setTimeout(unsigned int time);
goymame 3:ea5e0ab156b5 87 void setBits(unsigned char bits);
goymame 0:4929608f96d0 88 void startCalibrating(void);
goymame 0:4929608f96d0 89 void stopCalibrating(void);
goymame 0:4929608f96d0 90 };
goymame 0:4929608f96d0 91
goymame 0:4929608f96d0 92 #endif