MAJ Firmware pour Identification par Pilote
This commit is contained in:
parent
0d4df4c0fc
commit
08c0d2a9d9
72
src/main.cpp
72
src/main.cpp
|
@ -11,40 +11,17 @@ String SerialCMD;
|
||||||
/**
|
/**
|
||||||
* Helper routine to dump a byte array as hex values to Serial.
|
* Helper routine to dump a byte array as hex values to Serial.
|
||||||
*/
|
*/
|
||||||
void dump_byte_array(byte *buffer, byte bufferSize) {
|
void dump_byte_array(byte *buffer, byte bufferSize)
|
||||||
for (byte i = 0; i < bufferSize; i++) {
|
{
|
||||||
|
for (byte i = 0; i < bufferSize; i++)
|
||||||
|
{
|
||||||
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
|
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
|
||||||
Serial.print(buffer[i], HEX);
|
Serial.print(buffer[i], HEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void serialprint_rfid_uid()
|
||||||
* Initialize.
|
{
|
||||||
*/
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
Serial.begin(9600); // Initialize serial communications with the PC
|
|
||||||
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
|
|
||||||
|
|
||||||
SPI.begin(); // Init SPI bus
|
|
||||||
|
|
||||||
mfrc522.PCD_Init(SS_1_PIN, RST_PIN); // Init each MFRC522 card
|
|
||||||
Serial.print(F("Reader "));
|
|
||||||
Serial.print(F(": "));
|
|
||||||
mfrc522.PCD_DumpVersionToSerial();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main loop.
|
|
||||||
*/
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
if (Serial.available() > 0) {
|
|
||||||
SerialCMD = Serial.readString();
|
|
||||||
SerialCMD.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mfrc522.PICC_IsNewCardPresent() || SerialCMD.startsWith("READ") ) && mfrc522.PICC_ReadCardSerial()) {
|
|
||||||
Serial.print(F("R#"));
|
Serial.print(F("R#"));
|
||||||
// Show some details of the PICC (that is: the tag/card)
|
// Show some details of the PICC (that is: the tag/card)
|
||||||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
||||||
|
@ -54,13 +31,44 @@ void loop() {
|
||||||
Serial.print(piccType, HEX);
|
Serial.print(piccType, HEX);
|
||||||
Serial.print(F("#"));
|
Serial.print(F("#"));
|
||||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize.
|
||||||
|
*/
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
|
||||||
|
Serial.begin(9600); // Initialize serial communications with the PC
|
||||||
|
while (!Serial)
|
||||||
|
; // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
|
||||||
|
|
||||||
|
SPI.begin(); // Init SPI bus
|
||||||
|
|
||||||
|
mfrc522.PCD_Init(SS_1_PIN, RST_PIN); // Init each MFRC522 card
|
||||||
|
Serial.print(F("AT168RC522#Reader#"));
|
||||||
|
mfrc522.PCD_DumpVersionToSerial();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main loop.
|
||||||
|
*/
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Serial.available() > 0)
|
||||||
|
{
|
||||||
|
SerialCMD = Serial.readString();
|
||||||
|
SerialCMD.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
|
||||||
|
{
|
||||||
|
serialprint_rfid_uid();
|
||||||
// Halt PICC
|
// Halt PICC
|
||||||
mfrc522.PICC_HaltA();
|
mfrc522.PICC_HaltA();
|
||||||
// Stop encryption on PCD
|
// Stop encryption on PCD
|
||||||
mfrc522.PCD_StopCrypto1();
|
mfrc522.PCD_StopCrypto1();
|
||||||
|
}
|
||||||
|
|
||||||
//Reset SerialCMD
|
|
||||||
SerialCMD = "";
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue