Cleanup code structure and add some comments

This commit is contained in:
Adam Goldsmith 2020-03-28 17:18:54 -04:00
parent 1322667762
commit cad3579ecb

View File

@ -1,23 +1,11 @@
/* Based on: // Based on: http://www.pagemac.com/projects/rfid/arduino_wiegand
* HID RFID Reader Wiegand Interface for Arduino Uno
* Originally by Daniel Smith, 2012.01.30 -- http://www.pagemac.com/projects/rfid/arduino_wiegand
*
* Updated 2016-11-23 by Jon "ShakataGaNai" Davis.
* See https://obviate.io/?p=7470 for more details & instructions
*/
#include <limits.h>
#include <Keyboard.h> #include <Keyboard.h>
// DATA pins // DATA pins
#define DATA0 2 #define DATA0 2
#define DATA1 3 #define DATA1 3
// LED pins
#define LED_GREEN 11;
#define LED_RED 12;
#define BEEP_BEEP 10;
#define WEIGAND_WAIT_TIME 500 // time to wait for another weigand pulse. #define WEIGAND_WAIT_TIME 500 // time to wait for another weigand pulse.
#define DATA_SIZE 32 #define DATA_SIZE 32
@ -33,15 +21,9 @@ inline void gotBit(char bit) {
bitCount++; bitCount++;
} }
// interrupt that happens when INTO goes low (0 bit) // interrupts for DATA0/DATA1
void ISR_INT0() { void ISR_INT0() { gotBit(0); }
gotBit(0); void ISR_INT1() { gotBit(1); }
}
// interrupt that happens when INT1 goes low (1 bit)
void ISR_INT1() {
gotBit(1);
}
void setup() { void setup() {
pinMode(DATA0, INPUT); pinMode(DATA0, INPUT);
@ -57,7 +39,7 @@ void setup() {
void loop() void loop()
{ {
// if we have bits and we the weigand counter went out // Check if last bit was recieved more than WEIGAND_WAIT_TIME ago
if (bitCount > 0 && (millis() - weigand_idle_start) >= WEIGAND_WAIT_TIME) { if (bitCount > 0 && (millis() - weigand_idle_start) >= WEIGAND_WAIT_TIME) {
unsigned char i; unsigned char i;
uint32_t data = dataBits >> (DATA_SIZE - bitCount + 1); uint32_t data = dataBits >> (DATA_SIZE - bitCount + 1);
@ -75,10 +57,6 @@ void loop()
uint16_t cardCode = (data >> 1) & 0xFFFF; uint16_t cardCode = (data >> 1) & 0xFFFF;
// TODO: check parity bits // TODO: check parity bits
Keyboard.print(facilityCode);
Keyboard.print('\t');
Keyboard.print(cardCode);
Keyboard.print('\n');
printBits(facilityCode, cardCode); printBits(facilityCode, cardCode);
} }
else { else {
@ -91,6 +69,11 @@ void loop()
} }
void printBits(uint8_t facilityCode, uint16_t cardCode) { void printBits(uint8_t facilityCode, uint16_t cardCode) {
Keyboard.print(facilityCode);
Keyboard.print('\t');
Keyboard.print(cardCode);
Keyboard.print('\n');
Serial.print("FC = "); Serial.print("FC = ");
Serial.print(facilityCode); Serial.print(facilityCode);
Serial.print(", CC = "); Serial.print(", CC = ");