ThermometerPro/thermometer.h

122 lines
2.9 KiB
C
Raw Permalink Normal View History

2014-02-25 17:32:23 +01:00
/*
* thermometer.h
*
* Created on: 24.02.2014
* Author: wn
*/
#ifndef THERMOMETER_H_
#define THERMOMETER_H_
#include "cmd.h"
#include "Resources.h"
2014-02-25 17:32:23 +01:00
2014-02-26 20:54:54 +01:00
const bool DEBUG = true;
2014-02-25 17:32:23 +01:00
const bool INFO = true;
2014-02-26 20:54:54 +01:00
const unsigned long DEFAULT_PERIOD = 1000;
2014-02-25 17:32:23 +01:00
const unsigned int NUM_OF_CHANNELS = 4;
const unsigned long N_MAX = 0xffffff;
2014-03-08 00:23:46 +01:00
const float R_REF = 6200.0;
2014-02-25 17:32:23 +01:00
const float PT1000_R0 = 1000.0;
const float PT1000_Coeff = 3.85e-3;
const unsigned long CONV_TIMEOUT = 0xfffff;
2014-04-04 20:38:11 +02:00
const unsigned long NUM_OF_CALIBRATION_CYCLES = 250;
const unsigned long CALIBRATION_CYCLE_TIME = 10; // ms
2014-02-25 17:32:23 +01:00
2014-02-26 20:54:54 +01:00
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); }
2014-02-26 20:54:54 +01:00
virtual String exec(String params);
private:
Thermometer *m_thermometer;
};
2014-02-26 23:53:15 +01:00
class ThermValues : public Cmd {
public:
ThermValues(Thermometer *thermometer) : m_thermometer(thermometer) {};
virtual String getCmdName() { return "TVAL"; }
virtual String getHelp() { return getResource(THERMVALUES_HELP_KEY); }
2014-02-26 23:53:15 +01:00
virtual String exec(String params);
private:
Thermometer *m_thermometer;
};
2014-02-26 20:54:54 +01:00
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);
2014-03-04 22:53:40 +01:00
friend class Thermometer;
private:
Thermometer *m_thermometer;
bool m_enabled;
2014-03-08 00:23:46 +01:00
bool m_start_highCalibration;
bool m_start_zeroCalibration;
float m_r_cal;
float m_preserved_alpha;
unsigned long m_preserved_period;
2014-03-04 22:53:40 +01:00
unsigned int m_turn;
2014-04-04 20:38:11 +02:00
float m_r_sum[NUM_OF_CHANNELS];
};
2014-02-26 20:54:54 +01:00
2014-02-25 17:32:23 +01:00
class Thermometer {
public:
Thermometer();
void begin(CmdServer *cmdServer);
void exec();
2014-02-26 20:54:54 +01:00
friend class ThermConfig;
2014-02-26 23:53:15 +01:00
friend class ThermValues;
2014-05-04 20:56:03 +02:00
float getTemperature(unsigned int index);
float getCalibrateFactor(unsigned int i);
unsigned long getPeriodMeasure();
float getAlpha();
2014-02-26 20:54:54 +01:00
2014-02-25 17:32:23 +01:00
private:
2014-02-26 20:54:54 +01:00
unsigned long m_periodMillis;
ThermConfig thermConfig;
2014-02-26 23:53:15 +01:00
ThermValues thermValues;
2014-03-04 22:53:40 +01:00
ThermCalibrate thermCalibrate;
2014-02-26 20:54:54 +01:00
bool m_debug;
bool m_info;
2014-02-25 17:32:23 +01:00
unsigned long m_n[NUM_OF_CHANNELS];
float m_calibrateFactor[NUM_OF_CHANNELS];
2014-04-02 22:50:17 +02:00
float m_r[NUM_OF_CHANNELS];
2014-02-25 17:32:23 +01:00
float m_temperature[NUM_OF_CHANNELS];
2014-02-26 20:54:54 +01:00
float m_lastSmoothedTemperature[NUM_OF_CHANNELS];
float m_smoothedTemperature[NUM_OF_CHANNELS];
2014-02-25 17:32:23 +01:00
unsigned long m_timeOutFailureCnt;
2014-02-26 20:54:54 +01:00
unsigned long m_cylceCnt;
float m_alpha;
2014-03-08 00:23:46 +01:00
bool m_calibrationHighMode;
bool m_calibrationZeroMode;
2014-03-04 22:53:40 +01:00
2014-02-26 20:54:54 +01:00
void startSingleConv();
void prepareAdc();
2014-02-25 17:32:23 +01:00
void setTemperature(unsigned int index, float t);
2014-04-04 20:38:11 +02:00
void setR(unsigned int index, float r);
2014-02-26 20:54:54 +01:00
void setPeriodMeasure(unsigned long p);
void setAlpha(float a);
void setCalibrateFactor(unsigned int i, float c);
2014-03-04 19:08:19 +01:00
void setDebug(bool b);
bool getDebug();
void setInfo(bool b);
bool getInfo();
2014-02-25 17:32:23 +01:00
};
#endif /* THERMOMETER_H_ */