Limit reboots when USB flash drive is not present.

This commit is contained in:
Joe Kearney 2025-11-16 20:51:59 -06:00
parent 14ec8fe280
commit 1c2f281579

View file

@ -55,6 +55,8 @@ static const char *TAG = "USB";
static const char *OTA_FILE = "/usb/esp/OTA_URL.txt"; static const char *OTA_FILE = "/usb/esp/OTA_URL.txt";
const char *CONFIG_FILE = "/usb/esp/config.txt"; const char *CONFIG_FILE = "/usb/esp/config.txt";
__NOINIT_ATTR uint_fast8_t Restarts;
typedef enum typedef enum
{ {
USB_STATE_UNINITIALIZED, USB_STATE_UNINITIALIZED,
@ -281,6 +283,8 @@ static void app_usb_task(void *args)
static uint8_t device_address = 1; static uint8_t device_address = 1;
usb_message_t msg; usb_message_t msg;
esp_reset_reason() == ESP_RST_POWERON ? Restarts = 0 : Restarts++;
while (true) while (true)
{ {
switch (Current_State) switch (Current_State)
@ -313,9 +317,16 @@ static void app_usb_task(void *args)
} }
else else
{ {
KLOG_ERROR(TAG, "No flash drive detected--rebooting."); if (Restarts <= 3)
vTaskDelay(pdMS_TO_TICKS(100)); {
esp_restart(); KLOG_ERROR(TAG, "No flash drive detected--rebooting.");
vTaskDelay(pdMS_TO_TICKS(100));
esp_restart();
}
else
{
KLOG_WARN(TAG, "No flash drive detected after multiple attempts.");
}
} }
} }
break; break;