Files
espresso_frame/firmware/main/reset_button.c
T
tfaour d395cf3bb9
Build and push server image / build-and-push (push) Successful in 35s
Add two physical buttons: factory-reset and next-photo
Factory-reset (GPIO3, hold 10s): clears stored WiFi/server config and
restarts into provisioning -- the deliberate, USB-free replacement for
the earlier reverted RST-based auto-reprovisioning idea.

Next-photo (GPIO2, tap): wakes the device and forces the server to
advance immediately via a new POST /frame/advance, instead of waiting
for the refresh interval. Both buttons arm themselves as deep-sleep GPIO
wakeup sources so a press is noticed promptly even while asleep.

Also makes GET /frame/image side-effect-free: it now only advances once
refresh_interval_s has elapsed since the current photo was set (tracked
server-side), so a device reboot for any reason just redisplays the
current photo instead of silently skipping ahead. The server maintains a
small reorderable upcoming-photos queue, viewable and rearrangeable from
the web UI.
2026-07-18 23:28:36 -04:00

69 lines
2.1 KiB
C

#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_sleep.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "wifi_provisioning.h"
#include "reset_button.h"
static const char *TAG = "reset_button";
#if CONFIG_FRAME_RESET_BUTTON_GPIO >= 0
#define RESET_BUTTON_GPIO ((gpio_num_t)CONFIG_FRAME_RESET_BUTTON_GPIO)
#define RESET_BUTTON_POLL_MS 100
void reset_button_init(void)
{
gpio_config_t io_conf = {
.pin_bit_mask = 1ULL << RESET_BUTTON_GPIO,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
};
gpio_config(&io_conf);
/* Not esp_sleep_enable_ext1_wakeup_io(): its internal pull resistors
* don't hold once the RTC_PERIPH domain powers down for deep sleep, so
* the pin floats and reads spuriously low, waking the device instantly
* on every sleep entry (confirmed on hardware -- boot-looped every
* ~27s, the length of one fetch/display cycle, instead of sleeping for
* the configured interval). This GPIO-wakeup variant manages the pull
* resistor itself across the sleep transition. */
esp_sleep_enable_gpio_wakeup_on_hp_periph_powerdown(1ULL << RESET_BUTTON_GPIO, ESP_GPIO_WAKEUP_GPIO_LOW);
}
void reset_button_check(void)
{
if (gpio_get_level(RESET_BUTTON_GPIO) != 0) {
return; /* not pressed */
}
ESP_LOGI(TAG, "Reset button held -- hold for %dms to clear config and reprovision",
CONFIG_FRAME_RESET_BUTTON_HOLD_MS);
int elapsed_ms = 0;
while (elapsed_ms < CONFIG_FRAME_RESET_BUTTON_HOLD_MS) {
vTaskDelay(pdMS_TO_TICKS(RESET_BUTTON_POLL_MS));
elapsed_ms += RESET_BUTTON_POLL_MS;
if (gpio_get_level(RESET_BUTTON_GPIO) != 0) {
ESP_LOGI(TAG, "Reset button released early, continuing normal boot");
return;
}
}
ESP_LOGW(TAG, "Reset button held for %dms, clearing config and restarting into provisioning",
CONFIG_FRAME_RESET_BUTTON_HOLD_MS);
frame_config_clear();
esp_restart();
}
#else
void reset_button_init(void) {}
void reset_button_check(void) {}
#endif