store config in eeprom

This commit is contained in:
hg
2014-03-04 18:48:45 +01:00
parent ff730fcab2
commit 61b90393dc
6 changed files with 167 additions and 7 deletions

70
Config.cpp Normal file
View File

@ -0,0 +1,70 @@
/*
* Config.cpp
*
* Created on: 04.03.2014
* Author: wn
*/
#include <EEPROM.h>
#include "Config.h"
float Config::getFloat(int pos) {
u_float u;
for (unsigned int i = 0; i < sizeof(float); i++) {
u.e[i] = EEPROM.read(pos + i);
}
return u.f;
}
void Config::setFloat(int pos, float value) {
u_float u;
u.f = value;
for (unsigned int i = 0; i < sizeof(float); i++) {
EEPROM.write(pos + i, u.e[i]);
}
}
unsigned int Config::getUInt(int pos) {
u_uint u;
for (unsigned int i = 0; i < sizeof(unsigned int); i++) {
u.e[i] = EEPROM.read(pos + i);
}
return u.i;
}
void Config::setUInt(int pos, unsigned int value) {
u_uint u;
u.i = value;
for (unsigned int i = 0; i < sizeof(unsigned int); i++) {
EEPROM.write(pos + i, u.e[i]);
}
}
unsigned long Config::getULong(int pos) {
u_ulong u;
for (unsigned int i = 0; i < sizeof(unsigned long); i++) {
u.e[i] = EEPROM.read(pos + i);
}
return u.l;
}
void Config::setULong(int pos, unsigned long value) {
u_ulong u;
u.l = value;
for (unsigned int i = 0; i < sizeof(unsigned long); i++) {
EEPROM.write(pos + i, u.e[i]);
}
}
bool Config::isInitialized() {
unsigned int magic = getUInt(MAGIC);
return magic == MAGIC_TOKEN;
}
void Config::setMagic() {
setUInt(MAGIC, MAGIC_TOKEN);
}