feat(nodes): WIP supervisor first implementation

wip: untested
This commit is contained in:
adrien balleyguier
2026-04-22 09:55:13 +02:00
committed by Klagarge
parent f0bc4ee373
commit e1d274470b
9 changed files with 82 additions and 3 deletions

View File

@@ -0,0 +1,9 @@
#include "ble_advertiser.h"
enum error_code ble_init(){
return success;
}
enum error_code ble_advertise(){
return success;
}

View File

@@ -1,4 +1,9 @@
#ifndef BLE_ADVERTISER_H
#define BLE_ADVERTISER_H
#include "error_code.h"
enum error_code ble_init();
enum error_code ble_advertise();
#endif //BLE_ADVERTISER_H

View File

@@ -1,5 +1,7 @@
#include "co2_level.h"
const int CO2_LEVEL_EMPTY_ROOM = 400; // [ppm]
enum error_code co2_lvl_init(){
return success;
}

View File

@@ -3,6 +3,8 @@
#include "error_code.h"
extern const int CO2_LEVEL_EMPTY_ROOM; // [ppm]
enum error_code co2_lvl_init();
int co2_lvl_get_value();

View File

@@ -3,6 +3,8 @@
enum error_code{
success = 0,
init_failed,
error_unknown,
error_code_last, // iteration purpose
};

View File

@@ -8,6 +8,8 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include "supervisor.h"
int main(void){
supervisor_init();
supervisor_run();

View File

@@ -1,10 +1,53 @@
#include "supervisor.h"
const int SLEEP_GRANULARITY = 2; // [min]
const int SLEEP_MIN_DURATION = SLEEP_GRANULARITY; // [min]
const int SLEEP_MAX_DURATION = 30; // [min]
enum error_code supervisor_init(){
return success;
enum error_code ret = init_failed;
ret = ble_init();
if(success == ret){
ret = co2_lvl_init();
if(success == ret){
ret = hygro_init();
if(success == ret){
ret = thermo_init();
if(success == ret){
ret = window_init();
}else{}
}else{}
}else{}
}else{}
// debug with led set -> init and blink led red
return ret;
}
enum error_code supervisor_run(){
while(1);
return success;
int co2_lvl_value = -1;
int hygro_value = -1;
int thermo_value = -1;
enum window_status window_value = unknown;
int current_sleep_time = SLEEP_MIN_DURATION;
while(1){
co2_lvl_value = co2_lvl_get_value();
hygro_value = hygro_get_value();
thermo_value = thermo_get_value();
window_value = window_get_value();
// maybe change arguments order
// todo : manage special values
ble_advertise(co2_lvl_value, hygro_value, thermo_value, window_value);
if((co2_lvl_value > CO2_LEVEL_EMPTY_ROOM) || (window_value == open)){
// there are people in the room, or someone forgot to close the window
current_sleep_time = SLEEP_MIN_DURATION;
}else{
// no one is in the room, we can wait a liitle bit longer before getting the next data point
current_sleep_time += SLEEP_GRANULARITY;
if(current_sleep_time > SLEEP_MAX_DURATION){
current_sleep_time = SLEEP_MAX_DURATION;
}else{}
}
k_sleep(K_MINUTES(current_sleep_time));
}
return error_unknown; // should never return
}

View File

@@ -1,13 +1,20 @@
#ifndef SUPERVISOR_H
#define SUPERVISOR_H
#include <zephyr/kernel.h>
#include "error_code.h"
#include "ble_advertiser.h"
#include "window_status.h"
#include "thermometer.h"
#include "hygrometer.h"
#include "co2_level.h"
extern const int SLEEP_GRANULARITY; // [min]
extern const int SLEEP_MIN_DURATION; // [min]
extern const int SLEEP_MAX_DURATION; // [min]
enum error_code supervisor_init();
enum error_code supervisor_run();

View File

@@ -3,6 +3,13 @@
#include "error_code.h"
enum window_status{
closed = 0,
open,
unknown,
windows_status_last, // iteration purpose
};
enum error_code window_init();
int window_get_value();