EEPROMWearLevel icon indicating copy to clipboard operation
EEPROMWearLevel copied to clipboard

A functionality difference between original and EEPROMWearLevel

Open Janovlk opened this issue 1 year ago • 0 comments

Hello,

Here is a testing sketch:

#include <EEPROMWearLevel.h>

#define EEPROM_LAYOUT_VERSION 1
#define AMOUNT_OF_INDEXES 2
#define Variables_VAR1 0
#define Array_VAR2 1 

char Array[25];
char ArrayCopy1[25];
char ArrayCopy2[25];

struct VARIABLES {
  uint16_t number;
  char name[25];
};
VARIABLES Variables;
VARIABLES VariablesCopy;


void setup() {
  Serial.begin(115200);
  strcpy(Variables.name, "Testing string 1.");
  strcpy(Array, "Testing string 2.");
  Variables.number = 3512;

  EEPROMwl.begin(EEPROM_LAYOUT_VERSION, AMOUNT_OF_INDEXES);

  EEPROMwl.put(Variables_VAR1, Variables);
  EEPROMwl.put(Array_VAR2, Array);
  EEPROM.put(0, Array);

  EEPROMwl.get(Array_VAR2, ArrayCopy1);  // The crucial line.

  EEPROMwl.get(Variables_VAR1, VariablesCopy);
  EEPROM.get(0, ArrayCopy2);
  
  Serial.print("Variable number: ");
  Serial.println(VariablesCopy.number);
  Serial.print("Variable name: ");
  Serial.println(VariablesCopy.name);
  Serial.print("Array Copy 1: ");
  Serial.println(ArrayCopy1);

  Serial.print("Array Copy 2: ");
  Serial.println(ArrayCopy2);


}

void loop() {

}

The sketch compiles with the error: "invalid array assignment". When I comment out "the crucial line", it will work. Of course, the ArrayCopy1 character array then remains empty. So there is a difference between the original EEPROM functionality in Arduino and your implementation. As you can see, when I "stash" the character array into a structure, it will work with EEPROMWearLevel.

When I change "the crucial line" to:

  EEPROMwl.get(Array_VAR2, ArrayCopy1[25]);

the sketch will compile. (With any number between the brackets.) The character array ArrayCopy1 will remain empty, which is expected behavior.

Did I make a mistake or is it a difference in your implementation of EEPROM?

Thank you for your work.

PP

Janovlk avatar Nov 05 '24 00:11 Janovlk