Source

arduino_rfid_controller / wiegand_rfid.cpp

#include <WProgram.h>
#include "wiegand_rfid.h"
#include "interrupt_support.h"
#include "bitarray.h"

WiegandRFID::WiegandRFID(int pinDataZero,int pinDataOne)
{
  _pinDataZero = pinDataZero;
  _pinDataOne = pinDataOne;
  bits.clear();
  readerCount = 0;
}

void WiegandRFID::DataZeroInterrupt()
{
  if(digitalRead(_pinDataZero) == LOW){
    if(readerCount < MAX_BIT_LENGTH) {bits.set(readerCount,0);}
    readerCount++;
  }
  lastDataTime = millis();
}
void WiegandRFID::DataOneInterrupt()
{
  if(digitalRead(_pinDataOne) == LOW){
    if(readerCount < MAX_BIT_LENGTH) {bits.set(readerCount,1);}
    readerCount++;
  }
  lastDataTime = millis();
}

void WiegandRFID::reset() {
  resetInterruptPin(_pinDataZero);
  resetInterruptPin(_pinDataOne);
  bits.clear();
  readerCount = 0;
  lastDataTime = 0;
}
int WiegandRFID::getTag(){
  if(readerCount > 0 && (lastDataTime + 200 < millis())){
    //long ret = hash(reader);
    char str[MAX_BIT_LENGTH];
    bits.to_string(str);
    Serial.println(bits.length());
    for (int i = 0; i < MAX_BIT_LENGTH; i++) { Serial.print(str[i]);}
    Serial.println("");
    Serial.println(readerCount);
    bits.clear();
    readerCount = 0;
    //tag[0] = (byte)(ret >> 24);
    //tag[1] = (byte)(ret >> 16);
    //tag[2] = (byte)(ret >> 8);
    //tag[3] = (byte)ret;
    return 1;
  } 
  else {
    return 0;
  }
}

void WiegandRFID::resetInterruptPin(int i)
{
  // the interrupt in the Atmel processor mises out the first negitave pulse as the inputs are already high,
  // so this gives a pulse to each reader input line to get the interrupts working properly.
  // Then clear out the reader variables.
  // The readers are open collector sitting normally at a one so this is OK
  pinMode(i, OUTPUT);
  digitalWrite(i, HIGH); // enable internal pull up causing a one
  digitalWrite(i, LOW); // disable internal pull up causing zero and thus an interrupt
  pinMode(i, INPUT);
  digitalWrite(i, HIGH); // enable internal pull up
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.