|
|
|
@ -17,67 +17,146 @@ PN532_I2C pn532_i2c(Wire); |
|
|
|
NfcAdapter nfc = NfcAdapter(pn532_i2c); |
|
|
|
#endif |
|
|
|
|
|
|
|
int grabador_machine = 0; |
|
|
|
|
|
|
|
void setup() { |
|
|
|
Serial.begin(115200); |
|
|
|
Serial.begin(9600); |
|
|
|
Serial.println("NDEF Writer"); |
|
|
|
nfc.begin(); |
|
|
|
grabador_machine = 4; |
|
|
|
|
|
|
|
} |
|
|
|
bool record_name = false; |
|
|
|
bool valid_name = false; |
|
|
|
bool success2 = false; |
|
|
|
int grabador_machine = 0; |
|
|
|
String Name; |
|
|
|
const int payloadLength = 50; |
|
|
|
int char_count = 0; |
|
|
|
byte payload[payloadLength]; |
|
|
|
unsigned long time_rfid; |
|
|
|
|
|
|
|
void loop() { |
|
|
|
if (Serial.available() > 0) { |
|
|
|
int inByte = Serial.read(); |
|
|
|
if (inByte == '#') { |
|
|
|
|
|
|
|
Serial.print("Name: "); |
|
|
|
Serial.println(Name); |
|
|
|
|
|
|
|
} else { |
|
|
|
Name += (char)payload[char_count]; |
|
|
|
} |
|
|
|
char_count++; |
|
|
|
grabador_machine = !grabador_machine; |
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
switch (grabador_machine) { |
|
|
|
case 0 : |
|
|
|
Serial.println("\nPlace a formatted Mifare Classic NFC tag on the reader."); |
|
|
|
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()) { |
|
|
|
|
|
|
|
success2 = nfc.format(); |
|
|
|
if (success2) { |
|
|
|
Serial.println("\nSuccess, tag formatted as NDEF."); |
|
|
|
grabador_machine = 1; |
|
|
|
bool success = nfc.clean(); |
|
|
|
if (success) { |
|
|
|
Serial.println("\nSuccess, tag restored to factory state."); |
|
|
|
grabador_machine = 4; |
|
|
|
} else { |
|
|
|
Serial.println("\nFormat failed."); |
|
|
|
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"); |
|
|
|
} |
|
|
|
delay(1000); |
|
|
|
Serial.println("3_Clean RFID"); |
|
|
|
Serial.println("5_Insert Name"); |
|
|
|
|
|
|
|
Serial.print("Nombre:"); |
|
|
|
Serial.println(Name); |
|
|
|
grabador_machine = 6; |
|
|
|
break; |
|
|
|
case 1 : |
|
|
|
{ if (nfc.tagPresent()) { |
|
|
|
NdefMessage message = NdefMessage(); |
|
|
|
message.addTextRecord("Pedro Salzman", "ñ"); |
|
|
|
boolean success = nfc.write(message); |
|
|
|
if (success) { |
|
|
|
Serial.println("Success. Try reading this tag with your phone."); |
|
|
|
grabador_machine = 0; |
|
|
|
|
|
|
|
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 { |
|
|
|
Serial.println("Write failed"); |
|
|
|
Name += inByte; |
|
|
|
//Name += (char)payload[char_count];
|
|
|
|
} |
|
|
|
} |
|
|
|
delay(1000); |
|
|
|
|
|
|
|
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 2 : |
|
|
|
case 88 : |
|
|
|
|
|
|
|
for (int c = 3; c < payloadLength; c++) { |
|
|
|
Name += (char)payload[c]; |
|
|
|
@ -88,7 +167,7 @@ void loop() { |
|
|
|
default : |
|
|
|
{ |
|
|
|
Serial.println("End"); |
|
|
|
delay(11100); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
|