Skip to content

Commit 6d9721b

Browse files
Rocketctfacchinm
authored andcommitted
added new enviroment sensor management and added support for bme68x on new rev
1 parent 75a5ff2 commit 6d9721b

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

src/EnvClass.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 "EnvClass.h"
21+
22+
23+
// sets function called on slave write
24+
EnvClass::EnvClass( getRev_t getRevision )
25+
{
26+
//If board_revision = 1, IMU module is LSM6DSOX, otherwise is LSM6DS3
27+
board_revision = getRevision;
28+
}
29+
30+
EnvClass::~EnvClass()
31+
{
32+
}
33+
34+
int EnvClass::begin()
35+
{
36+
_revision = board_revision();
37+
if (_revision == BOARD_REVISION_2) {
38+
if (iaqSensor == nullptr) {
39+
iaqSensor = new Bsec();
40+
}
41+
iaqSensor->begin(BME680_I2C_ADDR_PRIMARY, Wire);
42+
if (checkIaqSensorStatus() == STATUS_ERROR){
43+
return 0;
44+
}
45+
46+
bsec_virtual_sensor_t sensorList[10] = {
47+
BSEC_OUTPUT_RAW_TEMPERATURE,
48+
BSEC_OUTPUT_RAW_PRESSURE,
49+
BSEC_OUTPUT_RAW_HUMIDITY,
50+
BSEC_OUTPUT_RAW_GAS,
51+
BSEC_OUTPUT_IAQ,
52+
BSEC_OUTPUT_STATIC_IAQ,
53+
BSEC_OUTPUT_CO2_EQUIVALENT,
54+
BSEC_OUTPUT_BREATH_VOC_EQUIVALENT,
55+
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE,
56+
BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY,
57+
};
58+
59+
iaqSensor->updateSubscription(sensorList, 10, BSEC_SAMPLE_RATE_CONTINUOUS);
60+
if (checkIaqSensorStatus() == STATUS_ERROR){
61+
return 0;
62+
}
63+
64+
return 1;
65+
} else {
66+
if (HTS221 == nullptr) {
67+
HTS221 = new HTS221Class(Wire);
68+
}
69+
return HTS221->begin();
70+
}
71+
}
72+
73+
int EnvClass::checkIaqSensorStatus(void)
74+
{
75+
if (iaqSensor->status != BSEC_OK) {
76+
if (iaqSensor->status < BSEC_OK) {
77+
return 0;
78+
}
79+
}
80+
81+
if (iaqSensor->bme680Status != BME680_OK) {
82+
if (iaqSensor->bme680Status < BME680_OK) {
83+
return 0;
84+
}
85+
}
86+
return 1;
87+
}
88+
89+
void EnvClass::end()
90+
{
91+
if (_revision == BOARD_REVISION_2) {
92+
delete iaqSensor;
93+
iaqSensor = nullptr;
94+
} else {
95+
HTS221->end();
96+
delete HTS221;
97+
HTS221 = nullptr;
98+
}
99+
}
100+
101+
float EnvClass::readTemperature(int units /*= CELSIUS*/)
102+
{
103+
if (_revision == BOARD_REVISION_2) {
104+
while(!iaqSensor->run()){ }
105+
return iaqSensor->temperature;
106+
}
107+
return HTS221->readTemperature(units);
108+
}
109+
110+
float EnvClass::readHumidity()
111+
{
112+
if (_revision == BOARD_REVISION_2) {
113+
while(!iaqSensor->run()){ }
114+
return iaqSensor->humidity;
115+
116+
}
117+
return HTS221->readHumidity();
118+
}

src/EnvClass.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef _ENVCLASS_H_INCLUDED
2+
#define _ENVCLASS_H_INCLUDED
3+
4+
#include <Arduino.h>
5+
#include <MKRIoTCarrierDefines.h>
6+
7+
8+
class EnvClass {
9+
public:
10+
EnvClass(int (*)(void));
11+
~EnvClass();
12+
13+
int begin();
14+
void end();
15+
16+
float readTemperature(int units = CELSIUS);
17+
float readHumidity();
18+
19+
private:
20+
int checkIaqSensorStatus(void);
21+
22+
HTS221Class* HTS221;
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 //_ENVCLASS_H_INCLUDED

0 commit comments

Comments
 (0)