make proper class declaration

This commit is contained in:
CAHEK7 2016-08-26 14:43:01 +03:00
parent 7881a1c58f
commit 94d34c6e4a
2 changed files with 31 additions and 32 deletions

View File

@ -1,14 +1,14 @@
#include "BaseMQ.h"
BaseMQ::BaseMQ(uint8_t pin) {
_pin = pin;
BaseMQ::BaseMQ(uint8_t pin) :
_pin (pin) {
}
BaseMQ::BaseMQ(uint8_t pin, uint8_t pinHeater) {
_pin = pin;
_pinHeater = pinHeater;
BaseMQ::BaseMQ(uint8_t pin, uint8_t pinHeater) :
_pin (pin),
_pinHeater (pinHeater)
{
pinMode(_pinHeater, OUTPUT);
_prMillis = 0;
}
// калибровка датчика
@ -48,14 +48,14 @@ void BaseMQ::heaterPwrOff() {
}
// сопротивление датчика
float BaseMQ::calculateResistance(int rawAdc) {
float BaseMQ::calculateResistance(int rawAdc) const {
float vrl = rawAdc*(5.0 / 1023);
float rsAir = (5.0 - vrl)/vrl*getRL();
return rsAir;
}
// считывание датчика
float BaseMQ::readRs() {
float BaseMQ::readRs() const {
float rs = 0;
for (int i = 0; i < MQ_SAMPLE_TIMES; i++) {
rs += calculateResistance(analogRead(_pin));
@ -65,31 +65,23 @@ float BaseMQ::readRs() {
return rs;
}
unsigned long readScaled(float a, float b) {
unsigned long BaseMQ::readScaled(float a, float b) const {
float ratio = readRatio();
return exp((log(ratio)-b)/a);
}
float BaseMQ::getRo() {
return _ro;
}
bool BaseMQ::isCalibrated() {
return _stateCalibrate;
}
float BaseMQ::readRatio() {
float BaseMQ::readRatio() const {
return readRs()/getRo();
}
bool BaseMQ::heatingCompleted() {
bool BaseMQ::heatingCompleted() const {
if ((_heater) && (!_cooler) && (millis() - _prMillis > 60000))
return true;
else
return false;
}
bool BaseMQ::coolanceCompleted() {
bool BaseMQ::coolanceCompleted() const {
if ((_heater) && (_cooler) && (millis() - _prMillis > 90000))
return true;
else

View File

@ -16,25 +16,32 @@ public:
void heaterPwrLow();
void heaterPwrOff();
void cycleHeat();
bool heatingCompleted();
bool coolanceCompleted();
bool isCalibrated();
bool atHeatCycleEnd();
float getRo();
float readRatio();
bool heatingCompleted() const;
bool coolanceCompleted() const;
float readRatio() const;
inline bool isCalibrated() const {
return _stateCalibrate;
};
inline float getRo() const {
return _ro;
};
protected:
unsigned long readScaled(float a, float b) const;
virtual float getRoInCleanAir() const = 0;
virtual int getRL() const = 0;
private:
bool _heater = false;
bool _cooler = false;
bool _stateCalibrate = false;
unsigned long _prMillis;
float _ro;
unsigned long _prMillis = 0;
float _ro = 1.0f;
uint8_t _pin;
uint8_t _pinHeater;
float readRs();
unsigned long readScaled(float a, float b);
float calculateResistance(int rawAdc);
virtual float getRoInCleanAir() const = 0;
virtual int getRL() const = 0;
float readRs() const;
float calculateResistance(int rawAdc) const;
};
#endif