Exemplo n.º 1
0
boolean RFID_EM41000::readRFID(String& rfid_result, unsigned long timeout_ms) { 
  unsigned long start_time = millis();
  int bytes_read = -1;
  char tag_byte = '\0';
  char tag_data[RFID_LENGTH+1];
  tag_data[RFID_LENGTH] = '\0';

  // Flush serial buffer before turning on RFID transponder
  readUntilUnavailable(_rfid_serial);

  // Enable the RFID reader
  enableRFID();
  
  while(bytes_read <= RFID_LENGTH
        && (timeout_ms == 0 || millis() - start_time < timeout_ms))
  { 
    // Read the byte from the RFID reader
    tag_byte = _rfid_serial.read();
    
    // Are we currently populating tag_data?
    if (bytes_read >= 0) {
      
      // Should we stop populating tag_data?
      if(bytes_read >= RFID_LENGTH || tag_byte == RFID_START || tag_byte == RFID_END) {
        disableRFID();
        break; // stop reading
      }
    
      // Append the tag_data (weird bytes appear in >=Arduino 1.0, so we check byte content)
      if ((tag_byte >= 'A' && tag_byte <= 'F') || (tag_byte >= '0' && tag_byte <= '9')) { 
        tag_data[bytes_read] = tag_byte;
        bytes_read++;
      }
    }
    else if(tag_byte == RFID_START) {
      // We read the first byte of a key... signals that we start reading into tagData[]
      bytes_read = 0; 
    }
  }
  
  // Disable RFID (just to be safe)
  disableRFID();
  
  // Return result
  if (bytes_read == RFID_LENGTH) {
    rfid_result = tag_data;
    return true;
  }
  else {
    return false;
  }
  
}
Exemplo n.º 2
0
void NabaztagInjector::processRequest() {
  if( sendEnabled && outSize > 0 ) {
    Wire.write(out, outSize);

    if( sendBuffer.getSize() < 1 ) { //all data is send
      inited = false;
      enableRFID();
    }
    outSize = 0;
    sendEnabled = false;
  }
}
Exemplo n.º 3
0
void loop() {   //Start our main Arduino Loop
 enableRFID();   //Enable the RFID card
 getRFIDTag();   //Reads the tag
 if(isCodeValid()) {  //Validates that the tag is good
   disableRFID();  //Puts the RFID reader in to low power mode
   sendCode();     //Sends the code read to the serial port
   delay(ITERATION_LENGTH);  //Debounce?
 } 
 else {
   disableRFID();  //Got a incomplete code.. 
   Serial.println("Got some noise");  
 }
 Serial.flush();
 clearCode();
} 
Exemplo n.º 4
0
void NabaztagInjector::begin(int _rfidPort)
{
  rfidPort = _rfidPort;
  if(rfidPort > 0) {
    pinMode(rfidPort, OUTPUT);
    digitalWrite(rfidPort, LOW);
  }

  sendBuffer.init(SEND_BUFFER_SIZE);

  Wire.begin(CRX14_ADR);
  Wire.onReceive(receiveCallback);
  Wire.onRequest(requestCallback);

  enableRFID();
}