49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
#include "eeprom_animacao.h"
|
|
#include "nvs.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_log.h"
|
|
|
|
static const char *TAG = "EEPROM_ANIM";
|
|
|
|
#define NAMESPACE "storage"
|
|
#define KEY_ANIM "animacao"
|
|
|
|
// valor em RAM, sempre igual ao guardado
|
|
uint8_t animacao = 0;
|
|
|
|
void animacao_load(void)
|
|
{
|
|
nvs_handle_t handle;
|
|
esp_err_t err = nvs_open(NAMESPACE, NVS_READONLY, &handle);
|
|
|
|
if (err == ESP_OK) {
|
|
err = nvs_get_u8(handle, KEY_ANIM, &animacao);
|
|
nvs_close(handle);
|
|
|
|
if (err != ESP_OK) {
|
|
animacao = 0; // default
|
|
}
|
|
} else {
|
|
animacao = 0; // default
|
|
}
|
|
|
|
ESP_LOGI(TAG, "Carregado animacao = %u", animacao);
|
|
}
|
|
|
|
void animacao_save(uint8_t v)
|
|
{
|
|
nvs_handle_t handle;
|
|
esp_err_t err = nvs_open(NAMESPACE, NVS_READWRITE, &handle);
|
|
|
|
if (err == ESP_OK) {
|
|
nvs_set_u8(handle, KEY_ANIM, v);
|
|
nvs_commit(handle);
|
|
nvs_close(handle);
|
|
|
|
animacao = v; // atualiza RAM também
|
|
ESP_LOGI(TAG, "Gravado animacao = %u", v);
|
|
} else {
|
|
ESP_LOGW(TAG, "Falha ao abrir NVS p/ animacao");
|
|
}
|
|
}
|