first commit
This commit is contained in:
56
ESP8266_DOMOTICZ_OCTOPRINT_WEB/Eeprom.cpp
Executable file
56
ESP8266_DOMOTICZ_OCTOPRINT_WEB/Eeprom.cpp
Executable file
@@ -0,0 +1,56 @@
|
||||
#include "Eeprom.h"
|
||||
|
||||
Eeprom::Eeprom()
|
||||
{
|
||||
// EEPROM.begin(512);
|
||||
}
|
||||
|
||||
// int Eeprom::readValueAt(int position, int size)
|
||||
// {
|
||||
// EEPROM.begin(size);
|
||||
// // read the last LED state from flash memory
|
||||
// return EEPROM.read(position);
|
||||
// }
|
||||
// void Eeprom::writeValueAt(int position, int size, int value)
|
||||
// {
|
||||
// EEPROM.write(position, value);
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
|
||||
// void Eeprom::writeString(int position, String value)
|
||||
// {
|
||||
// for(int i=0 ; i < value.length() ; i++)
|
||||
// {
|
||||
// EEPROM.write( i + position,value[i] );
|
||||
// }
|
||||
// EEPROM.commit();
|
||||
// }
|
||||
|
||||
void Eeprom::writeString(char add,String data)
|
||||
{
|
||||
int _size = data.length();
|
||||
int i;
|
||||
for(i=0;i<_size;i++)
|
||||
{
|
||||
EEPROM.write(add+i,data[i]);
|
||||
}
|
||||
EEPROM.write(add+_size,'\0'); //Add termination null character for String Data
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
String Eeprom::readString(char position)
|
||||
{
|
||||
int i;
|
||||
char data[100]; //Max 100 Bytes
|
||||
int len=0;
|
||||
unsigned char k;
|
||||
k=EEPROM.read(position);
|
||||
while(k != '\0' && len<500) //Read until null character
|
||||
{
|
||||
k=EEPROM.read(position+len);
|
||||
data[len]=k;
|
||||
len++;
|
||||
}
|
||||
data[len]='\0';
|
||||
return String(data);
|
||||
}
|
||||
Reference in New Issue
Block a user