Port to ESP32
This commit is contained in:
94
main/main.c
Normal file
94
main/main.c
Normal file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
* @file main.c
|
||||
* @brief Main application entry point for LED Controller
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "animation.h"
|
||||
#include "led.h"
|
||||
|
||||
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, BLE)
|
||||
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");
|
||||
ESP_LOGI(TAG, "BLE Device Name: LED-Controller");
|
||||
ESP_LOGI(TAG, "Connect via Web-BLE to configure");
|
||||
|
||||
// Main loop - just monitor system status
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
|
||||
// Periodic status logging
|
||||
//const controller_config_t *config = control_get_config();
|
||||
ESP_LOGI(TAG, "Status - Mode: %d, BLE: %s, PWM Active: %s",
|
||||
control_get_animation_mode(),
|
||||
control_is_ble_enabled() ? "ON" : "OFF",
|
||||
"N/A"); // Could add rcsignal_is_active() here
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user