mirror of
https://github.com/amperka/TroykaMQ.git
synced 2025-03-15 04:27:34 +03:00
make proper class declaration
This commit is contained in:
parent
7881a1c58f
commit
94d34c6e4a
32
BaseMQ.cpp
32
BaseMQ.cpp
@ -1,14 +1,14 @@
|
|||||||
#include "BaseMQ.h"
|
#include "BaseMQ.h"
|
||||||
|
|
||||||
BaseMQ::BaseMQ(uint8_t pin) {
|
BaseMQ::BaseMQ(uint8_t pin) :
|
||||||
_pin = pin;
|
_pin (pin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseMQ::BaseMQ(uint8_t pin, uint8_t pinHeater) {
|
BaseMQ::BaseMQ(uint8_t pin, uint8_t pinHeater) :
|
||||||
_pin = pin;
|
_pin (pin),
|
||||||
_pinHeater = pinHeater;
|
_pinHeater (pinHeater)
|
||||||
|
{
|
||||||
pinMode(_pinHeater, OUTPUT);
|
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 vrl = rawAdc*(5.0 / 1023);
|
||||||
float rsAir = (5.0 - vrl)/vrl*getRL();
|
float rsAir = (5.0 - vrl)/vrl*getRL();
|
||||||
return rsAir;
|
return rsAir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// считывание датчика
|
// считывание датчика
|
||||||
float BaseMQ::readRs() {
|
float BaseMQ::readRs() const {
|
||||||
float rs = 0;
|
float rs = 0;
|
||||||
for (int i = 0; i < MQ_SAMPLE_TIMES; i++) {
|
for (int i = 0; i < MQ_SAMPLE_TIMES; i++) {
|
||||||
rs += calculateResistance(analogRead(_pin));
|
rs += calculateResistance(analogRead(_pin));
|
||||||
@ -65,31 +65,23 @@ float BaseMQ::readRs() {
|
|||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long readScaled(float a, float b) {
|
unsigned long BaseMQ::readScaled(float a, float b) const {
|
||||||
float ratio = readRatio();
|
float ratio = readRatio();
|
||||||
return exp((log(ratio)-b)/a);
|
return exp((log(ratio)-b)/a);
|
||||||
}
|
}
|
||||||
|
|
||||||
float BaseMQ::getRo() {
|
float BaseMQ::readRatio() const {
|
||||||
return _ro;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BaseMQ::isCalibrated() {
|
|
||||||
return _stateCalibrate;
|
|
||||||
}
|
|
||||||
|
|
||||||
float BaseMQ::readRatio() {
|
|
||||||
return readRs()/getRo();
|
return readRs()/getRo();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseMQ::heatingCompleted() {
|
bool BaseMQ::heatingCompleted() const {
|
||||||
if ((_heater) && (!_cooler) && (millis() - _prMillis > 60000))
|
if ((_heater) && (!_cooler) && (millis() - _prMillis > 60000))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseMQ::coolanceCompleted() {
|
bool BaseMQ::coolanceCompleted() const {
|
||||||
if ((_heater) && (_cooler) && (millis() - _prMillis > 90000))
|
if ((_heater) && (_cooler) && (millis() - _prMillis > 90000))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
31
BaseMQ.h
31
BaseMQ.h
@ -16,25 +16,32 @@ public:
|
|||||||
void heaterPwrLow();
|
void heaterPwrLow();
|
||||||
void heaterPwrOff();
|
void heaterPwrOff();
|
||||||
void cycleHeat();
|
void cycleHeat();
|
||||||
bool heatingCompleted();
|
|
||||||
bool coolanceCompleted();
|
|
||||||
bool isCalibrated();
|
|
||||||
bool atHeatCycleEnd();
|
bool atHeatCycleEnd();
|
||||||
float getRo();
|
bool heatingCompleted() const;
|
||||||
float readRatio();
|
bool coolanceCompleted() const;
|
||||||
|
float readRatio() const;
|
||||||
|
inline bool isCalibrated() const {
|
||||||
|
return _stateCalibrate;
|
||||||
|
};
|
||||||
|
inline float getRo() const {
|
||||||
|
return _ro;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
unsigned long readScaled(float a, float b) const;
|
||||||
|
virtual float getRoInCleanAir() const = 0;
|
||||||
|
virtual int getRL() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
bool _heater = false;
|
bool _heater = false;
|
||||||
bool _cooler = false;
|
bool _cooler = false;
|
||||||
bool _stateCalibrate = false;
|
bool _stateCalibrate = false;
|
||||||
unsigned long _prMillis;
|
unsigned long _prMillis = 0;
|
||||||
float _ro;
|
float _ro = 1.0f;
|
||||||
uint8_t _pin;
|
uint8_t _pin;
|
||||||
uint8_t _pinHeater;
|
uint8_t _pinHeater;
|
||||||
float readRs();
|
float readRs() const;
|
||||||
unsigned long readScaled(float a, float b);
|
float calculateResistance(int rawAdc) const;
|
||||||
float calculateResistance(int rawAdc);
|
|
||||||
virtual float getRoInCleanAir() const = 0;
|
|
||||||
virtual int getRL() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user