I am having an issue after a reset reading back the data stored by the EDB library. I made a slight modification to the example sketch to show the error I am seeing.
Example Sketch
/*
EDB_Simple.pde
Extended Database Library + Internal Arduino EEPROM Demo Sketch
The Extended Database library project page is here:
*/
#include "WProgram.h"
#include <EDB.h>
// Use the Internal Arduino EEPROM as storage
#include <EEPROM.h>
// Uncomment the line appropriate for your platform
#define TABLE_SIZE 512 // Arduino 168 or greater
// The number of demo records that should be created. This should be less
// than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent). If it is higher,
// operations will return EDB_OUT_OF_RANGE for all records outside the usable range.
#define RECORDS_TO_CREATE 10
// Arbitrary record definition for this table.
// This should be modified to reflect your record needs.
struct LogEvent {
char something[50];
char something2[8];
int id;
int temperature;
}
logEvent;
// The read and write handlers for using the EEPROM Library
void writer(unsigned long address, byte data)
{
EEPROM.write(address, data);
}
byte reader(unsigned long address)
{
return EEPROM.read(address);
}
// Create an EDB object with the appropriate write and read handlers
EDB db(&writer, &reader);
void setup()
{
Serial.begin(9600);
Serial.println("Extended Database Library + Arduino Internal EEPROM Demo");
Serial.println();
//db.create(0, TABLE_SIZE, sizeof(logEvent));
db.open(0);
Serial.print("Record Count: "); Serial.println(db.count());
Serial.println("Creating Records...");
int recno;
Serial.print("Record Count: "); Serial.println(db.count());
for (recno = 1; recno < RECORDS_TO_CREATE; recno++)
{
db.readRec(recno, EDB_REC logEvent);
Serial.print("ID: "); Serial.println(logEvent.id);
Serial.print("Temp: "); Serial.println(logEvent.temperature);
Serial.print("1: "); Serial.println(logEvent.something);
Serial.print("2: "); Serial.println(logEvent.something2);
}
db.clear();
db.create(0, TABLE_SIZE, sizeof(logEvent));
for (recno = 1; recno <= RECORDS_TO_CREATE; recno++)
{
logEvent.id = recno;
logEvent.temperature = recno * 2;
strcpy(logEvent.something, "some test data that is long");
strcpy(logEvent.something2, "test2");
db.appendRec(EDB_REC logEvent);
}
Serial.print("Record Count: "); Serial.println(db.count());
for (recno = 1; recno < RECORDS_TO_CREATE; recno++)
{
db.readRec(recno, EDB_REC logEvent);
Serial.print("ID: "); Serial.println(logEvent.id);
Serial.print("Temp: "); Serial.println(logEvent.temperature);
Serial.print("1: "); Serial.println(logEvent.something);
Serial.print("2: "); Serial.println(logEvent.something2);
}
}
void loop()
{
}
Output after upload then pressing reset once.
Extended Database Library + Arduino Internal EEPROM Demo
Record Count: 0
Creating Records...
Record Count: 0
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
ID: 0
Temp: 0
1:
2:
Record Count: 8
ID: 1
Temp: 2
1: some test data that is long
2: test2
ID: 2
Temp: 4
1: some test data that is long
2: test2
ID: 3
Temp: 6
1: some test data that is long
2: test2
ID: 4
Temp: 8
1: some test data that is long
2: test2
ID: 5
Temp: 10
1: some test data that is long
2: test2
ID: 6
Temp: 12
1: some test data that is long
2: test2
ID: 7
Temp: 14
1: some test data that is long
2: test2
ID: 8
Temp: 16
1: some test data that is long
2: test2
ID: 8
Temp: 16
1: some test data that is long
2: test2
Reset button pressed here
Extended Database Library + Arduino Internal EEPROM Demo
Record Count: 8
Creating Records...
Record Count: 8
ID: 0
Temp: 25972
1:
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
ID: 0
Temp: 25972
1: st2
2:
Record Count: 8
ID: 1
Temp: 2
1: some test data that is long
2: test2
ID: 2
Temp: 4
1: some test data that is long
2: test2
ID: 3
Temp: 6
1: some test data that is long
2: test2
ID: 4
Temp: 8
1: some test data that is long
2: test2
ID: 5
Temp: 10
1: some test data that is long
2: test2
ID: 6
Temp: 12
1: some test data that is long
2: test2
ID: 7
Temp: 14
1: some test data that is long
2: test2
ID: 8
Temp: 16
1: some test data that is long
2: test2
ID: 8
Temp: 16
1: some test data that is long
2: test2