#include "nvs.h" #include "nvs_flash.h" #include "esp_log.h" #include "bottom_half.h" #include "char_lcd.h" static const char* TAG = "nvs"; nvs_handle_t hw_handle; bool init_nvs() { esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { // NVS partition was truncated, erase and retry ESP_LOGE(TAG, "Failed to init nvs flash: %s.", esp_err_to_name(ret)); lcd_print(1, 0, "NVS: "); lcd_print(1, 4, esp_err_to_name(ret)); lcd_print(2, 0, "Press Yellow to skip"); lcd_print(3, 0, "Press Red to erase"); ButtonKey button; while (!( get_button_pressed(&button) && (button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10)); lcd_clear(); if (button == ButtonKey::button_yellow) { return false; } if (button == ButtonKey::button_red) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } } ESP_ERROR_CHECK(ret); return true; }