add reset to factory

This commit is contained in:
Terrence
2024-09-10 00:45:13 +08:00
parent c212e0c482
commit 20c8c98b38
4 changed files with 90 additions and 14 deletions

View File

@ -9,29 +9,20 @@
#include "WifiConfigurationAp.h"
#include "Application.h"
#include "SystemInfo.h"
#include "SystemReset.h"
#define TAG "main"
#define STATS_TICKS pdMS_TO_TICKS(1000)
extern "C" void app_main(void)
{
// Check if the reset button is pressed
SystemReset system_reset;
system_reset.CheckButtons();
// Initialize the default event loop
ESP_ERROR_CHECK(esp_event_loop_create_default());
// Configure GPIO1 as INPUT, reset NVS flash if the button is pressed
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = 1ULL << 1;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_conf);
if (gpio_get_level(GPIO_NUM_1) == 0) {
ESP_LOGI(TAG, "Button is pressed, reset NVS flash");
nvs_flash_erase();
}
// Initialize NVS flash for WiFi configuration
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {