/**
 * @file    led_ancs.h
 *
 * @author  PerL13
 * @date    2025-09-16
 * @version 1.1
 *
 * @note    This module assumes LEDs are connected to GPIO16.
 *
 */

#include <stdio.h>
#include <stdlib.h>

#define LED_STRIP_PIN            16
#define LED_STRIP_COUNT          14
#define LED_CHASE_TIME_MS        10000   //chase duration
#define LED_STROBE_TIME_MS       10000   //strobe duration
#define LED_STROBE_BURSTS        5       //no of burst before pause
#define LED_STROBE_PERIOD_MS     100     //burst length
#define LED_STROBE_PAUSE_MS      1000    //pause btw bursts periods
#define LED_STATUS_TIME_MS       600000L //status duration
#define LED_DECAY_STEP           50      // smaller = longer tail
#define LED_BRIGHTNESS_MIN       20
#define LED_BRIGHTNESS_MAX       255

typedef struct {
    uint8_t r, g, b;
} rgb_t;

typedef enum {
    LED_MODE_OFF,
    LED_MODE_SOLID,
    LED_MODE_STROBE,
    LED_MODE_CHASE,
    LED_MODE_STATUS,
} led_mode_t;

typedef struct {
    led_mode_t mode;
    uint8_t strobe_on;
    uint8_t r, g, b;
    uint32_t duration_ms;
    uint32_t start_time;
    uint8_t chase_index;
    uint8_t left_position;
    uint8_t right_position;
} led_state_t;

static const rgb_t category_colors[] = {
    {  0, 255,   0}, // 0  green
    {255, 255, 255}, // 1  White
    {139,   0,   0}, // 2  DarkRed
    {  0, 255, 255}, // 3  Cyan
    {255, 255,   0}, // 4  Yellow
    {255, 140,   0}, // 5  DarkOrange
    {255, 165,   0}, // 6  Orange
    {255,   0, 255}, // 7  Magenta
    {127, 255, 212}, // 8  Aquamarine
    {255,  20, 147}, // 9  DeepPink
    {238, 130, 238}, // 10 Violet
    {164,  42,  42}, // 11 Brown
    {128, 128, 128}, // 12 Grey
};

// Public API
void led_init(void);
void led_set_solid(uint8_t r, uint8_t g, uint8_t b);
void set_led_by_category(const uint8_t cid);
// Non-blocking update function (call frequently in loop)
void led_update(void);
