feat(nodes): adding thermometer and hygrometer
Changed sensor value retrieval to return error_code
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
CONFIG_GPIO=y
|
CONFIG_GPIO=y
|
||||||
|
CONFIG_SENSOR=y
|
||||||
|
CONFIG_I2C=y
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ enum error_code ble_init(){
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum error_code ble_advertise(){
|
enum error_code ble_advertise(
|
||||||
|
int co2_lvl_value_ptr,
|
||||||
|
int hygro_value_ptr,
|
||||||
|
int thermo_value_ptr,
|
||||||
|
enum window_status window_value_ptr
|
||||||
|
){
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,14 @@
|
|||||||
#define BLE_ADVERTISER_H
|
#define BLE_ADVERTISER_H
|
||||||
|
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
|
#include "window_status.h"
|
||||||
|
|
||||||
enum error_code ble_init();
|
enum error_code ble_init();
|
||||||
enum error_code ble_advertise();
|
enum error_code ble_advertise(
|
||||||
|
int co2_lvl_value_ptr,
|
||||||
|
int hygro_value_ptr,
|
||||||
|
int thermo_value_ptr,
|
||||||
|
enum window_status window_value_ptr
|
||||||
|
);
|
||||||
|
|
||||||
#endif //BLE_ADVERTISER_H
|
#endif //BLE_ADVERTISER_H
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ enum error_code co2_lvl_init(){
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int co2_lvl_get_value(){
|
enum error_code co2_lvl_get_value(int* holder){
|
||||||
return 0;
|
return success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,6 @@
|
|||||||
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]
|
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]
|
||||||
|
|
||||||
enum error_code co2_lvl_init();
|
enum error_code co2_lvl_init();
|
||||||
int co2_lvl_get_value();
|
enum error_code co2_lvl_get_value(int* holder);
|
||||||
|
|
||||||
#endif //CO2_LEVEL_H
|
#endif //CO2_LEVEL_H
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#ifndef ERROR_CODE_H
|
#ifndef ERROR_CODE_H
|
||||||
#define ERROR_CODE_H
|
#define ERROR_CODE_H
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
enum error_code{
|
enum error_code{
|
||||||
success = 0,
|
success = 0,
|
||||||
init_failed,
|
init_failed,
|
||||||
|
read_failed,
|
||||||
error_unknown,
|
error_unknown,
|
||||||
error_code_last, // iteration purpose
|
error_code_last, // iteration purpose
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
#include "hygrometer.h"
|
#include "hygrometer.h"
|
||||||
|
|
||||||
|
static const struct device* dev = DEVICE_DT_GET_ONE(st_hts221);
|
||||||
|
|
||||||
enum error_code hygro_init(){
|
enum error_code hygro_init(){
|
||||||
return success;
|
enum error_code ret = init_failed;
|
||||||
|
if(device_is_ready(dev)){
|
||||||
|
ret = success;
|
||||||
|
}else{}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hygro_get_value(){
|
enum error_code hygro_get_value(int* holder){
|
||||||
return 0;
|
enum error_code ret = read_failed;
|
||||||
|
struct sensor_value humidity;
|
||||||
|
if(sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &humidity) >= 0){
|
||||||
|
*holder = sensor_value_to_deci(&humidity);
|
||||||
|
ret = success;
|
||||||
|
}else{}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
#ifndef HYGROMETER_H
|
#ifndef HYGROMETER_H
|
||||||
#define HYGROMETER_H
|
#define HYGROMETER_H
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/sensor.h>
|
||||||
|
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
|
|
||||||
enum error_code hygro_init();
|
enum error_code hygro_init();
|
||||||
int hygro_get_value();
|
enum error_code hygro_get_value(int* holder);
|
||||||
|
|
||||||
#endif //HYGROMETER_H
|
#endif //HYGROMETER_H
|
||||||
|
|||||||
@@ -28,15 +28,16 @@ enum error_code supervisor_run(){
|
|||||||
int hygro_value = -1;
|
int hygro_value = -1;
|
||||||
int thermo_value = -1;
|
int thermo_value = -1;
|
||||||
enum window_status window_value = unknown;
|
enum window_status window_value = unknown;
|
||||||
|
enum error_code co2_lvl_status, hygro_status, thermo_status, window_status;
|
||||||
int current_sleep_time = SLEEP_MIN_DURATION;
|
int current_sleep_time = SLEEP_MIN_DURATION;
|
||||||
while(1){
|
while(1){
|
||||||
co2_lvl_value = co2_lvl_get_value();
|
co2_lvl_status = co2_lvl_get_value(&co2_lvl_value);
|
||||||
hygro_value = hygro_get_value();
|
hygro_status = hygro_get_value(&hygro_value);
|
||||||
thermo_value = thermo_get_value();
|
thermo_status = thermo_get_value(&thermo_value);
|
||||||
window_value = window_get_value();
|
window_status = window_get_value(&window_value);
|
||||||
// maybe change arguments order
|
// maybe change arguments order
|
||||||
// todo : manage special values
|
// todo : manage special values
|
||||||
ble_advertise(co2_lvl_value, hygro_value, thermo_value, window_value);
|
ble_advertise(co2_lvl_value, hygro_value, thermo_value, window_status);
|
||||||
if((co2_lvl_value > CO2_LEVEL_EMPTY_ROOM) || (window_value == open)){
|
if((co2_lvl_value > CO2_LEVEL_EMPTY_ROOM) || (window_value == open)){
|
||||||
// there are people in the room, or someone forgot to close the window
|
// there are people in the room, or someone forgot to close the window
|
||||||
current_sleep_time = SLEEP_MIN_DURATION;
|
current_sleep_time = SLEEP_MIN_DURATION;
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
#include "thermometer.h"
|
#include "thermometer.h"
|
||||||
|
|
||||||
|
static const struct device* dev = DEVICE_DT_GET_ONE(st_hts221);
|
||||||
|
|
||||||
enum error_code thermo_init(){
|
enum error_code thermo_init(){
|
||||||
return success;
|
enum error_code ret = init_failed;
|
||||||
|
if(device_is_ready(dev)){
|
||||||
|
ret = success;
|
||||||
|
}else{}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int thermo_get_value(){
|
enum error_code thermo_get_value(int* holder){
|
||||||
return 0;
|
enum error_code ret = read_failed;
|
||||||
|
struct sensor_value temp;
|
||||||
|
if(sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp) >= 0){
|
||||||
|
*holder = sensor_value_to_deci(&temp);
|
||||||
|
ret = success;
|
||||||
|
}else{}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
#ifndef THERMOMETER_H
|
#ifndef THERMOMETER_H
|
||||||
#define THERMOMETER_H
|
#define THERMOMETER_H
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/sensor.h>
|
||||||
|
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
|
|
||||||
enum error_code thermo_init();
|
enum error_code thermo_init();
|
||||||
int thermo_get_value();
|
enum error_code thermo_get_value(int* holder);
|
||||||
|
|
||||||
#endif //THERMOMETER_H
|
#endif //THERMOMETER_H
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ enum error_code window_init(){
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int window_get_value(){
|
enum error_code window_get_value(enum window_status* holder){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ enum window_status{
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum error_code window_init();
|
enum error_code window_init();
|
||||||
int window_get_value();
|
enum error_code window_get_value(enum window_status* holder);
|
||||||
|
|
||||||
#endif //WINDOW_STATUS_
|
#endif //WINDOW_STATUS_
|
||||||
|
|||||||
Reference in New Issue
Block a user