/**
 * @file    led_ancs.h
 *
 * @author  PerL13
 * @date    2025-09-30
 * @version 1.2
 *
 * @note    Set the IO and LED strip length in menuconfig
 * supports strobe and burst mode also settable via menuconfig
 *
 */

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

#define LED_STRIP_PIN            CONFIG_ILLUMINANCS_LED_STRIP_PIN //Set through menuconfig
#define LED_STRIP_COUNT          CONFIG_ILLUMINANCS_LED_STRIP_COUNT //Set through menuconfig
#define LED_SOLID_TIME_MS        10000   //solid duration
#define LED_CHASE_TIME_MS        10000   //chase duration
#define LED_STROBE_TIME_MS       10000   //strobe duration
#define LED_TEST_1_TIME_MS       30000   //test 1 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_TEST_1_ON_MS         1000    //led on time for test 1
#define LED_TEST_1_OFF_MS        1000    //led off time for test 1
#define LED_STROBE_PAUSE_MS      1000    //pause btw bursts periods
#define LED_STATUS_TIME_MS       300000L //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_TEST_1,
} 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 index;
    int8_t left_position;
    int8_t right_position;
} led_state_t;

static const rgb_t category_colors[] = {
    {  0, 255,   0}, // 0  Green
    {255, 255, 255}, // 1  White
    {200,   0, 100}, // 2  DeepPink
    {  0, 255, 255}, // 3  Cyan
    {255, 255,   0}, // 4  Yellow
    {255, 127,  80}, // 5  Coral
    {255, 128,   0}, // 6  Orange
    {128,   0, 255}, // 7  Violet
    {191, 255,   0}, // 8  Lime
    {128, 112,  32}, // 9  Gold
    {128,  96, 128}, // 10 Lavender
    {  0, 128, 128}, // 11 Teal
    {255, 128, 128}, // 12 Pink
};

// Public API
void led_init(void);
void led_set_solid(const uint8_t r, const uint8_t g, const uint8_t b);
void led_set_by_category(const uint8_t cid);
void led_set_test_1(void); //this shows all different category_colors
// Non-blocking update function (call frequently in loop)
void led_update(void);
