From a1d0a1313d7ae0c17d7890d7da336b071726c884 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Thu, 11 May 2017 01:03:39 +0200 Subject: [PATCH] replace #define by constexpr --- examples/AccessControl/AccessControl.ino | 15 ++++++++------- examples/ChangeUID/ChangeUID.ino | 7 +++---- examples/DumpInfo/DumpInfo.ino | 4 ++-- examples/FixBrickedUID/FixBrickedUID.ino | 4 ++-- .../MifareClassicValueBlock.ino | 4 ++-- examples/MinimalInterrupt/MinimalInterrupt.ino | 6 +++--- examples/Ntag216_AUTH/Ntag216_AUTH.ino | 4 ++-- examples/RFID-Cloner/RFID-Cloner.ino | 6 +++--- examples/ReadAndWrite/ReadAndWrite.ino | 4 ++-- examples/ReadNUID/ReadNUID.ino | 4 ++-- .../ReadUidMultiReader/ReadUidMultiReader.ino | 8 ++++---- examples/firmware_check/firmware_check.ino | 4 ++-- examples/rfid_default_keys/rfid_default_keys.ino | 6 +++--- .../rfid_read_personal_data.ino | 4 ++-- .../rfid_write_personal_data.ino | 4 ++-- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/examples/AccessControl/AccessControl.ino b/examples/AccessControl/AccessControl.ino index 05f0c00..7d7aaaa 100644 --- a/examples/AccessControl/AccessControl.ino +++ b/examples/AccessControl/AccessControl.ino @@ -87,12 +87,12 @@ #define LED_OFF LOW #endif -#define redLed 7 // Set Led Pins -#define greenLed 6 -#define blueLed 5 +constexpr uint8_t redLed = 7; // Set Led Pins +constexpr uint8_t greenLed = 6; +constexpr uint8_t blueLed = 5; -#define relay 4 // Set Relay Pin -#define wipeB 3 // Button pin for WipeMode +constexpr uint8_t relay = 4; // Set Relay Pin +constexpr uint8_t wipeB = 3; // Button pin for WipeMode boolean match = false; // initialize card match to false boolean programMode = false; // initialize programming mode to false @@ -105,8 +105,9 @@ byte readCard[4]; // Stores scanned ID read from RFID Module byte masterCard[4]; // Stores master card's ID read from EEPROM // Create MFRC522 instance. -#define SS_PIN 10 -#define RST_PIN 9 +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above + MFRC522 mfrc522(SS_PIN, RST_PIN); ///////////////////////////////////////// Setup /////////////////////////////////// diff --git a/examples/ChangeUID/ChangeUID.ino b/examples/ChangeUID/ChangeUID.ino index 19315cd..fc53471 100644 --- a/examples/ChangeUID/ChangeUID.ino +++ b/examples/ChangeUID/ChangeUID.ino @@ -26,13 +26,13 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance /* Set your new UID here! */ -#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF} +byte newUid[] = {0xDE, 0xAD, 0xBE, 0xEF}; MFRC522::MIFARE_Key key; @@ -92,7 +92,6 @@ void loop() { // } // Set new UID - byte newUid[] = NEW_UID; if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) { Serial.println(F("Wrote new UID to card.")); } diff --git a/examples/DumpInfo/DumpInfo.ino b/examples/DumpInfo/DumpInfo.ino index 5cb0aaa..8ee4fc6 100644 --- a/examples/DumpInfo/DumpInfo.ino +++ b/examples/DumpInfo/DumpInfo.ino @@ -36,8 +36,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance diff --git a/examples/FixBrickedUID/FixBrickedUID.ino b/examples/FixBrickedUID/FixBrickedUID.ino index 391a252..df7a166 100644 --- a/examples/FixBrickedUID/FixBrickedUID.ino +++ b/examples/FixBrickedUID/FixBrickedUID.ino @@ -25,8 +25,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance diff --git a/examples/MifareClassicValueBlock/MifareClassicValueBlock.ino b/examples/MifareClassicValueBlock/MifareClassicValueBlock.ino index 1d78832..9df9348 100644 --- a/examples/MifareClassicValueBlock/MifareClassicValueBlock.ino +++ b/examples/MifareClassicValueBlock/MifareClassicValueBlock.ino @@ -31,8 +31,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. diff --git a/examples/MinimalInterrupt/MinimalInterrupt.ino b/examples/MinimalInterrupt/MinimalInterrupt.ino index b6ff703..a8ef898 100644 --- a/examples/MinimalInterrupt/MinimalInterrupt.ino +++ b/examples/MinimalInterrupt/MinimalInterrupt.ino @@ -29,9 +29,9 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 3 // Configurable, see typical pin layout above -#define IRQ_PIN 2 // Configurable, depends on hardware +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above +constexpr uint8_t IRQ_PIN = 2; // Configurable, depends on hardware MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. diff --git a/examples/Ntag216_AUTH/Ntag216_AUTH.ino b/examples/Ntag216_AUTH/Ntag216_AUTH.ino index fc9f22c..bad4b51 100644 --- a/examples/Ntag216_AUTH/Ntag216_AUTH.ino +++ b/examples/Ntag216_AUTH/Ntag216_AUTH.ino @@ -12,8 +12,8 @@ #include #include -#define RST_PIN 9 // -#define SS_PIN 10 // +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance diff --git a/examples/RFID-Cloner/RFID-Cloner.ino b/examples/RFID-Cloner/RFID-Cloner.ino index fc7361e..cf262ea 100644 --- a/examples/RFID-Cloner/RFID-Cloner.ino +++ b/examples/RFID-Cloner/RFID-Cloner.ino @@ -23,8 +23,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. @@ -37,7 +37,7 @@ MFRC522::MIFARE_Key key; // Number of known default keys (hard-coded) // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array -#define NR_KNOWN_KEYS 8 +constexpr uint8_t NR_KNOWN_KEYS = 8; // Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default diff --git a/examples/ReadAndWrite/ReadAndWrite.ino b/examples/ReadAndWrite/ReadAndWrite.ino index 6f7d822..10ee876 100644 --- a/examples/ReadAndWrite/ReadAndWrite.ino +++ b/examples/ReadAndWrite/ReadAndWrite.ino @@ -30,8 +30,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. diff --git a/examples/ReadNUID/ReadNUID.ino b/examples/ReadNUID/ReadNUID.ino index 9ff99da..da33211 100644 --- a/examples/ReadNUID/ReadNUID.ino +++ b/examples/ReadNUID/ReadNUID.ino @@ -31,8 +31,8 @@ #include #include -#define SS_PIN 10 -#define RST_PIN 9 +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class diff --git a/examples/ReadUidMultiReader/ReadUidMultiReader.ino b/examples/ReadUidMultiReader/ReadUidMultiReader.ino index c14c17a..1ee53d3 100644 --- a/examples/ReadUidMultiReader/ReadUidMultiReader.ino +++ b/examples/ReadUidMultiReader/ReadUidMultiReader.ino @@ -30,11 +30,11 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_1_PIN 10 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2 -#define SS_2_PIN 8 // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1 +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_1_PIN = 10; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2 +constexpr uint8_t SS_2_PIN = 8; // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1 -#define NR_OF_READERS 2 +constexpr uint8_t NR_OF_READERS = 2; byte ssPins[] = {SS_1_PIN, SS_2_PIN}; diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino index 943ce5b..cfada37 100644 --- a/examples/firmware_check/firmware_check.ino +++ b/examples/firmware_check/firmware_check.ino @@ -27,8 +27,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance diff --git a/examples/rfid_default_keys/rfid_default_keys.ino b/examples/rfid_default_keys/rfid_default_keys.ino index 78227cf..d28c771 100644 --- a/examples/rfid_default_keys/rfid_default_keys.ino +++ b/examples/rfid_default_keys/rfid_default_keys.ino @@ -28,14 +28,14 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. // Number of known default keys (hard-coded) // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array -#define NR_KNOWN_KEYS 8 +constexpr uint8_t NR_KNOWN_KEYS = 8; // Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default diff --git a/examples/rfid_read_personal_data/rfid_read_personal_data.ino b/examples/rfid_read_personal_data/rfid_read_personal_data.ino index 5271cd1..a302b45 100644 --- a/examples/rfid_read_personal_data/rfid_read_personal_data.ino +++ b/examples/rfid_read_personal_data/rfid_read_personal_data.ino @@ -22,8 +22,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance diff --git a/examples/rfid_write_personal_data/rfid_write_personal_data.ino b/examples/rfid_write_personal_data/rfid_write_personal_data.ino index 75bb2fb..72903d7 100644 --- a/examples/rfid_write_personal_data/rfid_write_personal_data.ino +++ b/examples/rfid_write_personal_data/rfid_write_personal_data.ino @@ -22,8 +22,8 @@ #include #include -#define RST_PIN 9 // Configurable, see typical pin layout above -#define SS_PIN 10 // Configurable, see typical pin layout above +constexpr uint8_t RST_PIN = 9; // Configurable, see typical pin layout above +constexpr uint8_t SS_PIN = 10; // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance