64 lines
1.6 KiB
C++
64 lines
1.6 KiB
C++
#include "VOC_sensor.h"
|
|
#define DEBUG_SERIAL
|
|
|
|
|
|
//Adafruit_SGP30 sgp;
|
|
SGP30 sgp;
|
|
|
|
//TwoWire wire1(1);
|
|
uint8_t VOC_samples = 3600 / g_pms_report_period;
|
|
#define VOC_MIN 0
|
|
#define VOC_MAX 10000
|
|
#define VOC_RAW_MAX 30000
|
|
#define VOC_INTERVAL 120000 //ms
|
|
|
|
uint32_t lastVOCtime = 0;
|
|
//sensors
|
|
AQSSensor SGP30_tvoc("TVOC", SGP30_TVOC, "ppb", device_name, VOC_samples, VOC_MIN, VOC_MAX);
|
|
AQSSensor SGP30_eco2("eCO2", SGP30_eCO2, "ppm", device_name, VOC_samples, VOC_MIN, VOC_MAX);
|
|
AQSSensor SGP30_rawh2("Raw_H2", SGP30_rawH2, "#", device_name, VOC_samples, VOC_MIN, VOC_RAW_MAX);
|
|
AQSSensor SGP30_rawethanol("Raw_Ethanol", SGP30_rawEthanol, "#", device_name, VOC_samples, VOC_MIN, VOC_RAW_MAX);
|
|
|
|
void initVOCsensor(void)
|
|
{
|
|
Serial.println("VOCSensor: Init SGP30: ");
|
|
//wire1.setPins(I2C_2_SDA, I2C_2_SCL);
|
|
//if (!sgp.begin(&wire1))
|
|
Wire.begin();
|
|
if (!sgp.begin())
|
|
{
|
|
Serial.println("VOCSensor: Init Failed (SGP30 not found)");
|
|
}
|
|
else
|
|
{
|
|
sgp.getSerialID();
|
|
//Get version number
|
|
sgp.getFeatureSetVersion();
|
|
Serial.print("VOCSensor: serial =0x");
|
|
Serial.println((unsigned long)sgp.serialID, HEX);
|
|
addSensorToList(&SGP30_tvoc);
|
|
addSensorToList(&SGP30_eco2);
|
|
|
|
sgp.initAirQuality();
|
|
sgp.measureAirQuality();
|
|
|
|
Serial.println("VOCSensor: Init OK");
|
|
}
|
|
}
|
|
|
|
void handleVOCsensor(void)
|
|
{
|
|
uint32_t timenow = millis();
|
|
if ((timenow - lastVOCtime > VOC_INTERVAL) || !lastVOCtime)
|
|
{
|
|
sgp.measureAirQuality();
|
|
|
|
SGP30_tvoc.set(sgp.TVOC);
|
|
SGP30_eco2.set(sgp.CO2);
|
|
|
|
SGP30_tvoc.publish();
|
|
SGP30_eco2.publish();
|
|
|
|
lastVOCtime = timenow;
|
|
}
|
|
} |