Debug de lajout d'un nouveau tag dans l'EEPROM
Ajout de la suppression de l'EEPROM d'un tag existant
This commit is contained in:
		| @@ -36,6 +36,7 @@ long red_led_timer = 0; | |||||||
|  |  | ||||||
| //byte tag1[14] = {2,52,54,48,48,57,49,48,57,56,48,53,69,3}; | //byte tag1[14] = {2,52,54,48,48,57,49,48,57,56,48,53,69,3}; | ||||||
| byte newtag[14] = EMPTY_TAG; // used for read comparisons | byte newtag[14] = EMPTY_TAG; // used for read comparisons | ||||||
|  |  | ||||||
| const byte emptytag[14] = EMPTY_TAG; | const byte emptytag[14] = EMPTY_TAG; | ||||||
| const byte unwrittentag[14] = UNWRITTEN_TAG; | const byte unwrittentag[14] = UNWRITTEN_TAG; | ||||||
|  |  | ||||||
| @@ -54,8 +55,18 @@ byte * readeepromtag(short tagnb=0) { | |||||||
|   for (int i=0; i<14; i++) |   for (int i=0; i<14; i++) | ||||||
|   { |   { | ||||||
|     tag[i]=EEPROM.read(i + tagnb*14); |     tag[i]=EEPROM.read(i + tagnb*14); | ||||||
|     //delay(2);   //small delay to avoid misreading |     //delay(1);   //small delay to avoid misreading | ||||||
|   } |   } | ||||||
|  |   //Serial.print("Tag nb "); | ||||||
|  |   //Serial.print(tagnb); | ||||||
|  |   //Serial.print(" : "); | ||||||
|  |   //for (int z = 0; z < 14 ; z++) { | ||||||
|  |   //    Serial.print(tag[z]); | ||||||
|  |   //    Serial.print(","); | ||||||
|  |   //} | ||||||
|  |   //Serial.println(""); | ||||||
|  |    | ||||||
|  |   delay(2);   //small delay to avoid misreading | ||||||
|   return tag; |   return tag; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -90,7 +101,10 @@ int findtag(byte searchtag[14]) { | |||||||
| void tagOK() { | void tagOK() { | ||||||
|   if (digitalRead(PROG_BUTTON)) |   if (digitalRead(PROG_BUTTON)) | ||||||
|   { |   { | ||||||
|     for (int z = 0; z < 14 ; z++) Serial.print(newtag[z]); |     for (int z = 0; z < 14 ; z++) { | ||||||
|  |       Serial.print(newtag[z]); | ||||||
|  |       Serial.print("."); | ||||||
|  |     } | ||||||
|     Serial.println(F(" : Accepted")); |     Serial.println(F(" : Accepted")); | ||||||
|     if (!door_state) { |     if (!door_state) { | ||||||
|       Serial.println("Ouverture..."); |       Serial.println("Ouverture..."); | ||||||
| @@ -106,7 +120,10 @@ void tagOK() { | |||||||
|  |  | ||||||
| void tagNoOK() { | void tagNoOK() { | ||||||
|   if (digitalRead(PROG_BUTTON)) { |   if (digitalRead(PROG_BUTTON)) { | ||||||
|     for (int z = 0; z < 14 ; z++) Serial.print(newtag[z]); |     for (int z = 0; z < 14 ; z++) { | ||||||
|  |       Serial.print(newtag[z]); | ||||||
|  |       Serial.print("."); | ||||||
|  |     } | ||||||
|     Serial.println(F(" : Rejected")); |     Serial.println(F(" : Rejected")); | ||||||
|     digitalWrite(RED_LED, HIGH); |     digitalWrite(RED_LED, HIGH); | ||||||
|     //Light the red LED for 1s |     //Light the red LED for 1s | ||||||
| @@ -180,14 +197,14 @@ void updateDoor() { | |||||||
|      servo_pos += SERVO_SPEED; |      servo_pos += SERVO_SPEED; | ||||||
|      door_servo.attach(SERVO_CTRL); |      door_servo.attach(SERVO_CTRL); | ||||||
|      door_servo.write(servo_pos); |      door_servo.write(servo_pos); | ||||||
|      Serial.print(F("Door : opening ")); |      //Serial.print(F("Door : opening ")); | ||||||
|      Serial.println(servo_pos); |      //Serial.println(servo_pos); | ||||||
|     } |     } | ||||||
|     //Check opened-door timer |     //Check opened-door timer | ||||||
|     if (millis() < door_timer) |     if (millis() < door_timer) | ||||||
|     { |     { | ||||||
|       Serial.print(F("Door timer :")); |       //Serial.print(F("Door timer :")); | ||||||
|       Serial.println(door_timer - millis()); |       //Serial.println(door_timer - millis()); | ||||||
|     } |     } | ||||||
|     else if (!door_move) |     else if (!door_move) | ||||||
|     { |     { | ||||||
| @@ -212,8 +229,8 @@ void updateDoor() { | |||||||
|      servo_pos -= SERVO_SPEED; |      servo_pos -= SERVO_SPEED; | ||||||
|      door_servo.attach(SERVO_CTRL); |      door_servo.attach(SERVO_CTRL); | ||||||
|      door_servo.write(servo_pos); |      door_servo.write(servo_pos); | ||||||
|      Serial.print(F("Door : closing ")); |      //Serial.print(F("Door : closing ")); | ||||||
|      Serial.println(servo_pos); |      //Serial.println(servo_pos); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -222,8 +239,8 @@ void updateRedLED() { | |||||||
|   //Check the redLED timer and turn ON or OFF the LED |   //Check the redLED timer and turn ON or OFF the LED | ||||||
|   if (millis() < red_led_timer) { |   if (millis() < red_led_timer) { | ||||||
|     digitalWrite(RED_LED, HIGH); |     digitalWrite(RED_LED, HIGH); | ||||||
|     Serial.print(F("Red LED timer : ")); | //    Serial.print(F("Red LED timer : ")); | ||||||
|     Serial.println(red_led_timer - millis()); | //    Serial.println(red_led_timer - millis()); | ||||||
|   } |   } | ||||||
|   else digitalWrite(RED_LED, LOW); |   else digitalWrite(RED_LED, LOW); | ||||||
| } | } | ||||||
| @@ -253,19 +270,43 @@ void addNewTag(byte tag[14]) { | |||||||
|   Serial.print(F("New tag number : ")); |   Serial.print(F("New tag number : ")); | ||||||
|   Serial.println(tagnb); |   Serial.println(tagnb); | ||||||
|   Serial.print(F("Writing...")); |   Serial.print(F("Writing...")); | ||||||
|   for (int z = 0; z < 14 ; z++) EEPROM.write(z+tagnb, tag[z]); |   for (int z = 0; z < 14 ; z++) { | ||||||
|  |     EEPROM.write(z+(tagnb*14), tag[z]); | ||||||
|  |   } | ||||||
|   Serial.print(F("  Checking...")); |   Serial.print(F("  Checking...")); | ||||||
|   byte tmptag[14]; |   int tmp = findtag(tag); | ||||||
|   for (int z = 0; z < 14 ; z++) tmptag[z]=EEPROM.read(tag[z+tagnb]); |   if (tmp != -1 and tmp == tagnb) { | ||||||
|   if (comparetag(tmptag, tag)) Serial.println("OK"); |     Serial.println("OK"); | ||||||
|   else Serial.println("Failed"); |   } | ||||||
|  |   else { | ||||||
|  |     Serial.println("Failed"); | ||||||
|  |   } | ||||||
|    |    | ||||||
| } | } | ||||||
|  |  | ||||||
| void delTag(byte tag[14]) { | void delTag(byte tag[14]) { | ||||||
|   Serial.print(F("Deleting tag from EEPROM : ")); |   Serial.print(F("Deleting tag from EEPROM : ")); | ||||||
|   for (int z = 0; z < 14 ; z++) Serial.print(tag[z]); |   for (int z = 0; z < 14 ; z++) { | ||||||
|  |     Serial.print(tag[z]); | ||||||
|  |   } | ||||||
|   Serial.println(""); |   Serial.println(""); | ||||||
|  |  | ||||||
|  |   int tagnb = findtag(tag); | ||||||
|  |   Serial.print("Tag number "); | ||||||
|  |   Serial.println(tagnb); | ||||||
|  |  | ||||||
|  |   Serial.print(F("Writing zeros...")); | ||||||
|  |   for (int z = 0; z < 14 ; z++) { | ||||||
|  |     EEPROM.write(z+(tagnb*14), 0); | ||||||
|  |   } | ||||||
|  |   Serial.print(F("  Checking...")); | ||||||
|  |   int tmptag = readeepromtag(tagnb); | ||||||
|  |   if (comparetag(tmptag, emptytag)) { | ||||||
|  |     Serial.println("OK"); | ||||||
|  |   } | ||||||
|  |   else { | ||||||
|  |     Serial.println("Failed"); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| void setup() { | void setup() { | ||||||
| @@ -294,20 +335,6 @@ void setup() { | |||||||
|   Serial.println(findtag(newtag)); |   Serial.println(findtag(newtag)); | ||||||
|   Serial.println(findtag(unwrittentag)); |   Serial.println(findtag(unwrittentag)); | ||||||
|  |  | ||||||
| //  for(byte n=0; n<maxeepromtags(); n++) |  | ||||||
| //  { |  | ||||||
| //    Serial.print(F("Tag n°")); |  | ||||||
| //    Serial.print(n); |  | ||||||
| //    Serial.print(": "); |  | ||||||
| //    byte *t; |  | ||||||
| //    t=readeepromtag(n); |  | ||||||
| //    for (int z = 0; z < 14 ; z++)  |  | ||||||
| //    { |  | ||||||
| //      Serial.print(t[z]); |  | ||||||
| //      Serial.print(","); |  | ||||||
| //    } |  | ||||||
| //    Serial.println(""); |  | ||||||
| //  } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void loop() { | void loop() { | ||||||
| @@ -319,5 +346,5 @@ void loop() { | |||||||
|    |    | ||||||
|   updateRedLED(); |   updateRedLED(); | ||||||
|    |    | ||||||
|   //delay(10); |   delay(10); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user