@@ -1,2 +1,3 @@
|
|||||||
|
CONFIG_I2C=y
|
||||||
CONFIG_SENSOR=y
|
CONFIG_SENSOR=y
|
||||||
CONFIG_BT=y
|
CONFIG_BT=y
|
||||||
|
|||||||
@@ -1,11 +1,34 @@
|
|||||||
#include "co2_level.h"
|
#include "co2_level.h"
|
||||||
|
|
||||||
|
static const struct device* dev = DEVICE_DT_GET_ONE(ams_ccs811);
|
||||||
|
|
||||||
const int CO2_LEVEL_EMPTY_ROOM = 400; // [ppm]
|
const int CO2_LEVEL_EMPTY_ROOM = 400; // [ppm]
|
||||||
|
|
||||||
enum error_code co2_lvl_init(){
|
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){
|
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;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#ifndef CO2_LEVEL_H
|
#ifndef CO2_LEVEL_H
|
||||||
#define CO2_LEVEL_H
|
#define CO2_LEVEL_H
|
||||||
|
|
||||||
|
#include <zephyr/drivers/sensor.h>
|
||||||
|
#include <zephyr/drivers/sensor/ccs811.h>
|
||||||
|
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
|
#include "hygrometer.h"
|
||||||
|
#include "thermometer.h"
|
||||||
|
|
||||||
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]
|
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user