Implemented fctns

This commit is contained in:
miguel5612 2019-05-24 22:09:11 -05:00
parent 8ea9600d3c
commit 081f57beca
5 changed files with 88 additions and 78 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -97,70 +97,21 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
//Defaults index //Defaults index
if(nameLectureRequeired == "") if(nameLectureRequeired == "")
{ {
Serial.println("Busqueda manual de los indices");
if(_type == 2)
{
_lecturePosInArray = defaultMQ2;
}
else if(_type == 3)
{
_lecturePosInArray = defaultMQ3;
}
else if(_type == 4)
{
_lecturePosInArray = defaultMQ4;
}
else if(_type == 5)
{
_lecturePosInArray = defaultMQ5;
}
else if(_type == 6)
{
_lecturePosInArray = defaultMQ6;
}
else if(_type == 7)
{
_lecturePosInArray = defaultMQ7;
}
else if(_type == 8)
{
_lecturePosInArray = defaultMQ8;
}
else if(_type == 9)
{
_lecturePosInArray = defaultMQ9;
}
else if(_type == 131)
{
_lecturePosInArray = defaultMQ131;
}
else if(_type == 135)
{
_lecturePosInArray = defaultMQ135;
}
else if(_type == 303)
{
_lecturePosInArray = defaultMQ303;
}
else if(_type == 309)
{
_lecturePosInArray = defaultMQ309;
}
} }
else
//Dinamic index search
if(print)
{ {
//Dinamic index search Serial.println("Busqueda dinamica de los indices");
if(print)
{
Serial.println("Busqueda dinamica de los indices");
}
for (int i=0; i<lecturesAvailable; i++) {
if (nameLectureRequeired = nameLecture[i]) { //modified here
_lecturePosInArray = i;
break;
}
}
} }
for (int i=0; i<sizeof(_MQ); i++) {
if (nameLectureRequeired = _MQ[i]) { //modified here
_lecturePosInArray = i;
break;
}
}
//Serial debugging //Serial debugging
if(print) if(print)
{ {
@ -169,12 +120,12 @@ void MQUnifiedsensor::setSensorCharacteristics(String nameLectureRequeired, bool
Serial.print("index in nameLectures: "); Serial.print("index in nameLectures: ");
Serial.println(_lecturePosInArray); Serial.println(_lecturePosInArray);
Serial.print("Slope index: "); Serial.print("Slope index: ");
Serial.println(indexSlopeLectures[_lecturePosInArray]); Serial.println(_lecturePosInArray+1);
Serial.print("B point index: "); Serial.print("B point index: ");
Serial.println(indexBPointLectures[_lecturePosInArray]); Serial.println(_lecturePosInArray+2);
} }
_m = _MQ[indexSlopeLectures[_lecturePosInArray]]; _m = stringToDouble(_MQ[_lecturePosInArray+1]);
_b = _MQ[indexBPointLectures[_lecturePosInArray]]; _b = stringToDouble(_MQ[_lecturePosInArray+2]);
} }
int MQUnifiedsensor::readPPM(int m, int b) { int MQUnifiedsensor::readPPM(int m, int b) {
/** /**
@ -215,4 +166,60 @@ double MQUnifiedsensor::getVoltage() {
} }
void MQUnifiedsensor::setR0(double R0) { void MQUnifiedsensor::setR0(double R0) {
this->_R0 = R0; this->_R0 = R0;
}
void MQUnifiedsensor::setDefaultGas()
{
Serial.println("Carga de los gases por defecto");
if(_type == 2)
{
nameLectureRequeired = defaultMQ2;
}
else if(_type == 3)
{
nameLectureRequeired = defaultMQ3;
}
else if(_type == 4)
{
nameLectureRequeired = defaultMQ4;
}
else if(_type == 5)
{
nameLectureRequeired = defaultMQ5;
}
else if(_type == 6)
{
nameLectureRequeired = defaultMQ6;
}
else if(_type == 7)
{
nameLectureRequeired = defaultMQ7;
}
else if(_type == 8)
{
nameLectureRequeired = defaultMQ8;
}
else if(_type == 9)
{
nameLectureRequeired = defaultMQ9;
}
else if(_type == 131)
{
nameLectureRequeired = defaultMQ131;
}
else if(_type == 135)
{
nameLectureRequeired = defaultMQ135;
}
else if(_type == 303)
{
nameLectureRequeired = defaultMQ303;
}
else if(_type == 309)
{
nameLectureRequeired = defaultMQ309;
}
}
double MQUnifiedsensor::stringToDouble(String & str) <-- notice the "&"
{
return atof( str.c_str() );
} }

View File

@ -8,18 +8,18 @@
#define lecturesAvailable 19 #define lecturesAvailable 19
//Index in the nameLecture vector //Index in the nameLecture vector
#define defaultMQ2 2 // LPG #define defaultMQ2 "LPG" // LPG
#define defaultMQ3 5 // Alcohol #define defaultMQ3 "Alcohol" // Alcohol
#define defaultMQ4 3 // CH4 #define defaultMQ4 "CH4" // CH4
#define defaultMQ5 0 //H2 #define defaultMQ5 "H2" //H2
#define defaultMQ6 3 // CH4 #define defaultMQ6 "CH4" // CH4
#define defaultMQ7 4 //CO #define defaultMQ7 "CO" //CO
#define defaultMQ8 0 //H2 #define defaultMQ8 "H2" //H2
#define defaultMQ9 2 // LPG #define defaultMQ9 "LPG" // LPG
#define defaultMQ131 12 //O3 #define defaultMQ131 "O3" //O3
#define defaultMQ135 15 //NH4 #define defaultMQ135 "NH4" //NH4
#define defaultMQ303 17 //Isobutano #define defaultMQ303 "Isobutano" //Isobutano
#define defaultMQ309 4 //CO #define defaultMQ309 "CO" //CO
class MQUnifiedsensor class MQUnifiedsensor
@ -29,12 +29,14 @@ class MQUnifiedsensor
void inicializar(); void inicializar();
void setR0(double R0); void setR0(double R0);
void setSensorCharacteristics(String nameLectureReqeuired, bool print); void setSensorCharacteristics(String nameLectureReqeuired, bool print);
void setDefaultGas();
int readSensor(String nameLectureRequeired = "", bool print = false); int readSensor(String nameLectureRequeired = "", bool print = false);
int readPPM(int m, int b); int readPPM(int m, int b);
double calibrate(); double calibrate();
double getVoltage(); double getVoltage();
double stringToDouble(String & str);
String getnameLecture(); String getnameLecture();
@ -56,7 +58,8 @@ class MQUnifiedsensor
private: private:
int _pin, _type, _PPM, _lecturePosInArray; int _pin, _type, _PPM, _lecturePosInArray;
double _R0, _m, _b, _MQ[12]; double _R0, _m, _b;
String _MQ[19];
const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3 const float VOLT_RESOLUTION = 5.0; // if 3.3v use 3.3
const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter. const int ADC_RESOLUTION = 10; // for 10bit analog to digital converter.
const int retries = 50; const int retries = 50;