split project a bit

This commit is contained in:
Myk
2024-04-07 03:01:19 +03:00
parent 590d4958c2
commit 54285dd721
5 changed files with 129 additions and 76 deletions

View File

@@ -0,0 +1,31 @@
// CCS811Sensor.cpp
#include "CCS811Sensor.h"
CCS811Sensor::CCS811Sensor(uint8_t wakePin) : _wakePin(wakePin), ccs811(wakePin) {
// Constructor sets the wake pin and initializes the ccs811 object
}
void CCS811Sensor::init(double* temperature, double* humidity) {
// Enable CCS811
bool ok = ccs811.begin();
// let's handle if not OK later
// Lock pointers to temperature and humidity values
ok = ccs811.start(CCS811_MODE_1SEC);
// if( !ok ) Serial.println("setup: CCS811 start FAILED");
_temperaturePtr = temperature;
_humidityPtr = humidity;
}
void CCS811Sensor::init() {
bool ok = ccs811.begin();
}
void CCS811Sensor::read_values(uint16_t* eco2, uint16_t* etvoc, uint16_t* errstat, uint16_t* raw) {
if (_temperaturePtr && _humidityPtr) {
// Set environmental data for CCS811 sensor using pointers
ccs811.set_envdata(*_temperaturePtr, *_humidityPtr);
}
// Read eCO2, eTVOC, error status, and raw data values from CCS811 sensor
ccs811.read(eco2, etvoc, errstat, raw);
}

View File

@@ -0,0 +1,19 @@
// HDC1080Sensor.cpp
#include "HDC1080Sensor.h"
HDC1080Sensor::HDC1080Sensor(uint8_t address) : _address(address) {
// Constructor sets the address
}
void HDC1080Sensor::init() {
hdc1080.begin(_address); // Initialize HDC1080 sensor with the specified address
}
void HDC1080Sensor::read_values(double* temperature, double* humidity, bool* success) {
if (temperature) *temperature = hdc1080.readTemperature();
if (humidity) *humidity = hdc1080.readHumidity();
// Set success flag based on whether readings were successful
if (success) *success = !isnan(*temperature) && !isnan(*humidity);
}