store config in eeprom
This commit is contained in:
@ -27,6 +27,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/NilRTOS}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/Metro}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/Streaming}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/EEPROM}""/>
|
||||
</option>
|
||||
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.244106961" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
|
||||
</tool>
|
||||
@ -38,6 +39,7 @@
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/NilRTOS}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/Metro}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/Streaming}""/>
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc:/ThermometerPro/Libraries/EEPROM}""/>
|
||||
</option>
|
||||
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.1503729033" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
|
||||
</tool>
|
||||
|
5
.project
5
.project
@ -26,6 +26,11 @@
|
||||
<nature>it.baeyens.arduinonature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>Libraries/EEPROM</name>
|
||||
<type>2</type>
|
||||
<locationURI>ArduinoHardwareLibPath/EEPROM</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>Libraries/Metro</name>
|
||||
<type>2</type>
|
||||
|
70
Config.cpp
Normal file
70
Config.cpp
Normal 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);
|
||||
}
|
||||
|
||||
|
49
Config.h
Normal file
49
Config.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Config.h
|
||||
*
|
||||
* Created on: 04.03.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
|
||||
|
||||
typedef union {
|
||||
float f;
|
||||
uint8_t e[sizeof(float)];
|
||||
} u_float;
|
||||
|
||||
typedef union {
|
||||
unsigned int i;
|
||||
uint8_t e[sizeof(unsigned int)];
|
||||
} u_uint;
|
||||
|
||||
typedef union {
|
||||
unsigned long l;
|
||||
uint8_t e[sizeof(unsigned long)];
|
||||
} u_ulong;
|
||||
|
||||
|
||||
namespace Config {
|
||||
const unsigned int MAGIC_TOKEN = 0xDEADBEEF;
|
||||
|
||||
const int MAGIC = 0; // 4
|
||||
const int THERMOMETER_ALPHA = 4; // 4
|
||||
const int THERMOMETER_PERIOD = 8; // 8
|
||||
const int THERMOMETER_CAL[4] = {12, 16, 20, 24}; // 4 x 4
|
||||
|
||||
float getFloat(int pos);
|
||||
void setFloat(int pos, float value);
|
||||
unsigned int getUInt(int pos);
|
||||
void setUInt(int pos, unsigned int value);
|
||||
unsigned long getULong(int pos);
|
||||
void setULong(int pos, unsigned long value);
|
||||
|
||||
bool isInitialized();
|
||||
|
||||
void setMagic();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_H_ */
|
@ -3,6 +3,7 @@
|
||||
#include "fatal.h"
|
||||
#include "AD7190.h"
|
||||
#include "Streaming.h"
|
||||
#include "Config.h"
|
||||
|
||||
|
||||
|
||||
@ -118,18 +119,33 @@ Thermometer::Thermometer() : m_period(DEFAULT_PERIOD), m_periodMillis(DEFAULT_PE
|
||||
|
||||
|
||||
void Thermometer::setPeriodMeasure(unsigned long p) {
|
||||
Config::setULong(Config::THERMOMETER_PERIOD, p);
|
||||
m_periodMillis = p;
|
||||
m_period = Metro(p);
|
||||
}
|
||||
|
||||
unsigned long Thermometer::getPeriodMeasure() {
|
||||
return m_periodMillis;
|
||||
}
|
||||
|
||||
void Thermometer::setAlpha(float a) {
|
||||
Config::setFloat(Config::THERMOMETER_ALPHA, a);
|
||||
m_alpha = a;
|
||||
}
|
||||
|
||||
float Thermometer::getAlpha() {
|
||||
return m_alpha;
|
||||
}
|
||||
|
||||
|
||||
void Thermometer::setCalibrateFactor(unsigned int i, float c) {
|
||||
Config::setFloat(Config::THERMOMETER_CAL[i], c);
|
||||
m_calibrateFactor[i] = c;
|
||||
}
|
||||
|
||||
float Thermometer::getCalibrateFactor(unsigned int i) {
|
||||
return m_calibrateFactor[i];
|
||||
}
|
||||
|
||||
|
||||
float pt1000(float r) {
|
||||
@ -205,10 +221,28 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN1P_AINCOM);
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN1P_AINCOM);
|
||||
|
||||
setCalibrateFactor(0, 1.002999);
|
||||
setCalibrateFactor(1, 1.001804);
|
||||
setCalibrateFactor(2, 1.000794);
|
||||
setCalibrateFactor(3, 1.001071);
|
||||
|
||||
if (! Config::isInitialized()) {
|
||||
Serial << "Initializing EEPROM" << endl;
|
||||
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
||||
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
|
||||
}
|
||||
Config::setMagic();
|
||||
}
|
||||
|
||||
setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
|
||||
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
setCalibrateFactor(i, Config::getFloat(Config::THERMOMETER_CAL[i]));
|
||||
}
|
||||
|
||||
|
||||
//setCalibrateFactor(0, 1.002999);
|
||||
//setCalibrateFactor(1, 1.001804);
|
||||
//setCalibrateFactor(2, 1.000794);
|
||||
//setCalibrateFactor(3, 1.001071);
|
||||
|
||||
// prepare
|
||||
prepareAdc();
|
||||
|
@ -93,11 +93,11 @@ private:
|
||||
|
||||
void setTemperature(unsigned int index, float t);
|
||||
void setPeriodMeasure(unsigned long p);
|
||||
unsigned long getPeriodMeasure() { return m_periodMillis; }
|
||||
unsigned long getPeriodMeasure();
|
||||
void setAlpha(float a);
|
||||
float getAlpha() { return m_alpha; }
|
||||
float getAlpha();
|
||||
void setCalibrateFactor(unsigned int i, float c);
|
||||
float getCalibrateFactor(unsigned int i) { return m_calibrateFactor[i]; }
|
||||
float getCalibrateFactor(unsigned int i);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user