Make wiegand idle check more simple/consistent using millis()

This commit is contained in:
Adam Goldsmith 2020-03-28 17:07:52 -04:00
parent df2210bf4d
commit 90248057d7

View File

@ -14,19 +14,17 @@
#define LED_RED 12;
#define BEEP_BEEP 10;
#define WEIGAND_WAIT_TIME 3000 // time to wait for another weigand pulse.
#define WEIGAND_WAIT_TIME 500 // time to wait for another weigand pulse.
#define DATA_SIZE 32
volatile uint32_t dataBits = 0; // stores all of the data bits
volatile size_t bitCount = 0; // number of bits recieved
volatile unsigned char flagDone; // goes low when data is currently being captured
volatile unsigned int weigand_counter; // countdown until we assume there are no more bits
volatile unsigned long weigand_idle_start;
inline void gotBit() {
weigand_idle_start = millis();
bitCount++;
flagDone = 0;
weigand_counter = WEIGAND_WAIT_TIME;
}
// interrupt that happens when INTO goes low (0 bit)
@ -52,20 +50,13 @@ void setup() {
attachInterrupt(0, ISR_INT0, FALLING);
attachInterrupt(1, ISR_INT1, FALLING);
weigand_counter = WEIGAND_WAIT_TIME;
Keyboard.begin();
}
void loop()
{
// This waits to make sure that there have been no more data pulses before processing data
if (!flagDone) {
if (--weigand_counter == 0)
flagDone = 1;
}
// if we have bits and we the weigand counter went out
if (bitCount > 0 && flagDone) {
if (bitCount > 0 && (millis() - weigand_idle_start) >= WEIGAND_WAIT_TIME) {
unsigned char i;
uint32_t data = dataBits >> (DATA_SIZE - bitCount + 1);