use F() Macro to move strings to ProgMem

This commit is contained in:
Lorne Bonnell
2015-02-02 08:42:32 +10:00
parent 4bbc8eb46a
commit 5b148a2e72

View File

@@ -1152,7 +1152,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
MIFARE_Key key; MIFARE_Key key;
// UID // UID
Serial.print("Card UID:"); Serial.print(F("Card UID:"));
for (byte i = 0; i < uid->size; i++) { for (byte i = 0; i < uid->size; i++) {
Serial.print(uid->uidByte[i] < 0x10 ? " 0" : " "); Serial.print(uid->uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(uid->uidByte[i], HEX); Serial.print(uid->uidByte[i], HEX);
@@ -1161,7 +1161,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
// PICC type // PICC type
byte piccType = PICC_GetType(uid->sak); byte piccType = PICC_GetType(uid->sak);
Serial.print("PICC type: "); Serial.print(F("PICC type: "0);
Serial.println(PICC_GetTypeName(piccType)); Serial.println(PICC_GetTypeName(piccType));
// Dump contents // Dump contents
@@ -1184,7 +1184,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
case PICC_TYPE_ISO_18092: case PICC_TYPE_ISO_18092:
case PICC_TYPE_MIFARE_PLUS: case PICC_TYPE_MIFARE_PLUS:
case PICC_TYPE_TNP3XXX: case PICC_TYPE_TNP3XXX:
Serial.println("Dumping memory contents not implemented for that PICC type."); Serial.println(F("Dumping memory contents not implemented for that PICC type."));
break; break;
case PICC_TYPE_UNKNOWN: case PICC_TYPE_UNKNOWN:
@@ -1228,7 +1228,7 @@ void MFRC522::PICC_DumpMifareClassicToSerial( Uid *uid, ///< Pointer to Uid str
// Dump sectors, highest address first. // Dump sectors, highest address first.
if (no_of_sectors) { if (no_of_sectors) {
Serial.println("Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits"); Serial.println(F("Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits"));
for (char i = no_of_sectors - 1; i >= 0; i--) { for (char i = no_of_sectors - 1; i >= 0; i--) {
PICC_DumpMifareClassicSectorToSerial(uid, key, i); PICC_DumpMifareClassicSectorToSerial(uid, key, i);
} }
@@ -1290,20 +1290,20 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
if (isSectorTrailer) { if (isSectorTrailer) {
Serial.print(sector < 10 ? " " : " "); // Pad with spaces Serial.print(sector < 10 ? " " : " "); // Pad with spaces
Serial.print(sector); Serial.print(sector);
Serial.print(" "); Serial.print(F(" "));
} }
else { else {
Serial.print(" "); Serial.print(F(" "));
} }
// Block number // Block number
Serial.print(blockAddr < 10 ? " " : (blockAddr < 100 ? " " : " ")); // Pad with spaces Serial.print(blockAddr < 10 ? " " : (blockAddr < 100 ? " " : " ")); // Pad with spaces
Serial.print(blockAddr); Serial.print(blockAddr);
Serial.print(" "); Serial.print(F(" "));
// Establish encrypted communications before reading the first block // Establish encrypted communications before reading the first block
if (isSectorTrailer) { if (isSectorTrailer) {
status = PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid); status = PCD_Authenticate(PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("PCD_Authenticate() failed: "); Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
return; return;
} }
@@ -1312,7 +1312,7 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
byteCount = sizeof(buffer); byteCount = sizeof(buffer);
status = MIFARE_Read(blockAddr, buffer, &byteCount); status = MIFARE_Read(blockAddr, buffer, &byteCount);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("MIFARE_Read() failed: "); Serial.print(F("MIFARE_Read() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
continue; continue;
} }
@@ -1321,7 +1321,7 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
Serial.print(buffer[index] < 0x10 ? " 0" : " "); Serial.print(buffer[index] < 0x10 ? " 0" : " ");
Serial.print(buffer[index], HEX); Serial.print(buffer[index], HEX);
if ((index % 4) == 3) { if ((index % 4) == 3) {
Serial.print(" "); Serial.print(F(" "));
} }
} }
// Parse sector trailer data // Parse sector trailer data
@@ -1352,20 +1352,20 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
if (firstInGroup) { if (firstInGroup) {
// Print access bits // Print access bits
Serial.print(" [ "); Serial.print(F(" [ "));
Serial.print((g[group] >> 2) & 1, DEC); Serial.print(" "); Serial.print((g[group] >> 2) & 1, DEC); Serial.print(" ");
Serial.print((g[group] >> 1) & 1, DEC); Serial.print(" "); Serial.print((g[group] >> 1) & 1, DEC); Serial.print(" ");
Serial.print((g[group] >> 0) & 1, DEC); Serial.print((g[group] >> 0) & 1, DEC);
Serial.print(" ] "); Serial.print(F(" ] "));
if (invertedError) { if (invertedError) {
Serial.print(" Inverted access bits did not match! "); Serial.print(F(" Inverted access bits did not match! "));
} }
} }
if (group != 3 && (g[group] == 1 || g[group] == 6)) { // Not a sector trailer, a value block if (group != 3 && (g[group] == 1 || g[group] == 6)) { // Not a sector trailer, a value block
long value = (long(buffer[3])<<24) | (long(buffer[2])<<16) | (long(buffer[1])<<8) | long(buffer[0]); long value = (long(buffer[3])<<24) | (long(buffer[2])<<16) | (long(buffer[1])<<8) | long(buffer[0]);
Serial.print(" Value=0x"); Serial.print(value, HEX); Serial.print(F(" Value=0x")); Serial.print(value, HEX);
Serial.print(" Adr=0x"); Serial.print(buffer[12], HEX); Serial.print(F(" Adr=0x")); Serial.print(buffer[12], HEX);
} }
Serial.println(); Serial.println();
} }
@@ -1382,14 +1382,14 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() {
byte buffer[18]; byte buffer[18];
byte i; byte i;
Serial.println("Page 0 1 2 3"); Serial.println(F("Page 0 1 2 3"));
// Try the mpages of the original Ultralight. Ultralight C has more pages. // Try the mpages of the original Ultralight. Ultralight C has more pages.
for (byte page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time. for (byte page = 0; page < 16; page +=4) { // Read returns data for 4 pages at a time.
// Read pages // Read pages
byteCount = sizeof(buffer); byteCount = sizeof(buffer);
status = MIFARE_Read(page, buffer, &byteCount); status = MIFARE_Read(page, buffer, &byteCount);
if (status != STATUS_OK) { if (status != STATUS_OK) {
Serial.print("MIFARE_Read() failed: "); Serial.print(F("MIFARE_Read() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
break; break;
} }
@@ -1398,7 +1398,7 @@ void MFRC522::PICC_DumpMifareUltralightToSerial() {
i = page + offset; i = page + offset;
Serial.print(i < 10 ? " " : " "); // Pad with spaces Serial.print(i < 10 ? " " : " "); // Pad with spaces
Serial.print(i); Serial.print(i);
Serial.print(" "); Serial.print(F(" "));
for (byte index = 0; index < 4; index++) { for (byte index = 0; index < 4; index++) {
i = 4 * offset + index; i = 4 * offset + index;
Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i] < 0x10 ? " 0" : " ");
@@ -1458,19 +1458,19 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) {
byte status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 40 byte status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 40
if( status != STATUS_OK ) { if( status != STATUS_OK ) {
if( logErrors ) { if( logErrors ) {
Serial.println("Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?"); Serial.println(F("Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one?"));
Serial.print("Error name: "); Serial.print(F("Error name: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;
} }
if ( received != 1 || response[0] != 0x0A ) { if ( received != 1 || response[0] != 0x0A ) {
if ( logErrors ) { if ( logErrors ) {
Serial.print("Got bad response on backdoor 0x40 command: "); Serial.print(F("Got bad response on backdoor 0x40 command: "));
Serial.print(response[0], HEX); Serial.print(response[0], HEX);
Serial.print(" ("); Serial.print(F(" ("));
Serial.print(validBits); Serial.print(validBits);
Serial.print(" valid bits)\r\n"); Serial.print(F(" valid bits)\r\n"));
} }
return false; return false;
} }
@@ -1480,19 +1480,19 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) {
status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 43 status = PCD_TransceiveData(&cmd, (byte)1, response, &received, &validBits, (byte)0, false); // 43
if( status != STATUS_OK ) { if( status != STATUS_OK ) {
if( logErrors ) { if( logErrors ) {
Serial.println("Error in communication at command 0x43, after successfully executing 0x40"); Serial.println(F("Error in communication at command 0x43, after successfully executing 0x40"));
Serial.print("Error name: "); Serial.print(F("Error name: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;
} }
if ( received != 1 || response[0] != 0x0A ) { if ( received != 1 || response[0] != 0x0A ) {
if ( logErrors ) { if ( logErrors ) {
Serial.print("Got bad response on backdoor 0x43 command: "); Serial.print(F("Got bad response on backdoor 0x43 command: "));
Serial.print(response[0], HEX); Serial.print(response[0], HEX);
Serial.print(" ("); Serial.print(F(" ("));
Serial.print(validBits); Serial.print(validBits);
Serial.print(" valid bits)\r\n"); Serial.print(F(" valid bits)\r\n"));
} }
return false; return false;
} }
@@ -1514,7 +1514,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
// UID + BCC byte can not be larger than 16 together // UID + BCC byte can not be larger than 16 together
if ( !newUid || !uidSize || uidSize > 15) { if ( !newUid || !uidSize || uidSize > 15) {
if ( logErrors ) { if ( logErrors ) {
Serial.println("New UID buffer empty, size 0, or size > 15 given"); Serial.println(F("New UID buffer empty, size 0, or size > 15 given"));
} }
return false; return false;
} }
@@ -1533,7 +1533,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
// PICC_WakeupA(atqa_answer, &atqa_size); // PICC_WakeupA(atqa_answer, &atqa_size);
if ( !PICC_IsNewCardPresent() || !PICC_ReadCardSerial() ) { if ( !PICC_IsNewCardPresent() || !PICC_ReadCardSerial() ) {
Serial.println("No card was previously selected, and none are available. Failed to set UID."); Serial.println(F("No card was previously selected, and none are available. Failed to set UID."));
return false; return false;
} }
@@ -1541,7 +1541,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
if ( status != STATUS_OK ) { if ( status != STATUS_OK ) {
// We tried, time to give up // We tried, time to give up
if ( logErrors ) { if ( logErrors ) {
Serial.println("Failed to authenticate to card for reading, could not set UID: "); Serial.println(F("Failed to authenticate to card for reading, could not set UID: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;
@@ -1549,7 +1549,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
} }
else { else {
if ( logErrors ) { if ( logErrors ) {
Serial.print("PCD_Authenticate() failed: "); Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;
@@ -1562,9 +1562,9 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
status = MIFARE_Read((byte)0, block0_buffer, &byteCount); status = MIFARE_Read((byte)0, block0_buffer, &byteCount);
if ( status != STATUS_OK ) { if ( status != STATUS_OK ) {
if ( logErrors ) { if ( logErrors ) {
Serial.print("MIFARE_Read() failed: "); Serial.print(F("MIFARE_Read() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
Serial.println("Are you sure your KEY A for sector 0 is 0xFFFFFFFFFFFF?"); Serial.println(F("Are you sure your KEY A for sector 0 is 0xFFFFFFFFFFFF?"));
} }
return false; return false;
} }
@@ -1585,7 +1585,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
// Activate UID backdoor // Activate UID backdoor
if ( !MIFARE_OpenUidBackdoor(logErrors) ) { if ( !MIFARE_OpenUidBackdoor(logErrors) ) {
if ( logErrors ) { if ( logErrors ) {
Serial.println("Activating the UID backdoor failed."); Serial.println(F("Activating the UID backdoor failed."));
} }
return false; return false;
} }
@@ -1594,7 +1594,7 @@ bool MFRC522::MIFARE_SetUid(byte* newUid, byte uidSize, bool logErrors) {
status = MIFARE_Write((byte)0, block0_buffer, (byte)16); status = MIFARE_Write((byte)0, block0_buffer, (byte)16);
if (status != STATUS_OK) { if (status != STATUS_OK) {
if ( logErrors ) { if ( logErrors ) {
Serial.print("MIFARE_Write() failed: "); Serial.print(F("MIFARE_Write() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;
@@ -1620,7 +1620,7 @@ bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
byte status = MIFARE_Write((byte)0, block0_buffer, (byte)16); byte status = MIFARE_Write((byte)0, block0_buffer, (byte)16);
if (status != STATUS_OK) { if (status != STATUS_OK) {
if ( logErrors ) { if ( logErrors ) {
Serial.print("MIFARE_Write() failed: "); Serial.print(F("MIFARE_Write() failed: "));
Serial.println(GetStatusCodeName(status)); Serial.println(GetStatusCodeName(status));
} }
return false; return false;