pumps now write values to nvs

This commit is contained in:
Morgan 'ARR\!' Allen 2021-09-23 22:58:57 -07:00
parent afd99d2586
commit 88f4c96247

View file

@ -5,6 +5,7 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "main.h"
#include "pumps.h" #include "pumps.h"
#define TAG "PUMP!" #define TAG "PUMP!"
@ -17,6 +18,14 @@ static uint8_t pumps_enabled[PUMPS] = {0};
static uint8_t pumps_state[PUMPS] = {0}; static uint8_t pumps_state[PUMPS] = {0};
static uint8_t safety = 1; static uint8_t safety = 1;
void pumps_update_config() {
ESP_LOGI(TAG, "writing config");
size_t size = sizeof(uint8_t) * PUMPS;
nvs_set_blob(config_handle, "pumps_duration", &pumps_duration, size);
nvs_commit(config_handle);
}
uint8_t pumps_set_duration(uint8_t idx, uint8_t time) { uint8_t pumps_set_duration(uint8_t idx, uint8_t time) {
if(idx > PUMPS) return PUMPS_ERR_OUT_IDX; if(idx > PUMPS) return PUMPS_ERR_OUT_IDX;
@ -24,6 +33,8 @@ uint8_t pumps_set_duration(uint8_t idx, uint8_t time) {
pumps_duration[idx] = time; pumps_duration[idx] = time;
pumps_update_config();
return 0; return 0;
} }
@ -117,8 +128,12 @@ uint8_t pumps_init() {
memset(&pumps_enabled, 0, sizeof(uint8_t) * PUMPS); memset(&pumps_enabled, 0, sizeof(uint8_t) * PUMPS);
memset(&pumps_duration, 10, sizeof(uint8_t) * PUMPS); memset(&pumps_duration, 10, sizeof(uint8_t) * PUMPS);
//uint32_t durations; size_t size = sizeof(uint8_t) * PUMPS;
//esp_err_t err = nvs_get_i32(config_handle, "durations", &durations); if(!nvs_get_blob(config_handle, "pumps_duration", &pumps_duration, &size)) {
ESP_LOGI(TAG, "Initializing pumps config");
nvs_set_blob(config_handle, "pumps_duration", &pumps_duration, size);
};
ESP_LOGI(TAG, "pumps_enabled: %d %d %d %d", pumps_enabled[0], pumps_enabled[1], pumps_enabled[2], pumps_enabled[3]); ESP_LOGI(TAG, "pumps_enabled: %d %d %d %d", pumps_enabled[0], pumps_enabled[1], pumps_enabled[2], pumps_enabled[3]);
ESP_LOGI(TAG, "pumps_duration: %d %d %d %d", pumps_duration[0], pumps_duration[1], pumps_duration[2], pumps_duration[3]); ESP_LOGI(TAG, "pumps_duration: %d %d %d %d", pumps_duration[0], pumps_duration[1], pumps_duration[2], pumps_duration[3]);