Modify int data types for cross platforms
This commit is contained in:
@@ -98,7 +98,7 @@ boolean match = false; // initialize card match to false
|
|||||||
boolean programMode = false; // initialize programming mode to false
|
boolean programMode = false; // initialize programming mode to false
|
||||||
boolean replaceMaster = false;
|
boolean replaceMaster = false;
|
||||||
|
|
||||||
int successRead; // Variable integer to keep if we have Successful Read from Reader
|
uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader
|
||||||
|
|
||||||
byte storedCard[4]; // Stores an ID read from EEPROM
|
byte storedCard[4]; // Stores an ID read from EEPROM
|
||||||
byte readCard[4]; // Stores scanned ID read from RFID Module
|
byte readCard[4]; // Stores scanned ID read from RFID Module
|
||||||
@@ -143,7 +143,7 @@ void setup() {
|
|||||||
delay(15000); // Give user enough time to cancel operation
|
delay(15000); // Give user enough time to cancel operation
|
||||||
if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
|
if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
|
||||||
Serial.println(F("Starting Wiping EEPROM"));
|
Serial.println(F("Starting Wiping EEPROM"));
|
||||||
for (int x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address
|
for (uint8_t x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address
|
||||||
if (EEPROM.read(x) == 0) { //If EEPROM address 0
|
if (EEPROM.read(x) == 0) { //If EEPROM address 0
|
||||||
// do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
|
// do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ void setup() {
|
|||||||
delay(200);
|
delay(200);
|
||||||
}
|
}
|
||||||
while (!successRead); // Program will not go further while you not get a successful read
|
while (!successRead); // Program will not go further while you not get a successful read
|
||||||
for ( int j = 0; j < 4; j++ ) { // Loop 4 times
|
for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
|
||||||
EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3
|
EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3
|
||||||
}
|
}
|
||||||
EEPROM.write(1, 143); // Write to EEPROM we defined Master Card.
|
EEPROM.write(1, 143); // Write to EEPROM we defined Master Card.
|
||||||
@@ -190,7 +190,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
Serial.println(F("-------------------"));
|
Serial.println(F("-------------------"));
|
||||||
Serial.println(F("Master Card's UID"));
|
Serial.println(F("Master Card's UID"));
|
||||||
for ( int i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM
|
for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM
|
||||||
masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard
|
masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard
|
||||||
Serial.print(masterCard[i], HEX);
|
Serial.print(masterCard[i], HEX);
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ void loop () {
|
|||||||
if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode
|
if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode
|
||||||
programMode = true;
|
programMode = true;
|
||||||
Serial.println(F("Hello Master - Entered Program Mode"));
|
Serial.println(F("Hello Master - Entered Program Mode"));
|
||||||
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
||||||
Serial.print(F("I have ")); // stores the number of ID's in EEPROM
|
Serial.print(F("I have ")); // stores the number of ID's in EEPROM
|
||||||
Serial.print(count);
|
Serial.print(count);
|
||||||
Serial.print(F(" record(s) on EEPROM"));
|
Serial.print(F(" record(s) on EEPROM"));
|
||||||
@@ -280,7 +280,7 @@ void loop () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////// Access Granted ///////////////////////////////////
|
///////////////////////////////////////// Access Granted ///////////////////////////////////
|
||||||
void granted (int setDelay) {
|
void granted ( uint16_t setDelay) {
|
||||||
digitalWrite(blueLed, LED_OFF); // Turn off blue LED
|
digitalWrite(blueLed, LED_OFF); // Turn off blue LED
|
||||||
digitalWrite(redLed, LED_OFF); // Turn off red LED
|
digitalWrite(redLed, LED_OFF); // Turn off red LED
|
||||||
digitalWrite(greenLed, LED_ON); // Turn on green LED
|
digitalWrite(greenLed, LED_ON); // Turn on green LED
|
||||||
@@ -300,7 +300,7 @@ void denied() {
|
|||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
|
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
|
||||||
int getID() {
|
uint8_t getID() {
|
||||||
// Getting ready for Reading PICCs
|
// Getting ready for Reading PICCs
|
||||||
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
|
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
|
||||||
return 0;
|
return 0;
|
||||||
@@ -312,7 +312,7 @@ int getID() {
|
|||||||
// I think we should assume every PICC as they have 4 byte UID
|
// I think we should assume every PICC as they have 4 byte UID
|
||||||
// Until we support 7 byte PICCs
|
// Until we support 7 byte PICCs
|
||||||
Serial.println(F("Scanned PICC's UID:"));
|
Serial.println(F("Scanned PICC's UID:"));
|
||||||
for (int i = 0; i < 4; i++) { //
|
for ( uint8_t i = 0; i < 4; i++) { //
|
||||||
readCard[i] = mfrc522.uid.uidByte[i];
|
readCard[i] = mfrc522.uid.uidByte[i];
|
||||||
Serial.print(readCard[i], HEX);
|
Serial.print(readCard[i], HEX);
|
||||||
}
|
}
|
||||||
@@ -370,9 +370,9 @@ void normalModeOn () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
|
//////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
|
||||||
void readID( int number ) {
|
void readID( uint8_t number ) {
|
||||||
int start = (number * 4 ) + 2; // Figure out starting position
|
uint8_t start = (number * 4 ) + 2; // Figure out starting position
|
||||||
for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
|
for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
|
||||||
storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array
|
storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,11 +380,11 @@ void readID( int number ) {
|
|||||||
///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
|
///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
|
||||||
void writeID( byte a[] ) {
|
void writeID( byte a[] ) {
|
||||||
if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
|
if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
|
||||||
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
|
uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
|
||||||
int start = ( num * 4 ) + 6; // Figure out where the next slot starts
|
uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts
|
||||||
num++; // Increment the counter by one
|
num++; // Increment the counter by one
|
||||||
EEPROM.write( 0, num ); // Write the new count to the counter
|
EEPROM.write( 0, num ); // Write the new count to the counter
|
||||||
for ( int j = 0; j < 4; j++ ) { // Loop 4 times
|
for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
|
||||||
EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
|
EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
|
||||||
}
|
}
|
||||||
successWrite();
|
successWrite();
|
||||||
@@ -403,12 +403,12 @@ void deleteID( byte a[] ) {
|
|||||||
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
|
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
|
uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
|
||||||
int slot; // Figure out the slot number of the card
|
uint8_t slot; // Figure out the slot number of the card
|
||||||
int start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
|
uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
|
||||||
int looping; // The number of times the loop repeats
|
uint8_t looping; // The number of times the loop repeats
|
||||||
int j;
|
uint8_t j;
|
||||||
int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
|
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
|
||||||
slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
|
slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
|
||||||
start = (slot * 4) + 2;
|
start = (slot * 4) + 2;
|
||||||
looping = ((num - slot) * 4);
|
looping = ((num - slot) * 4);
|
||||||
@@ -417,7 +417,7 @@ void deleteID( byte a[] ) {
|
|||||||
for ( j = 0; j < looping; j++ ) { // Loop the card shift times
|
for ( j = 0; j < looping; j++ ) { // Loop the card shift times
|
||||||
EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
|
EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
|
||||||
}
|
}
|
||||||
for ( int k = 0; k < 4; k++ ) { // Shifting loop
|
for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop
|
||||||
EEPROM.write( start + j + k, 0);
|
EEPROM.write( start + j + k, 0);
|
||||||
}
|
}
|
||||||
successDelete();
|
successDelete();
|
||||||
@@ -427,9 +427,9 @@ void deleteID( byte a[] ) {
|
|||||||
|
|
||||||
///////////////////////////////////////// Check Bytes ///////////////////////////////////
|
///////////////////////////////////////// Check Bytes ///////////////////////////////////
|
||||||
boolean checkTwo ( byte a[], byte b[] ) {
|
boolean checkTwo ( byte a[], byte b[] ) {
|
||||||
if ( a[0] != NULL ) // Make sure there is something in the array first
|
if ( a[0] != 0 ) // Make sure there is something in the array first
|
||||||
match = true; // Assume they match at first
|
match = true; // Assume they match at first
|
||||||
for ( int k = 0; k < 4; k++ ) { // Loop 4 times
|
for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times
|
||||||
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
|
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
|
||||||
match = false;
|
match = false;
|
||||||
}
|
}
|
||||||
@@ -442,9 +442,9 @@ boolean checkTwo ( byte a[], byte b[] ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////// Find Slot ///////////////////////////////////
|
///////////////////////////////////////// Find Slot ///////////////////////////////////
|
||||||
int findIDSLOT( byte find[] ) {
|
uint8_t findIDSLOT( byte find[] ) {
|
||||||
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
||||||
for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
|
for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
|
||||||
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
|
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
|
||||||
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
|
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
|
||||||
// is the same as the find[] ID card passed
|
// is the same as the find[] ID card passed
|
||||||
@@ -456,8 +456,8 @@ int findIDSLOT( byte find[] ) {
|
|||||||
|
|
||||||
///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
|
///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
|
||||||
boolean findID( byte find[] ) {
|
boolean findID( byte find[] ) {
|
||||||
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
|
||||||
for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
|
for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
|
||||||
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
|
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
|
||||||
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
|
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user