Skip to content

Commit 42675ba

Browse files
Rocketctfacchinm
authored andcommitted
added new pressure sensor library for new revision
1 parent bb07eb2 commit 42675ba

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

src/PressureClass.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
This file is part of the Arduino_LSM6DSOX library.
3+
Copyright (c) 2021 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "PressureClass.h"
21+
22+
// sets function called on slave write
23+
PressureClass::PressureClass( getRev_t getRevision)
24+
{
25+
//If board_revision = 1, IMU module is LSM6DSOX, otherwise is LSM6DS3
26+
board_revision = getRevision;
27+
}
28+
29+
PressureClass::~PressureClass()
30+
{
31+
}
32+
33+
int PressureClass::begin()
34+
{
35+
_revision = board_revision();
36+
if (_revision == BOARD_REVISION_2) {
37+
if (iaqSensor == nullptr) {
38+
iaqSensor = new Bsec();
39+
}
40+
iaqSensor->begin(BME680_I2C_ADDR_PRIMARY, Wire);
41+
if (checkIaqSensorStatus() == STATUS_ERROR){
42+
return 0;
43+
}
44+
45+
bsec_virtual_sensor_t sensorList[10] = {
46+
BSEC_OUTPUT_RAW_TEMPERATURE,
47+
BSEC_OUTPUT_RAW_PRESSURE,
48+
BSEC_OUTPUT_RAW_HUMIDITY,
49+
BSEC_OUTPUT_RAW_GAS,
50+
BSEC_OUTPUT_IAQ,
51+
BSEC_OUTPUT_STATIC_IAQ,
52+
BSEC_OUTPUT_CO2_EQUIVALENT,
53+
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
54+
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
55+
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
56+
};
57+
58+
iaqSensor->updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_CONTINUOUS);
59+
if (checkIaqSensorStatus() == STATUS_ERROR){
60+
return 0;
61+
}
62+
return 1;
63+
} else {
64+
if (LPS22HB == nullptr) {
65+
LPS22HB = new LPS22HBClass(Wire);
66+
}
67+
if (LPS22HB == nullptr) return 0;
68+
return LPS22HB->begin();
69+
}
70+
}
71+
72+
int PressureClass::checkIaqSensorStatus(void)
73+
{
74+
if (iaqSensor->status != BSEC_OK) {
75+
if (iaqSensor->status < BSEC_OK) {
76+
return STATUS_ERROR;
77+
}
78+
}
79+
80+
if (iaqSensor->bme680Status != BME680_OK) {
81+
if (iaqSensor->bme680Status < BME680_OK) {
82+
return STATUS_ERROR;
83+
}
84+
}
85+
return STATUS_OK;
86+
}
87+
88+
void PressureClass::end()
89+
{
90+
if (_revision == BOARD_REVISION_2) {
91+
delete iaqSensor;
92+
iaqSensor = nullptr;
93+
} else {
94+
LPS22HB->end();
95+
delete LPS22HB;
96+
LPS22HB = nullptr;
97+
}
98+
}
99+
100+
float PressureClass::readPressure(int units)
101+
{
102+
if (_revision == BOARD_REVISION_2) {
103+
while(!iaqSensor->run()){ }
104+
return iaqSensor->pressure/1000;
105+
}
106+
return LPS22HB->readPressure(units);
107+
}
108+
109+
float PressureClass::readTemperature()
110+
{
111+
if (_revision == BOARD_REVISION_2) {
112+
while(!iaqSensor->run()){}
113+
return iaqSensor->temperature;
114+
}
115+
return LPS22HB->readTemperature();
116+
}
117+

src/PressureClass.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef _PRESSURECLASS_H_INCLUDED
2+
#define _PRESSURECLASS_H_INCLUDED
3+
4+
#include <Arduino.h>
5+
#include <MKRIoTCarrierDefines.h>
6+
7+
class PressureClass {
8+
public:
9+
PressureClass(int (*)(void));
10+
~PressureClass();
11+
12+
int begin();
13+
void end();
14+
15+
float readPressure(int units = KILOPASCAL);
16+
float readTemperature(void);
17+
18+
private:
19+
// Helper functions declarations
20+
int checkIaqSensorStatus(void);
21+
22+
LPS22HBClass* LPS22HB;
23+
Bsec *iaqSensor;
24+
//LSM6DS3Class& LSM6DS3 = IMU;
25+
//LSM6DSOXClass& LSM6DSOX = IMU;
26+
27+
private:
28+
29+
int (*board_revision)(void);
30+
int _revision;
31+
};
32+
33+
#endif //_PRESSURECLASS_H_INCLUDED

0 commit comments

Comments
 (0)