#ifndef __BSP_LED_H__
#define __BSP_LED_H__

#include "board.h"
#include "drv_gpio.h"
#include "agile_led.h"

extern agile_led_t *led_r;
extern agile_led_t *led_g;
extern agile_led_t *led_y;

#define LED_R_PIN     GET_PIN(B, 12)
#define LED_G_PIN     GET_PIN(B, 13)
#define LED_Y_PIN     GET_PIN(B, 14)

#define LED_ON(x)     agile_led_on(led_##x)
#define LED_OFF(x)    agile_led_off(led_##x)
#define LED_TOGGLE(x) agile_led_toggle(led_##x)
#define LED_START(x)  agile_led_start(led_##x)

#define LED_STOP(x)              \
    do                           \
    {                            \
        LED_OFF(x);              \
        agile_led_stop(led_##x); \
    } while (0U)

#define LED_CTRL(x, light_mode, loop_cnt)                                   \
    do                                                                      \
    {                                                                       \
        agile_led_dynamic_change_light_mode(led_##x, light_mode, loop_cnt); \
    } while (0U)

// LED
#define LED_G_PREAT  \
    do               \
    {                \
        LED_STOP(r);\
        LED_STOP(g);\
        LED_STOP(y);\
        LED_CTRL(g, "500,2500", -1);\
        LED_START(g);\
        rt_thread_mdelay(1000);\
        LED_CTRL(y, "500,2500", -1);\
        LED_START(y);\
        rt_thread_mdelay(1000);\
        LED_CTRL(r, "500,2500", -1);\
        LED_START(r);\
        rt_thread_mdelay(1000);\
    } while (0U)

#define LED_G_NORMAL \
    do               \
    {                \
        LED_STOP(r); \
        LED_STOP(g); \
        LED_STOP(y); \
        LED_ON(g);   \
    } while (0U)

#define LED_G_NORMAL \
    do               \
    {                \
        LED_STOP(r); \
        LED_STOP(g); \
        LED_STOP(y); \
        LED_ON(g);   \
    } while (0U)

//网络连接断开指示灯
#define LED_G_INTERNET \
    do               \
    {                \
        LED_STOP(r); \
        LED_STOP(g); \
        LED_STOP(y); \
        LED_CTRL(g, "500,1000", -1);\
        LED_START(g);\
    } while (0U)

#define LED_Y_FAULT  \
    do               \
    {                \
        LED_STOP(r); \
        LED_STOP(g); \
        LED_STOP(y); \
        LED_ON(y);   \
    } while (0U)


#define LED_R_ALARM                 \
    do                              \
    {                               \
        LED_STOP(r);                \
        LED_STOP(g);                \
        LED_STOP(y);                \
        LED_CTRL(r, "500,500", -1); \
        LED_START(r);               \
    } while (0U)

#define LED_Y_END_OF_LIFE           \
    do                              \
    {                               \
        LED_STOP(r);                \
        LED_STOP(g);                \
        LED_STOP(y);                \
        LED_CTRL(y, "500,500", -1); \
        LED_START(r);               \
    } while (0U)

int BSP_LED_Init(void);
#endif //!__BSP_LED_H__
