You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
3.9 KiB
175 lines
3.9 KiB
#if 0
|
|
#include <SPI.h>
|
|
#include <PN532_SPI.h>
|
|
#include <PN532.h>
|
|
#include <NfcAdapter.h>
|
|
|
|
PN532_SPI pn532spi(SPI, 10);
|
|
NfcAdapter nfc = NfcAdapter(pn532spi);
|
|
#else
|
|
|
|
#include <Wire.h>
|
|
#include <PN532_I2C.h>
|
|
#include <PN532.h>
|
|
#include <NfcAdapter.h>
|
|
|
|
PN532_I2C pn532_i2c(Wire);
|
|
NfcAdapter nfc = NfcAdapter(pn532_i2c);
|
|
#endif
|
|
|
|
int grabador_machine = 0;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
Serial.println("NDEF Writer");
|
|
nfc.begin();
|
|
grabador_machine = 4;
|
|
|
|
}
|
|
bool record_name = false;
|
|
bool valid_name = false;
|
|
bool success2 = false;
|
|
String Name;
|
|
const int payloadLength = 50;
|
|
int char_count = 0;
|
|
byte payload[payloadLength];
|
|
unsigned long time_rfid;
|
|
|
|
void loop() {
|
|
|
|
|
|
switch (grabador_machine) {
|
|
case 1 :
|
|
if (time_rfid < millis()) {
|
|
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
|
|
if (nfc.tagPresent()) {
|
|
|
|
success2 = nfc.format();
|
|
if (success2) {
|
|
Serial.println("\nSuccess, tag formatted as NDEF.");
|
|
grabador_machine = 4;
|
|
time_rfid = millis() + 1000;
|
|
} else {
|
|
Serial.println("\nFormat failed.");
|
|
grabador_machine = 4;
|
|
}
|
|
}
|
|
time_rfid = millis() + 1000;
|
|
}
|
|
|
|
break;
|
|
case 2 :
|
|
{
|
|
if (time_rfid < millis()) {
|
|
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader.");
|
|
if (nfc.tagPresent()) {
|
|
NdefMessage message = NdefMessage();
|
|
Serial.println(Name);
|
|
message.addTextRecord(Name, "ñ");
|
|
boolean success = nfc.write(message);
|
|
if (success) {
|
|
Serial.println("Success. Try reading this tag with your phone.");
|
|
grabador_machine = 4;
|
|
} else {
|
|
Serial.println("Write failed");
|
|
grabador_machine = 4;
|
|
}
|
|
}
|
|
|
|
time_rfid = millis() + 1000;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 3:
|
|
if (time_rfid < millis()) {
|
|
Serial.println("Ubique una tarjeta RFID para borrar");
|
|
time_rfid = millis() + 20000;
|
|
|
|
}
|
|
if (nfc.tagPresent()) {
|
|
|
|
bool success = nfc.clean();
|
|
if (success) {
|
|
Serial.println("\nSuccess, tag restored to factory state.");
|
|
grabador_machine = 4;
|
|
} else {
|
|
Serial.println("\nError, unable to clean tag.");
|
|
grabador_machine = 4;
|
|
}
|
|
|
|
}
|
|
break;
|
|
|
|
case 4:
|
|
//if(inserted_name)
|
|
Serial.println(""); Serial.println("");
|
|
Serial.println("MENU");
|
|
Serial.println("1_Format RFID");
|
|
if (valid_name) {
|
|
|
|
Serial.println("2_Write RFID");
|
|
}
|
|
Serial.println("3_Clean RFID");
|
|
Serial.println("5_Insert Name");
|
|
|
|
Serial.print("Nombre:");
|
|
Serial.println(Name);
|
|
grabador_machine = 6;
|
|
break;
|
|
|
|
case 5:
|
|
Serial.println("Inserte el nombre y # al final");
|
|
grabador_machine = 6;
|
|
Name.clear();
|
|
record_name = true;
|
|
break;
|
|
|
|
case 6:
|
|
if (Serial.available() > 0) {
|
|
char inByte = Serial.read();
|
|
if (record_name) {
|
|
if (inByte == 35) {
|
|
grabador_machine = 4;
|
|
valid_name = true;
|
|
record_name = false;
|
|
} else {
|
|
Name += inByte;
|
|
//Name += (char)payload[char_count];
|
|
}
|
|
}
|
|
|
|
if (inByte == '1') grabador_machine = 1;
|
|
if (inByte == '2') grabador_machine = 2;
|
|
if (inByte == '3') grabador_machine = 3;
|
|
if (inByte == '5') grabador_machine = 5;
|
|
|
|
if (char_count > 50) {
|
|
char_count = 0;
|
|
}
|
|
else {
|
|
char_count++;
|
|
}
|
|
//grabador_machine = !grabador_machine;
|
|
//Serial.print(inByte);
|
|
|
|
}
|
|
break;
|
|
|
|
case 88 :
|
|
|
|
for (int c = 3; c < payloadLength; c++) {
|
|
Name += (char)payload[c];
|
|
|
|
}
|
|
break;
|
|
|
|
default :
|
|
{
|
|
Serial.println("End");
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|