Move common function to separate file

This commit is contained in:
Phat Nguyen
2024-04-22 16:30:57 +07:00
parent 2d96fc28c5
commit b91a3058fc
4 changed files with 38 additions and 18 deletions

View File

@ -202,18 +202,3 @@ void PMS5003T::handle(void) { pms.handle(); }
*/
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
float PMS5003T::temperatureCompensated(float temp) {
if (temp < 10.0f) {
return temp * 1.327f - 6.738f;
}
return temp * 1.181f - 5.113f;
}
float PMS5003T::humidityCompensated(float hum) {
hum = hum * 1.259f + 7.34f;
if (hum > 100.0f) {
hum = 100.0f;
}
return hum;
}

View File

@ -3,13 +3,14 @@
#include "../Main/BoardDef.h"
#include "PMS.h"
#include "PMS5003TBase.h"
#include "Stream.h"
#include <HardwareSerial.h>
/**
* @brief The class define how to handle PMS5003T sensor bas on @ref PMS class
*/
class PMS5003T {
class PMS5003T: public PMS5003TBase {
public:
PMS5003T(BoardType def);
#if defined(ESP8266)
@ -28,8 +29,6 @@ public:
int convertPm25ToUsAqi(int pm25);
float getTemperature(void);
float getRelativeHumidity(void);
float temperatureCompensated(float temp);
float humidityCompensated(float hum);
private:
bool _isBegin = false;

21
src/PMS/PMS5003TBase.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "PMS5003TBase.h"
PMS5003TBase::PMS5003TBase() {}
PMS5003TBase::~PMS5003TBase() {}
float PMS5003TBase::temperatureCompensated(float temp) {
if (temp < 10.0f) {
return temp * 1.327f - 6.738f;
}
return temp * 1.181f - 5.113f;
}
float PMS5003TBase::humidityCompensated(float hum) {
hum = hum * 1.259f + 7.34f;
if (hum > 100.0f) {
hum = 100.0f;
}
return hum;
}

15
src/PMS/PMS5003TBase.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef _PMS5003T_BASE_H_
#define _PMS5003T_BASE_H_
class PMS5003TBase
{
private:
public:
PMS5003TBase();
~PMS5003TBase();
float temperatureCompensated(float temp);
float humidityCompensated(float hum);
};
#endif