Files
ModbusThermometer/Thermometer.cpp
Wolfgang Hottgenroth 33a8a35bf8 thermometer stuff
2014-11-17 19:17:09 +01:00

29 lines
598 B
C++

#include "Thermometer.h"
using namespace nsThermometer;
const float INVALID_TEMPERATURE = -300.0;
Thermometer::Thermometer() {
}
void Thermometer::begin(int eepromAddr) {
m_eepromAddr = eepromAddr;
m_lastSmoothedTemperature = INVALID_TEMPERATURE;
m_alpha = 0.1;
}
void Thermometer::exec(float r) {
temperatureRaw = (r / PT1000_R0 - 1) / PT1000_Coeff;
if (m_lastSmoothedTemperature == INVALID_TEMPERATURE) {
temperature = temperatureRaw;
} else {
temperature = m_alpha * temperatureRaw + (1 - m_alpha) * m_lastSmoothedTemperature;
}
m_lastSmoothedTemperature = temperature;
}