util fct
This commit is contained in:
parent
02967d4449
commit
dcc43d7fbc
@ -1,3 +1,3 @@
|
|||||||
idf_component_register(SRCS "sensirion_common.c" "sensirion_i2c.c" "sensirion_i2c_hal.c" "scd4x_i2c.c" "scd4x_config.c"
|
idf_component_register(SRCS "sensirion_common.c" "sensirion_i2c.c" "sensirion_i2c_hal.c" "scd4x_i2c.c" "scd4x_config.c" "scd4x_util.c"
|
||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
REQUIRES driver nvs_flash)
|
REQUIRES driver nvs_flash)
|
||||||
|
10
include/scd4x_util.h
Normal file
10
include/scd4x_util.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef SCD4X_UTIL_H
|
||||||
|
#define SCD4X_UTIL_H
|
||||||
|
|
||||||
|
#include "scd4x_data.h"
|
||||||
|
|
||||||
|
void update_scd4x_measures(scd4x_data_t* data);
|
||||||
|
void start_scd4x_measure(scd4x_config_t* conf);
|
||||||
|
void scd4x_wait_wake_up();
|
||||||
|
|
||||||
|
#endif
|
42
scd4x_util.c
Normal file
42
scd4x_util.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "scd4x_data.h"
|
||||||
|
#include "scd4x_i2c.h"
|
||||||
|
|
||||||
|
void update_scd4x_measures(scd4x_data_t* data){
|
||||||
|
uint16_t dataReady;
|
||||||
|
scd4x_get_data_ready_status(&dataReady);
|
||||||
|
if(!(dataReady & 0x07FF)){
|
||||||
|
ESP_LOGI("MAIN", "no new sensor data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int16_t error = scd4x_read_measurement(&data->co2, &data->temperature, &data->humidity);
|
||||||
|
if (error) ESP_LOGE("sensor fetch", "Error executing scd4x_read_measurement(): %i\n", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void scd4x_wait_wake_up(){
|
||||||
|
scd4x_wake_up();
|
||||||
|
for(int i=0; i<5; i++){
|
||||||
|
uint16_t s0, s1, s2;
|
||||||
|
int16_t res=scd4x_get_serial_number(&s0, &s1, &s2);
|
||||||
|
if(res == 0) break;
|
||||||
|
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void start_scd4x_measure(scd4x_config_t* conf){
|
||||||
|
switch(conf->mode){
|
||||||
|
case SCD4X_NORMAL_MODE:
|
||||||
|
ESP_ERROR_CHECK(scd4x_start_periodic_measurement());
|
||||||
|
ESP_LOGI("scd4x init","started in normal mode");
|
||||||
|
break;
|
||||||
|
case SCD4X_LP_MODE:
|
||||||
|
ESP_ERROR_CHECK(scd4x_start_low_power_periodic_measurement());
|
||||||
|
ESP_LOGI("scd4x init","started in low power mode");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
conf->enabled = true;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user