#include "esp_err.h" #include "nvs.h" #include "configuration.h" #include "power_profiler.h" void init_configuration_from_nvs(configuration* conf){ nvs_handle_t handle; ESP_ERROR_CHECK(nvs_open("storage", NVS_READONLY, &handle)); nvs_get_u32(handle, "refresh_delay", &conf->refresh_delay); nvs_get_u16(handle, "zero_c_nsamp", &conf->zero_cali_nsamp); nvs_get_i32(handle, "range", &conf->range); nvs_get_i32(handle, "auto_range", &conf->auto_range); for(int i = 0; i < INPUTS_NUM; i++){ char key[16]; sprintf(key, "offset%d", i); nvs_get_u32(handle, key, &conf->offsets[i]); } nvs_close(handle); } void save_configuration_to_nvs(configuration* conf){ nvs_handle_t handle; ESP_ERROR_CHECK(nvs_open("storage", NVS_READWRITE, &handle)); nvs_set_u32(handle, "refresh_delay", conf->refresh_delay); nvs_set_u16(handle, "zero_c_nsamp", conf->zero_cali_nsamp); nvs_set_i32(handle, "range", conf->range); nvs_set_i32(handle, "auto_range", conf->auto_range); for(int i = 0; i < INPUTS_NUM; i++){ char key[16]; sprintf(key, "offset%d", i); nvs_set_u32(handle, key, conf->offsets[i]); } ESP_ERROR_CHECK(nvs_commit(handle)); nvs_close(handle); }