/** * @file main.c * @brief Main application entry point for LED Controller */ #include "control.h" #include "animation.h" #include "led.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "esp_system.h" #include static const char *TAG = "MAIN"; #define ANIMATION_UPDATE_RATE_MS 16 // ~60 FPS /** * @brief Animation update task * Runs continuously to update LED animations */ static void animation_task(void *pvParameters) { ESP_LOGI(TAG, "Animation task started"); TickType_t last_wake_time = xTaskGetTickCount(); const TickType_t update_interval = pdMS_TO_TICKS(ANIMATION_UPDATE_RATE_MS); while (1) { animation_update(); vTaskDelayUntil(&last_wake_time, update_interval); } } /** * @brief Main application entry point */ void app_main(void) { ESP_LOGI(TAG, "=============================================="); ESP_LOGI(TAG, " ESP32 LED Controller for Model Aircraft"); ESP_LOGI(TAG, "=============================================="); // Initialize control system (LEDs, PWM) esp_err_t ret = control_init(); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to initialize control system: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "System halted. Please reset the device."); while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); } } // Create animation update task BaseType_t task_ret = xTaskCreate( animation_task, "animation", 4096, NULL, 5, NULL); if (task_ret != pdPASS) { ESP_LOGE(TAG, "Failed to create animation task"); ESP_LOGE(TAG, "System halted. Please reset the device."); while (1) { vTaskDelay(pdMS_TO_TICKS(1000)); } } ESP_LOGI(TAG, "System initialized successfully"); // Main loop - just monitor system status while (1) { vTaskDelay(pdMS_TO_TICKS(5000)); // Periodic status logging ESP_LOGI(TAG, "Status - Mode: %d", control_get_animation_mode()); } }