more config stuff

This commit is contained in:
Wolfgang Hottgenroth
2014-11-17 20:08:49 +01:00
parent c5a21fd827
commit 5b30486f5b
6 changed files with 39 additions and 14 deletions

View File

@ -1,9 +1,13 @@
#include "Thermometer.h"
#include "Config.h"
using namespace nsThermometer;
const float INVALID_TEMPERATURE = -300.0;
const uint8_t CONFIG_ALPHA = 0;
Thermometer::Thermometer() {
}
@ -14,10 +18,11 @@ void Thermometer::begin(bool initializeConfig, int eepromAddr) {
if (initializeConfig) {
// set default values
Config::setFloat(m_eepromAddr + CONFIG_ALPHA, 1.0);
}
m_lastSmoothedTemperature = INVALID_TEMPERATURE;
m_alpha = 0.1;
alpha = Config::setFloat(m_eepromAddr + CONFIG_ALPHA);
}
@ -27,7 +32,7 @@ void Thermometer::exec(float r) {
if (m_lastSmoothedTemperature == INVALID_TEMPERATURE) {
temperature = temperatureRaw;
} else {
temperature = m_alpha * temperatureRaw + (1 - m_alpha) * m_lastSmoothedTemperature;
temperature = alpha * temperatureRaw + (1 - alpha) * m_lastSmoothedTemperature;
}
m_lastSmoothedTemperature = temperature;
}