I am having an issue with passing an array into function which is contained in a library. I am using the Arduino IDE 16.7. If I pass a non-array/non-pointer variable than the code compiles fine. I think I have made a basic flaw with my addresses of pointers. But I am unable to see what it is
Here are the errors I am getting:
invalid conversion from 'char*' to 'uint8_t {aka unsigned char}' [-fpermissive]
initializing argument 2 of 'void EEPROMClass::write(int, uint8_t)' [-fpermissive]
Both of these errors are related to the EEPROM Arduino library I am using.
The compiler doesn't seem to agree with my passing of an array/pointer to the EEPROm library like this... Why?
H file:
#ifndef EEPROMAnyType_h
#define EEPROMAnyType_h
#include <Arduino.h>
#include <EEPROM.h>
template <class E>
class EEPROMAnyType
{
public:
int EEPROMReadAny(unsigned int addr, E x); //Reads any type of variable EEPROM
int EEPROMWriteAny(unsigned int addr, E x);//Writes any type of variable to EEPROM
// EEPROMAnyType(unsigned int addr, E x);
};
//#include "EEPROMAnyType.cpp"
#endif
CPP file:
#include <Arduino.h>
#include <EEPROM.h>
#include "EEPROMAnyType.h"
template <class E>
int EEPROMAnyType<E>::EEPROMReadAny(unsigned int addr, E x)
{
union{
byte b[sizeof(x)];
E y;//generaltype y //have a variable that has no type here(using a tempplate???)
};
int i;
x = x; //assign x to y( a variable of no type) which should be n the union
y = x;
for(i = 0; i < sizeof(y); i++){ // Why can I not declare i as an integer in the for loop?
b[i] = EEPROM.read(addr+i);
}
return i;
}
template <class E>
int EEPROMAnyType<E>::EEPROMWriteAny(unsigned int addr, E x)
{
union{
byte b[sizeof(x)];
E y;//generaltype y //have a variable that has no type here(using a tempplate???)
};
int i = 0;
y = x;
for(i = 0; i < sizeof(y); i++){
EEPROM.write(addr+i, y);
}
return i;
}
INO file(implements the library):
#include <Arduino.h>
#include <EEPROM.h>
#include <EEPROMAnyType.h>
#include <EEPROMAnyType.cpp>
int addressCharArray;
const int writes = 80;
const int memBase = 350;
unsigned int eeaddrPASS;
unsigned int eeaddrSSID;
char eePASS[writes];
char eeSSID[writes];
EEPROMAnyType<char*> eepblueString;//instantiates EEPROMANyType class
boolean check = false;
void setup(){
if (check = true){
EEPROMwifiUpdate(eeaddrPASS, eeaddrSSID, eePASS, eeSSID);
}
}
void loop(){
EEPROMwifiRead(eeaddrPASS, eeaddrSSID, eePASS, eeSSID);
}
void EEPROMwifiUpdate(unsigned int writeaddrPASS, unsigned int writeaddrSSID, char writePASS[writes], char writeSSID[writes]){
eepblueString.EEPROMWriteAny(writeaddrPASS, writePASS);
eepblueString.EEPROMWriteAny(writeaddrSSID, writeSSID);
}
void EEPROMwifiRead(unsigned int readaddrPASS, unsigned int readaddrSSID, char readPASS[writes], char readSSID[writes]){
eepblueString.EEPROMReadAny(readaddrPASS, readPASS);
eepblueString.EEPROMReadAny(readaddrSSID, readSSID);
}