ThermometerPro/thermometer.h
2014-03-08 00:23:46 +01:00

118 lines
2.7 KiB
C++

/*
* thermometer.h
*
* Created on: 24.02.2014
* Author: wn
*/
#ifndef THERMOMETER_H_
#define THERMOMETER_H_
#include "cmd.h"
#include "Resources.h"
const bool DEBUG = true;
const bool INFO = true;
const unsigned long DEFAULT_PERIOD = 1000;
const unsigned int NUM_OF_CHANNELS = 4;
const unsigned long N_MAX = 0xffffff;
const float R_REF = 6200.0;
const float PT1000_R0 = 1000.0;
const float PT1000_Coeff = 3.85e-3;
const unsigned long CONV_TIMEOUT = 0xfffff;
class Thermometer;
class ThermConfig : public Cmd {
public:
ThermConfig(Thermometer *thermometer) : m_thermometer(thermometer) {};
virtual String getCmdName() { return "TCFG"; }
virtual String getHelp() { return getResource(THERMCONFIG_HELP_KEY); }
virtual String exec(String params);
private:
Thermometer *m_thermometer;
};
class ThermValues : public Cmd {
public:
ThermValues(Thermometer *thermometer) : m_thermometer(thermometer) {};
virtual String getCmdName() { return "TVAL"; }
virtual String getHelp() { return getResource(THERMVALUES_HELP_KEY); }
virtual String exec(String params);
private:
Thermometer *m_thermometer;
};
class ThermCalibrate : public Cmd {
public:
ThermCalibrate(Thermometer *thermometer);
virtual String getCmdName() { return "TCALIBR"; }
virtual String getHelp() { return getResource(THERMCALIBRATE_HELP_KEY); }
virtual String exec(String params);
friend class Thermometer;
private:
Thermometer *m_thermometer;
bool m_enabled;
bool m_start_highCalibration;
bool m_start_zeroCalibration;
float m_r_cal;
float m_preserved_alpha;
unsigned long m_preserved_period;
unsigned int m_channel;
unsigned int m_turn;
float m_r_sum;
};
class Thermometer {
public:
Thermometer();
void begin(CmdServer *cmdServer);
void exec();
friend class ThermConfig;
friend class ThermValues;
private:
unsigned long m_periodMillis;
ThermConfig thermConfig;
ThermValues thermValues;
ThermCalibrate thermCalibrate;
bool m_debug;
bool m_info;
unsigned long m_n[NUM_OF_CHANNELS];
float m_calibrateFactor[NUM_OF_CHANNELS];
float m_temperature[NUM_OF_CHANNELS];
float m_lastSmoothedTemperature[NUM_OF_CHANNELS];
float m_smoothedTemperature[NUM_OF_CHANNELS];
unsigned long m_timeOutFailureCnt;
unsigned long m_cylceCnt;
float m_alpha;
bool m_calibrationHighMode;
bool m_calibrationZeroMode;
void startSingleConv();
void prepareAdc();
void setTemperature(unsigned int index, float t);
void setPeriodMeasure(unsigned long p);
unsigned long getPeriodMeasure();
void setAlpha(float a);
float getAlpha();
void setCalibrateFactor(unsigned int i, float c);
float getCalibrateFactor(unsigned int i);
void setDebug(bool b);
bool getDebug();
void setInfo(bool b);
bool getInfo();
};
#endif /* THERMOMETER_H_ */