feat(nodes): adding co2_level retrieval

Refs: #3
This commit is contained in:
adrien balleyguier
2026-05-04 14:38:34 +02:00
committed by Klagarge
parent 53ccda306b
commit bce2417ded
3 changed files with 30 additions and 1 deletions

View File

@@ -1,2 +1,3 @@
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BT=y

View File

@@ -1,11 +1,34 @@
#include "co2_level.h"
static const struct device* dev = DEVICE_DT_GET_ONE(ams_ccs811);
const int CO2_LEVEL_EMPTY_ROOM = 400; // [ppm]
enum error_code co2_lvl_init(){
return success;
enum error_code ret = init_failed;
if(device_is_ready(dev)){
ret = success;
}else{}
return ret;
}
enum error_code co2_lvl_get_value(int* holder){
struct sensor_value temp, humidity, co2;
enum error_code ret = read_failed;
int temp_value, humidity_value;
if( (success == thermo_get_value(&temp_value)) && (success == hygro_get_value(&humidity_value)) ){
// temperature conversion from deci, no function in the API
temp.val1 = temp_value/10;
temp.val2 = temp_value%10;
// humidity conversion is straight away
humidity.val1 = humidity_value;
if( (0 == sensor_sample_fetch(dev)) &&
(0 == sensor_channel_get(dev, SENSOR_CHAN_CO2, &co2))
){
*holder = co2.val1; // taking only the integer part
ret = success;
}else{}
}else{}
return success;
}

View File

@@ -1,7 +1,12 @@
#ifndef CO2_LEVEL_H
#define CO2_LEVEL_H
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/sensor/ccs811.h>
#include "error_code.h"
#include "hygrometer.h"
#include "thermometer.h"
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]