#include "driver/gpio.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "board.h" #define BTN_GPIO GPIO_NUM_0 #define BTN_HOLD_MS 10000 extern void wifi_request_portal_physical(void); static void button_task(void *arg) { gpio_config_t io = { .pin_bit_mask = 1ULL << BTN_GPIO, .mode = GPIO_MODE_INPUT, .pull_up_en = GPIO_PULLUP_ENABLE, }; gpio_config(&io); /* ignore a button still held from boot */ while (gpio_get_level(BTN_GPIO) == 0) vTaskDelay(pdMS_TO_TICKS(50)); int held = 0; for (;;) { if (gpio_get_level(BTN_GPIO) == 0) { held += 50; if (held >= BTN_HOLD_MS) { ESP_LOGW("button", "long press -> portal"); wifi_request_portal_physical(); /* does not return */ } } else { held = 0; } vTaskDelay(pdMS_TO_TICKS(50)); } } void button_start(void) { xTaskCreate(button_task, "btn", 3072, NULL, 3, NULL); }