PCB lives now in its own git repo https://git.la10cy.net/DeltaLima/CanGrow-12V-PCB
58 lines
1.6 KiB
C
58 lines
1.6 KiB
C
/*
|
|
*
|
|
* include/Sensor/10_CCS811_.h - CCS811 CO2 I2C sensor
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include "Adafruit_CCS811.h"
|
|
|
|
#define SENSOR_10_NAME "CCS811"
|
|
|
|
const byte Sensor_10_CCS811_Addr[] = { 0x5a, 0x5b };
|
|
|
|
Adafruit_CCS811 CCS811[sizeof(Sensor_10_CCS811_Addr)];
|
|
|
|
/* Create main data array specifying max amount of readings */
|
|
float Sensor_10_CCS811[sizeof(Sensor_10_CCS811_Addr)][4];
|
|
|
|
void Sensor_10_CCS811_Update(const byte AddrId) {
|
|
const static char LogLoc[] PROGMEM = "[Sensor:10_CCS811:Update]";
|
|
if(CCS811[AddrId].available()){
|
|
if(!CCS811[AddrId].readData()){
|
|
/* keep the same order as in SensorIndex[].read[] !! */
|
|
/* CO2 in ppm */
|
|
Sensor_10_CCS811[AddrId][0] = CCS811[AddrId].geteCO2();
|
|
/* TVOC (Total Volatile Organic Compouds) */
|
|
Sensor_10_CCS811[AddrId][1] = CCS811[AddrId].getTVOC();
|
|
}
|
|
#ifndef DEBUG
|
|
else {
|
|
Log.error(F("%s 0x%x ERROR getting new data" CR), LogLoc, Sensor_10_CCS811_Addr[AddrId]);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
}
|
|
|
|
bool Sensor_10_CCS811_Init(const byte AddrId) {
|
|
/* Sensor Init function
|
|
*
|
|
* returns true (1) when Init was successful
|
|
* returns false (0) if not.
|
|
*/
|
|
const static char LogLoc[] PROGMEM = "[Sensor:10_CCS811:Init]";
|
|
bool returnCode;
|
|
|
|
if(CCS811[AddrId].begin(Sensor_10_CCS811_Addr[AddrId])) {
|
|
Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Sensor_10_CCS811_Addr[AddrId]);
|
|
Sensor_10_CCS811_Update(AddrId);
|
|
returnCode = true;
|
|
} else {
|
|
Log.error(F("%s FAILED! Not found at addr 0x%x" CR), LogLoc, Sensor_10_CCS811_Addr[AddrId]);
|
|
returnCode = false;
|
|
}
|
|
return returnCode;
|
|
}
|