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:
Sat Apr 27 23:37:01 2019 +0000
Revision:
0:4929608f96d0
Child:
1:5217baef72fd
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
goymame 0:4929608f96d0 1 #ifndef MBED_MICIO_H
goymame 0:4929608f96d0 2 #define MBED_MICIO_H
goymame 0:4929608f96d0 3
goymame 0:4929608f96d0 4 #include "mbed.h"
goymame 0:4929608f96d0 5
goymame 0:4929608f96d0 6 /*
goymame 0:4929608f96d0 7 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 8 It automatically calibrates the timeout during the first reading unless specified.
goymame 0:4929608f96d0 9 Timeout can be set using setTimout, units are in milliseconds (first call stopCalibrating()).
goymame 0:4929608f96d0 10 Always call reset after saving Wiegand data.
goymame 0:4929608f96d0 11 Data can be extracted as :
goymame 0:4929608f96d0 12 * Raw -- For manipulation
goymame 0:4929608f96d0 13 * Base 10 Integer
goymame 0:4929608f96d0 14 * Base 10 String
goymame 0:4929608f96d0 15 * Base 16 String
goymame 0:4929608f96d0 16 EventQueue is required for deferring from ISR, it is possible to dispatch the EventQueue from the mainQueue or any other thread.
goymame 0:4929608f96d0 17 */
goymame 0:4929608f96d0 18
goymame 0:4929608f96d0 19 class Wiegand {
goymame 0:4929608f96d0 20 private:
goymame 0:4929608f96d0 21 Callback<void(void)> _callback;
goymame 0:4929608f96d0 22 InterruptIn _d0;
goymame 0:4929608f96d0 23 InterruptIn _d1;
goymame 0:4929608f96d0 24 EventQueue* _eventQueue;
goymame 0:4929608f96d0 25 Timer _interPulseGapTimer;
goymame 0:4929608f96d0 26 Timeout _timeout;
goymame 0:4929608f96d0 27
goymame 0:4929608f96d0 28 bool _autoCalibration;
goymame 0:4929608f96d0 29 unsigned char _bits;
goymame 0:4929608f96d0 30 volatile unsigned char _bitsRead;
goymame 0:4929608f96d0 31 uint8_t* _buffer;
goymame 0:4929608f96d0 32 unsigned char _bufferSize;
goymame 0:4929608f96d0 33 unsigned char _decDigits;
goymame 0:4929608f96d0 34 bool _firstReading;
goymame 0:4929608f96d0 35 unsigned char _hexDigits;
goymame 0:4929608f96d0 36 volatile int* _interPulseGapBuffer;
goymame 0:4929608f96d0 37 unsigned int _transmissionTimeout;
goymame 0:4929608f96d0 38
goymame 0:4929608f96d0 39 void _data0ISR(void);
goymame 0:4929608f96d0 40 void _data0ISRRise(void);
goymame 0:4929608f96d0 41 void _data1ISR(void);
goymame 0:4929608f96d0 42 void _data1ISRRise(void);
goymame 0:4929608f96d0 43 void _onWiegandISR(void);
goymame 0:4929608f96d0 44 void _onWiegandNonISR(void);
goymame 0:4929608f96d0 45 void _shift_left(volatile unsigned char *ar, int size, int shift);
goymame 0:4929608f96d0 46
goymame 0:4929608f96d0 47 public:
goymame 0:4929608f96d0 48 Wiegand(PinName d0, PinName d1, EventQueue* eventQueue, Callback<void(void)> wiegandCallback, unsigned char bits);
goymame 0:4929608f96d0 49 ~Wiegand();
goymame 0:4929608f96d0 50
goymame 0:4929608f96d0 51 void calibrateTimeout(void);
goymame 0:4929608f96d0 52 unsigned char getDecDigits();
goymame 0:4929608f96d0 53 void getDecString(volatile char* decString);
goymame 0:4929608f96d0 54 unsigned char getHexDigits();
goymame 0:4929608f96d0 55 void getHexString(volatile char* hexString);
goymame 0:4929608f96d0 56 uint8_t* getRaw(void);
goymame 0:4929608f96d0 57 long double getRawInt(void);
goymame 0:4929608f96d0 58 unsigned int getTimeout(void);
goymame 0:4929608f96d0 59 void reset(void);
goymame 0:4929608f96d0 60 void setTimeout(unsigned int time);
goymame 0:4929608f96d0 61 void startCalibrating(void);
goymame 0:4929608f96d0 62 void stopCalibrating(void);
goymame 0:4929608f96d0 63 };
goymame 0:4929608f96d0 64
goymame 0:4929608f96d0 65 #endif