/* * 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; const unsigned long NUM_OF_CALIBRATION_CYCLES = 250; const unsigned long CALIBRATION_CYCLE_TIME = 10; // ms 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_turn; float m_r_sum[NUM_OF_CHANNELS]; }; class Thermometer { public: Thermometer(); void begin(CmdServer *cmdServer); void exec(); friend class ThermConfig; friend class ThermValues; float getTemperature(unsigned int index); float getCalibrateFactor(unsigned int i); unsigned long getPeriodMeasure(); float getAlpha(); 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_r[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 setR(unsigned int index, float r); void setPeriodMeasure(unsigned long p); void setAlpha(float a); void setCalibrateFactor(unsigned int i, float c); void setDebug(bool b); bool getDebug(); void setInfo(bool b); bool getInfo(); }; #endif /* THERMOMETER_H_ */