nvs
This commit is contained in:
parent
cd394834e6
commit
4f81adb83a
@ -1,6 +1,8 @@
|
|||||||
#ifndef LED_CONT_H
|
#ifndef LED_CONT_H
|
||||||
#define LED_CONT_H
|
#define LED_CONT_H
|
||||||
|
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
struct led_disp_config {
|
struct led_disp_config {
|
||||||
uint8_t output;
|
uint8_t output;
|
||||||
uint16_t min;
|
uint16_t min;
|
||||||
|
8
default_conf.csv
Normal file
8
default_conf.csv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default nvs configuration
|
||||||
|
key,type,encoding,value
|
||||||
|
main,namespace,,
|
||||||
|
wireless_conf,data,binary,00000001
|
||||||
|
sensor_conf,data,binary,00000000
|
||||||
|
led1_conf,data,hex2bin,0400DC051027640001FF
|
||||||
|
led2_conf,data,hex2bin,0500BC02DB05640001FF
|
||||||
|
led3_conf,data,hex2bin,06000000BB02640001FF
|
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "CO2_Sense.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
@ -18,54 +19,23 @@
|
|||||||
#include "sensirion_i2c_hal.h"
|
#include "sensirion_i2c_hal.h"
|
||||||
#include "scd4x_data.h"
|
#include "scd4x_data.h"
|
||||||
|
|
||||||
void fetch_sensor_task(void* pvParameters){
|
#define LED1_PIN CONFIG_LED_1_PIN
|
||||||
scd4x_config_t* conf = (scd4x_config_t*) pvParameters;
|
#define LED2_PIN CONFIG_LED_2_PIN
|
||||||
scd4x_data_t* measures = conf->measure;
|
#define LED3_PIN CONFIG_LED_3_PIN
|
||||||
while(1){
|
|
||||||
vTaskDelay(conf->delay * 1000 / portTICK_PERIOD_MS);
|
#define LED_NUMBER 3
|
||||||
int16_t error = scd4x_read_measurement(&measures->co2, &measures->temperature, &measures->humidity);
|
|
||||||
if (error)
|
|
||||||
ESP_LOGE("sensor fetch", "Error executing scd4x_read_measurement(): %i\n", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void app_main(void){
|
void app_main(void){
|
||||||
// init LEDs driver
|
init_nvs();
|
||||||
led_disp_config_t led_configs[] = {
|
|
||||||
[0] = {
|
nvs_handle_t nvs_handle;
|
||||||
.output = 4,
|
ESP_ERROR_CHECK(nvs_open("main", NVS_READWRITE, &nvs_handle));
|
||||||
.min = 1500,
|
|
||||||
.max = 10000,
|
|
||||||
.intensity = 100,
|
|
||||||
.blink_duty_cycle = 1,
|
|
||||||
.blink_delay = 255,
|
|
||||||
},
|
|
||||||
[1] = {
|
|
||||||
.output = 5,
|
|
||||||
.min = 700,
|
|
||||||
.max = 1499,
|
|
||||||
.intensity = 100,
|
|
||||||
.blink_duty_cycle = 1,
|
|
||||||
.blink_delay = 255,
|
|
||||||
},
|
|
||||||
[2] = {
|
|
||||||
.output = 6,
|
|
||||||
.min = 0,
|
|
||||||
.max = 699,
|
|
||||||
.intensity = 100,
|
|
||||||
.blink_duty_cycle = 1,
|
|
||||||
.blink_delay = 255,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
init_led_driver(led_configs, sizeof(led_configs)/sizeof(led_disp_config_t));
|
|
||||||
|
|
||||||
|
// init LEDs driver
|
||||||
|
led_disp_config_t* led_configs = generate_led_conf(nvs_handle,LED_NUMBER);
|
||||||
|
init_led_driver(led_configs, LED_NUMBER);
|
||||||
|
|
||||||
// init wifi AP (and nvs)
|
// init wifi AP (and nvs)
|
||||||
esp_err_t ret = nvs_flash_init();
|
|
||||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
||||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
||||||
ret = nvs_flash_init();
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(ret);
|
|
||||||
wifi_config_t wifi_config = wifi_config_generator("CO2Sense","testtest",1);
|
wifi_config_t wifi_config = wifi_config_generator("CO2Sense","testtest",1);
|
||||||
|
|
||||||
wifi_init_softap(wifi_config);
|
wifi_init_softap(wifi_config);
|
||||||
@ -127,6 +97,38 @@ void app_main(void){
|
|||||||
while(1){
|
while(1){
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
ESP_LOGI("MAIN", "co2 : %u ppm, temp : %d m°C, hum : %d mRH", sensor_data.co2, sensor_data.temperature, sensor_data.humidity);
|
ESP_LOGI("MAIN", "co2 : %u ppm, temp : %d m°C, hum : %d mRH", sensor_data.co2, sensor_data.temperature, sensor_data.humidity);
|
||||||
update_led_status(led_configs, sizeof(led_configs)/sizeof(led_disp_config_t), sensor_data.co2);
|
update_led_status(led_configs, LED_NUMBER, sensor_data.co2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fetch_sensor_task(void* pvParameters){
|
||||||
|
scd4x_config_t* conf = (scd4x_config_t*) pvParameters;
|
||||||
|
scd4x_data_t* measures = conf->measure;
|
||||||
|
while(1){
|
||||||
|
vTaskDelay(conf->delay * 1000 / portTICK_PERIOD_MS);
|
||||||
|
int16_t error = scd4x_read_measurement(&measures->co2, &measures->temperature, &measures->humidity);
|
||||||
|
if (error)
|
||||||
|
ESP_LOGE("sensor fetch", "Error executing scd4x_read_measurement(): %i\n", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_nvs(void){
|
||||||
|
esp_err_t ret = nvs_flash_init();
|
||||||
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
ret = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
led_disp_config_t* generate_led_conf(nvs_handle_t nvs, unsigned int nb){
|
||||||
|
led_disp_config_t* led_configs = malloc(nb * sizeof(led_disp_config_t));
|
||||||
|
size_t conf_size = sizeof(led_disp_config_t);
|
||||||
|
for(int i = 0; i < nb; i++){
|
||||||
|
char key[15];
|
||||||
|
sprintf(key, "led%i_conf", i+1);
|
||||||
|
ESP_ERROR_CHECK(nvs_get_blob(nvs, key, &led_configs[i], &conf_size));
|
||||||
|
}
|
||||||
|
return led_configs;
|
||||||
|
}
|
||||||
|
6
main/CO2_Sense.h
Normal file
6
main/CO2_Sense.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "ledController.h"
|
||||||
|
#include "nvs.h"
|
||||||
|
|
||||||
|
void fetch_sensor_task(void* pvParameters);
|
||||||
|
void init_nvs(void);
|
||||||
|
led_disp_config_t* generate_led_conf(nvs_handle_t nvs, unsigned int nb);
|
24
main/Kconfig.projbuild
Normal file
24
main/Kconfig.projbuild
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
menu "CO2Sense config"
|
||||||
|
menu "LED pins"
|
||||||
|
config LED_1_PIN
|
||||||
|
int "pin"
|
||||||
|
range 0 10
|
||||||
|
default 4
|
||||||
|
help
|
||||||
|
The pin on which the 1st LED is connected
|
||||||
|
|
||||||
|
config LED_2_PIN
|
||||||
|
int "pin"
|
||||||
|
range 0 10
|
||||||
|
default 5
|
||||||
|
help
|
||||||
|
The pin on which the 2nd LED is connected
|
||||||
|
|
||||||
|
config LED_3_PIN
|
||||||
|
int "pin"
|
||||||
|
range 0 10
|
||||||
|
default 6
|
||||||
|
help
|
||||||
|
The pin on which the 3rd LED is connected
|
||||||
|
endmenu
|
||||||
|
endmenu
|
13
sdkconfig
13
sdkconfig
@ -299,6 +299,19 @@ CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
|||||||
CONFIG_PARTITION_TABLE_MD5=y
|
CONFIG_PARTITION_TABLE_MD5=y
|
||||||
# end of Partition Table
|
# end of Partition Table
|
||||||
|
|
||||||
|
#
|
||||||
|
# CO2Sense config
|
||||||
|
#
|
||||||
|
|
||||||
|
#
|
||||||
|
# LED pins
|
||||||
|
#
|
||||||
|
CONFIG_LED_1_PIN=4
|
||||||
|
CONFIG_LED_2_PIN=5
|
||||||
|
CONFIG_LED_3_PIN=6
|
||||||
|
# end of LED pins
|
||||||
|
# end of CO2Sense config
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compiler options
|
# Compiler options
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user