100 lines
2.3 KiB
C
100 lines
2.3 KiB
C
/**
|
|
* @file control.c
|
|
* @brief Control module implementation
|
|
*/
|
|
|
|
#include "control.h"
|
|
#include "config.h"
|
|
#include "led.h"
|
|
#include "rcsignal.h"
|
|
#include "localbtn.h"
|
|
#include "animation.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_log.h"
|
|
|
|
static const char *TAG = "CONTROL";
|
|
static uint8_t current_animation_mode = 0;
|
|
|
|
// Animation mode change callback
|
|
static void on_mode_change()
|
|
{
|
|
current_animation_mode = (current_animation_mode + 1) % ANIM_MODE_COUNT;
|
|
animation_set_mode((animation_mode_t)current_animation_mode);
|
|
}
|
|
|
|
void control_set_animation_mode(uint8_t mode)
|
|
{
|
|
if (mode >= ANIM_MODE_COUNT)
|
|
{
|
|
mode = 0;
|
|
}
|
|
on_mode_change(mode);
|
|
}
|
|
|
|
uint8_t control_get_animation_mode(void)
|
|
{
|
|
return current_animation_mode;
|
|
}
|
|
|
|
// Main initialization
|
|
esp_err_t control_init(void)
|
|
{
|
|
esp_err_t ret;
|
|
|
|
ESP_LOGI(TAG, "Initializing LED Controller...");
|
|
|
|
// Initialize config
|
|
ret = config_init();
|
|
if (ret != ESP_OK)
|
|
{
|
|
ESP_LOGE(TAG, "Config init failed: %s", esp_err_to_name(ret));
|
|
return ret;
|
|
}
|
|
|
|
config_t current_config;
|
|
config_get_config(¤t_config);
|
|
|
|
// Initialize LED strips
|
|
ret = led_init(current_config.led_pin_strip_a, current_config.led_pin_strip_b,
|
|
current_config.led_count_strip_a, current_config.led_count_strip_a);
|
|
if (ret != ESP_OK)
|
|
{
|
|
ESP_LOGE(TAG, "LED init failed: %s", esp_err_to_name(ret));
|
|
return ret;
|
|
}
|
|
|
|
// Initialize animation system
|
|
ret = animation_init();
|
|
if (ret != ESP_OK)
|
|
{
|
|
ESP_LOGE(TAG, "Animation init failed: %s", esp_err_to_name(ret));
|
|
return ret;
|
|
}
|
|
|
|
// Initialize RC signal
|
|
ret = rcsignal_init(current_config.pwm_pin);
|
|
if (ret != ESP_OK)
|
|
{
|
|
ESP_LOGE(TAG, "RC signal init failed: %s", esp_err_to_name(ret));
|
|
return ret;
|
|
}
|
|
|
|
// Initialize local BTN
|
|
ret = localbtn_init(current_config.localBtn_pin);
|
|
if (ret != ESP_OK)
|
|
{
|
|
ESP_LOGE(TAG, "Local BTN init failed: %s", esp_err_to_name(ret));
|
|
return ret;
|
|
}
|
|
|
|
// Register mode change callback
|
|
rcsignal_register_callback(on_mode_change);
|
|
localbtn_register_callback(on_mode_change);
|
|
|
|
ESP_LOGI(TAG, "Control system initialized successfully");
|
|
|
|
return ESP_OK;
|
|
}
|