feat: add factory reset on holding BOOT button

This commit is contained in:
2026-05-15 16:34:57 +02:00
parent 541d1be6ac
commit dd61c782cb
3 changed files with 58 additions and 1 deletions
+36 -1
View File
@@ -9,10 +9,12 @@
#include "esp_netif.h"
#include "esp_log.h"
#include "mdns.h"
#include "driver/gpio.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "freertos/task.h"
#include <stdio.h>
#include "driver/gpio.h"
#include <stdio.h>
#include <string.h>
#define TAG "main"
@@ -25,6 +27,37 @@
static EventGroupHandle_t s_evt;
static void reset_button_task(void *arg)
{
gpio_config_t io_conf = {
.pin_bit_mask = 1ULL << CONFIG_SENSOR_RESET_GPIO,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
gpio_config(&io_conf);
TickType_t held_since = 0;
const TickType_t threshold = pdMS_TO_TICKS(CONFIG_SENSOR_RESET_HOLD_MS);
for (;;) {
if (gpio_get_level(CONFIG_SENSOR_RESET_GPIO) == 0) {
if (held_since == 0) held_since = xTaskGetTickCount();
if ((xTaskGetTickCount() - held_since) >= threshold) {
ESP_LOGI(TAG, "Reset button held %d ms — factory resetting", CONFIG_SENSOR_RESET_HOLD_MS);
led_indicator_set(LED_ERROR);
vTaskDelay(pdMS_TO_TICKS(500));
config_store_erase();
esp_restart();
}
} else {
held_since = 0;
}
vTaskDelay(pdMS_TO_TICKS(50));
}
}
static void wifi_event_handler(void *arg, esp_event_base_t base,
int32_t id, void *data)
{
@@ -103,6 +136,8 @@ void app_main(void)
led_indicator_init();
led_indicator_set(LED_CONNECTING);
xTaskCreate(reset_button_task, "reset_btn", 4096, NULL, 1, NULL);
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());