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:
Pierrick C 2017-09-24 19:03:04 +02:00
parent 5e2c3d652f
commit e612150f01
1 changed files with 59 additions and 32 deletions

View File

@ -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 newtag[14] = EMPTY_TAG; // used for read comparisons
const byte emptytag[14] = EMPTY_TAG;
const byte unwrittentag[14] = UNWRITTEN_TAG;
@ -54,8 +55,18 @@ byte * readeepromtag(short tagnb=0) {
for (int i=0; i<14; i++)
{
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;
}
@ -90,7 +101,10 @@ int findtag(byte searchtag[14]) {
void tagOK() {
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"));
if (!door_state) {
Serial.println("Ouverture...");
@ -106,7 +120,10 @@ void tagOK() {
void tagNoOK() {
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"));
digitalWrite(RED_LED, HIGH);
//Light the red LED for 1s
@ -180,14 +197,14 @@ void updateDoor() {
servo_pos += SERVO_SPEED;
door_servo.attach(SERVO_CTRL);
door_servo.write(servo_pos);
Serial.print(F("Door : opening "));
Serial.println(servo_pos);
//Serial.print(F("Door : opening "));
//Serial.println(servo_pos);
}
//Check opened-door timer
if (millis() < door_timer)
{
Serial.print(F("Door timer :"));
Serial.println(door_timer - millis());
//Serial.print(F("Door timer :"));
//Serial.println(door_timer - millis());
}
else if (!door_move)
{
@ -212,8 +229,8 @@ void updateDoor() {
servo_pos -= SERVO_SPEED;
door_servo.attach(SERVO_CTRL);
door_servo.write(servo_pos);
Serial.print(F("Door : closing "));
Serial.println(servo_pos);
//Serial.print(F("Door : closing "));
//Serial.println(servo_pos);
}
}
}
@ -222,8 +239,8 @@ void updateRedLED() {
//Check the redLED timer and turn ON or OFF the LED
if (millis() < red_led_timer) {
digitalWrite(RED_LED, HIGH);
Serial.print(F("Red LED timer : "));
Serial.println(red_led_timer - millis());
// Serial.print(F("Red LED timer : "));
// Serial.println(red_led_timer - millis());
}
else digitalWrite(RED_LED, LOW);
}
@ -253,19 +270,43 @@ void addNewTag(byte tag[14]) {
Serial.print(F("New tag number : "));
Serial.println(tagnb);
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..."));
byte tmptag[14];
for (int z = 0; z < 14 ; z++) tmptag[z]=EEPROM.read(tag[z+tagnb]);
if (comparetag(tmptag, tag)) Serial.println("OK");
else Serial.println("Failed");
int tmp = findtag(tag);
if (tmp != -1 and tmp == tagnb) {
Serial.println("OK");
}
else {
Serial.println("Failed");
}
}
void delTag(byte tag[14]) {
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("");
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() {
@ -294,20 +335,6 @@ void setup() {
Serial.println(findtag(newtag));
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() {
@ -319,5 +346,5 @@ void loop() {
updateRedLED();
//delay(10);
delay(10);
}