Pages: [1]   Go Down
Author Topic: EEPROMEx library not behaiving as expected  (Read 399 times)
0 Members and 1 Guest are viewing this topic.
Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to implement the EEPROMEx libray and run into a problem.
(http://playground.arduino.cc/Code/EEPROMLoadAndSaveSettings)
In my setup() if want to see if there is a software change:
Code:
#include <Streaming.h>
#include <SoftwareSerial.h>
#define SOFTWARE_VERSION "0.1"
const int maxAllowedWrites = 200;
const int memBase = 0;
const int memCeiling = EEPROMSizeATmega328;
boolean OK = true;
int configAdress = 0;

void setup() {
  configAdress  = EEPROM.getAddress(sizeof(StoreStruct)); // Size of config object
  OK = loadConfig();    // Try to load config
  if(OK) {
           Serial << "Config load" << endl;
           }  // If version are same resume
  else   {
          saveConfig();
          Serial << "Config save" << endl;
          }  // else save defaults and use them

}
And the two routines from that example adjusted to my enviroment:
Code:
bool loadConfig() {
  EEPROM.readBlock(configAdress, confValue);
// for debug only
  Serial << SOFTWARE_VERSION << endl;
  Serial << confValue.softwareVersion << endl;
//
  return (confValue.softwareVersion == SOFTWARE_VERSION);
}

void saveConfig() {
   EEPROM.writeBlock(configAdress, confValue);
}

Althoug both version are the same, saveConfig() is called always.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Althoug both version are the same, saveConfig() is called always.
Correctly, too, I'm almost certain.

Where/how is your structure defined?

Quote
  return (confValue.softwareVersion == SOFTWARE_VERSION);
If softwareVersion in the struct is an array or a pointer, that array address or pointer will never be equal to "0.1".

You could use strcmp() to see if the two strings are the same. The addresses certainly aren't.
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 187
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
bool loadConfig() {
  EEPROM.readBlock(configAdress, confValue);
// for debug only
  Serial << SOFTWARE_VERSION << endl;
  Serial << confValue.softwareVersion << endl;
//
  return (confValue.softwareVersion == SOFTWARE_VERSION);
}

Yep, because of this

Quote
return (confValue.softwareVersion == SOFTWARE_VERSION);

put this line against the above

Code:
return strcmp(confValue.softwareVersion, "0.1")

will solve the issue.

Edit: during typing PaulS already mention that
« Last Edit: March 13, 2013, 06:04:31 am by Cybernetician » Logged

From Idea To Invention

Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok will try that later. If correct the example is wrong.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If correct the example is wrong.
No. The example is comparing one character at time, not the whole string at once like you are trying to.
Logged

Enschede, Netherlands
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now i am puzzled. The example shows :
Code:
void setup() {
OK = loadConfig;
}

void loop() { }

bool loadConfig() {
  EEPROM.readBlock(configAdress, confValue);
  return (confValue.softwareVersion == SOFTWARE_VERSION);
}
So  the result of loadConfig() could be false or true but if i understand you correct this isnt so.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The example shows
If the example really shows assigning the address of a function to OK, it is wrong in more that one way.

Ignore it. You know the right way to do what you want.
Logged

Pages: [1]   Go Up
Jump to: