pumps now write values to nvs
This commit is contained in:
parent
afd99d2586
commit
88f4c96247
1 changed files with 17 additions and 2 deletions
19
main/pumps.c
19
main/pumps.c
|
@ -5,6 +5,7 @@
|
|||
#include "driver/gpio.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "pumps.h"
|
||||
|
||||
#define TAG "PUMP!"
|
||||
|
@ -17,6 +18,14 @@ static uint8_t pumps_enabled[PUMPS] = {0};
|
|||
static uint8_t pumps_state[PUMPS] = {0};
|
||||
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) {
|
||||
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_update_config();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -117,8 +128,12 @@ uint8_t pumps_init() {
|
|||
memset(&pumps_enabled, 0, sizeof(uint8_t) * PUMPS);
|
||||
memset(&pumps_duration, 10, sizeof(uint8_t) * PUMPS);
|
||||
|
||||
//uint32_t durations;
|
||||
//esp_err_t err = nvs_get_i32(config_handle, "durations", &durations);
|
||||
size_t size = sizeof(uint8_t) * PUMPS;
|
||||
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_duration: %d %d %d %d", pumps_duration[0], pumps_duration[1], pumps_duration[2], pumps_duration[3]);
|
||||
|
|
Loading…
Reference in a new issue