#include "led_app.h"

#include "can_app.h"
#include "Com_Cfg.h"
#include "pwm_manage.h"
#include "Com.h"
#include "system_voltage_manage.h"
#include "system_voltage_manage_cfg.h"
#include "CanNm.h"
#include "common_memory.h"
#include "Com_Cfg.h"
#define LED_APP_TASK_PERIOD_TIME    5u
#define OTA_EXIT_DELAY_3S   (3000u / LED_APP_TASK_PERIOD_TIME)



#define BACKGROUND_LIGHT_MOD_4G_49A_LOST_COMMUNICATION_3MIN    (1000u * 60u * 3u / LED_APP_TASK_PERIOD_TIME)
#define BACKGROUND_LIGHT_METER_1_DIR_4BF_LOST_COMMUNICATION_2S  (2000u / LED_APP_TASK_PERIOD_TIME)

#define BACKGROUND_LIGHT_LEVEL_INVALID  0u
#define BACKGROUND_LIGHT_LEVEL_1        1u
#define BACKGROUND_LIGHT_LEVEL_2        2u
#define BACKGROUND_LIGHT_LEVEL_3        3u
#define BACKGROUND_LIGHT_LEVEL_4        4u
#define BACKGROUND_LIGHT_LEVEL_5        5u
#define BACKGROUND_LIGHT_LEVEL_6        6u
#define BACKGROUND_LIGHT_LEVEL_7        7u
#define BACKGROUND_LIGHT_LEVEL_8        8u
#define BACKGROUND_LIGHT_LEVEL_9        9u
#define BACKGROUND_LIGHT_LEVEL_10       10u
#define BACKGROUND_LIGHT_LEVEL_11       11u

#define BACKGROUND_LIGHT_LEVEL_RESERVED 23u

#define BACKGROUND_LIGHT_LEVEL_MAX      11u
#define NUM_OF_BACKGROUND_LIGHT_LEVEL   12u   


#define PICK_LIGHT_FAST_FLASH_PERIOD (380u / LED_APP_TASK_PERIOD_TIME)
#define PICK_LIGHT_FAST_FLASH_DUTY   (200u / LED_APP_TASK_PERIOD_TIME)

#define PICK_LIGHT_SLOW_FLASH_PERIOD (750u / LED_APP_TASK_PERIOD_TIME)
#define PICK_LIGHT_SLOW_FLASH_DUTY   (400u / LED_APP_TASK_PERIOD_TIME)



#define PICK_FUN_INACTIVE       0u
#define PICK_FUN_ACTIVE         1u
#define PICK_FUN_SECOND_ALARM   2u
#define PICK_FUN_THREE_ALARM    3u

const uint8_t background_light_level_tab[NUM_OF_BACKGROUND_LIGHT_LEVEL] = 
{
   0, 10, 16, 22, 28, 34, 40, 70, 80, 85, 90, 100
}; 

#define BACKGROUND_LIGHT_STEP_TIME_35MS (30u / LED_APP_TASK_PERIOD_TIME)

typedef struct
{
    uint8_t  cur_level;
    uint8_t  duty;
    uint16_t invalid_timer;
    uint8_t  ota_mod;
    uint16_t ota_exit_delay;
    uint32_t mod_4g_49a_lost_communication_timer;
    uint8_t  step_timer;
    uint16_t meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer;
}app_background_light_type;

app_background_light_type app_background_light;




#define APP_PICK_LIGHT_STATE_IDLE           0u
#define APP_PICK_LIGHT_STATE_ON             1u
#define APP_PICK_LIGHT_STATE_SLOW_FLASH     2u
#define APP_PICK_LIGHT_STATE_FAST_FLASH     3u

#define APP_PICK_LIGHT_DAY_MOD     0u
#define APP_PICK_LIGHT_NIGHT_MOD   1u


typedef struct 
{
    uint8_t timer;
    uint8_t state;
    uint8_t output;
    uint8_t day_night_mod;
}app_pick_light_type;

app_pick_light_type app_pick_light;


void led_app_init(void)
{
    common_memory_clear((uint8_t *)&app_background_light, sizeof(app_background_light));
    common_memory_clear((uint8_t *)&app_pick_light, sizeof(app_pick_light));
    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
    pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);
    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);
    pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);
}

uint8_t is_led_app_allow_sleep(void)
{
    uint8_t ret = FALSE;
    if((app_background_light.duty == (uint16_t)0))
    {
        ret = TRUE;
    }

    return (ret);
}

uint8_t pick_light_state_get(void)
{
    uint8_t acc_mode_display1_29c_s;
    uint8_t dnp_status_s;
    uint8_t dnp_take_over_req_s;
    uint8_t pick_light_state;


    can_app_receive_signal(COM_RXSIGADS_ACC_MODE_DISPLAYL, &acc_mode_display1_29c_s);
    can_app_receive_signal(COM_RXSIGADS_DNP_STATS, &dnp_status_s);
    can_app_receive_signal(COM_RXSIGADS_DNP_TAKE_OVER_REQ_S, &dnp_take_over_req_s);


    pick_light_state = PICK_FUN_INACTIVE;
        /* ACC 功能未激活 */
    if( ( (acc_mode_display1_29c_s != ADS_ACC_MODE_DISPLAYL_ACTIVE_CONTROL_MODE) \
    && (acc_mode_display1_29c_s != ADS_ACC_MODE_DISPLAYL_BRAKE_ONLY_MODE) \
    && (acc_mode_display1_29c_s != ADS_ACC_MODE_DISPLAYL_OVENIDE) \
    && (acc_mode_display1_29c_s != ADS_ACC_MODE_DISPLAYL_STAND_STILL_ACTIVE_MODE)\
    && (acc_mode_display1_29c_s != ADS_ACC_MODE_DISPLAYL_STAND_STILL_WAIT_MODE) ) \
    /* LCC功能不可用*/
    && ((dnp_status_s == ADS_DNP_STATS_OFF) || (dnp_status_s == ADS_DNP_STATS_PASSIVE)) \
    /* NOA 功能不可用 */
      ||((dnp_status_s == ADS_DNP_STATS_FAULT) || (dnp_status_s == ADS_DNP_STATS_FORBIDDEN))) 
    {
        pick_light_state = PICK_FUN_INACTIVE;
    }
             /* ACC 功能激活 */
    if ( (((acc_mode_display1_29c_s == ADS_ACC_MODE_DISPLAYL_ACTIVE_CONTROL_MODE) \
    || (acc_mode_display1_29c_s == ADS_ACC_MODE_DISPLAYL_BRAKE_ONLY_MODE) \
    || (acc_mode_display1_29c_s == ADS_ACC_MODE_DISPLAYL_OVENIDE) \
    || (acc_mode_display1_29c_s == ADS_ACC_MODE_DISPLAYL_STAND_STILL_ACTIVE_MODE)\
    || (acc_mode_display1_29c_s == ADS_ACC_MODE_DISPLAYL_STAND_STILL_WAIT_MODE)) \
          /*LCC 功能激活*/
    || ((dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE2) || (dnp_status_s == ADS_DNP_STATS_ILCA_ACTIVE) || (dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE1)) \
         /* NOA 功能激活 */
    || ((dnp_status_s == ADS_DNP_STATS_DNP_ACTIVE))) && ((dnp_take_over_req_s == ADS_DNP_TAKE_OVER_REQ_S_INACTIVE))
    )
    {
        pick_light_state = PICK_FUN_ACTIVE;
    }

            /*LCC 功能激活*/
    if( (((dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE2) || (dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE1)) \
           /* NOA 功能激活 */
    || ((dnp_status_s == ADS_DNP_STATS_DNP_ACTIVE))) 
        /* 触发一级接管请求 */
    && ((dnp_take_over_req_s == ADS_DNP_TAKE_OVER_REQ_S_WARNING_LEVEL1)))
    {
        pick_light_state = PICK_FUN_ACTIVE;
    }

            /*LCC 功能激活*/
    if( (((dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE2) || (dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE1)) \
           /* NOA 功能激活 */
    || ((dnp_status_s == ADS_DNP_STATS_DNP_ACTIVE))) 
        /* 触发二级接管请求 */
    && ((dnp_take_over_req_s == ADS_DNP_TAKE_OVER_REQ_S_WARNING_LEVEL2)))
    {
        pick_light_state = PICK_FUN_SECOND_ALARM;
    }
       /* LCC 功能退出 */
    if( (((dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE2) || (dnp_status_s == ADS_DNP_STATS_LCC_ACTIVE1)) \
           /* NOA 功能激活 */
    || ((dnp_status_s == ADS_DNP_STATS_DNP_ACTIVE))) 
        /* 触发三级接管请求 */
    && ((dnp_take_over_req_s == ADS_DNP_TAKE_OVER_REQ_S_WARNING_LEVEL3)))
    {
        pick_light_state = PICK_FUN_THREE_ALARM;
    }

       /* LCC 等于MRC（最小风险策略） */
    if((dnp_status_s == ADS_DNP_STATS_MRC) && (dnp_take_over_req_s == ADS_DNP_TAKE_OVER_REQ_S_SAFE_STOP))
    {
        pick_light_state = PICK_FUN_THREE_ALARM;
    }

    if(COM_RXIPDUADS_29C_TIMEOUTFLAG)
    {
        pick_light_state = PICK_FUN_INACTIVE;
    }
    return (pick_light_state);

}

uint8_t pick_light_state_process(void)
{
    uint8_t pick_light_state;
    uint8_t pick_light_task_state;

    pick_light_state = pick_light_state_get();
    if(pick_light_state == PICK_FUN_ACTIVE)
    {
        pick_light_task_state = APP_PICK_LIGHT_STATE_ON;
    }
    else if(pick_light_state == PICK_FUN_SECOND_ALARM)
    {
        pick_light_task_state = APP_PICK_LIGHT_STATE_SLOW_FLASH;
    }
    else if(pick_light_state == PICK_FUN_THREE_ALARM)
    {
        pick_light_task_state = APP_PICK_LIGHT_STATE_FAST_FLASH;
    }
    else
    {
        pick_light_task_state = APP_PICK_LIGHT_STATE_IDLE;
    }


    return pick_light_task_state;
}

void pick_light_task(void)
{
    uint8_t background_light_level;
    Nm_StateType can_nm_state;
    Nm_ModeType  can_nm_mode;

    can_app_receive_signal(COM_RXSIGMETER1_BACKGROUNDLIGHTLVLCMD, &background_light_level);
    CanNm_GetState(0 ,(Nm_StateType * )(&can_nm_state),(Nm_ModeType * )(&can_nm_mode));
    

    if(background_light_level >= BACKGROUND_LIGHT_LEVEL_1 && background_light_level <= BACKGROUND_LIGHT_LEVEL_11)
    {
        app_pick_light.day_night_mod = APP_PICK_LIGHT_NIGHT_MOD;
    }
    else if(background_light_level > BACKGROUND_LIGHT_LEVEL_11 && background_light_level < BACKGROUND_LIGHT_LEVEL_RESERVED)
    {
        app_pick_light.day_night_mod = APP_PICK_LIGHT_DAY_MOD;
    }
    else
    {
        app_pick_light.day_night_mod = APP_PICK_LIGHT_DAY_MOD;
    }

    app_pick_light.state = APP_PICK_LIGHT_STATE_IDLE;

    #if 0
    switch(app_pick_light.state)
    {
        case APP_PICK_LIGHT_STATE_IDLE:
            pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
            pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);
            pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);
            pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);
            app_pick_light.state = pick_light_state_process();
            if(app_pick_light.state != APP_PICK_LIGHT_STATE_IDLE)
            {
                app_pick_light.timer = 0u;
                app_pick_light.output = 1u;
            }
            break;
        case APP_PICK_LIGHT_STATE_ON:
            if(app_pick_light.day_night_mod == APP_PICK_LIGHT_DAY_MOD)
            {
                pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 1000);
                pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 1000);
            }
            else
            {
                pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
                pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);               
            }           
            pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 1000);           
            pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 1000);
            app_pick_light.state = pick_light_state_process();
            app_pick_light.timer = 0u;
            app_pick_light.output = 1u;
            break;
        case APP_PICK_LIGHT_STATE_FAST_FLASH:
            app_pick_light.timer ++;
            if(app_pick_light.output)
            {
                if(app_pick_light.day_night_mod == APP_PICK_LIGHT_DAY_MOD)
                {
                    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 1000);
                    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 1000);
                }
                else
                {
                    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
                    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);               
                }           
                pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 1000);           
                pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 1000);  
                if(app_pick_light.timer >= PICK_LIGHT_FAST_FLASH_DUTY)          
                {
                    app_pick_light.output = 0;
                }    
            }
            else
            {
                pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
                pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);    
                pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);           
                pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);  
                if(app_pick_light.timer >= PICK_LIGHT_FAST_FLASH_PERIOD)   
                {
                    app_pick_light.timer = 0;
                    app_pick_light.output = 1;
                    app_pick_light.state = pick_light_state_process();
                }          
            }
            break;
        case APP_PICK_LIGHT_STATE_SLOW_FLASH:
            app_pick_light.timer ++;
            if(app_pick_light.output)
            {
                if(app_pick_light.day_night_mod == APP_PICK_LIGHT_DAY_MOD)
                {
                    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 1000);
                    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 1000);
                }
                else
                {
                    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
                    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);               
                }           
                pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 1000);           
                pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 1000);  
                if(app_pick_light.timer >= PICK_LIGHT_SLOW_FLASH_DUTY)          
                {
                    app_pick_light.output = 0;
                }    
            }
            else
            {
                pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
                pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);    
                pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);           
                pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);  
                if(app_pick_light.timer >= PICK_LIGHT_SLOW_FLASH_PERIOD)   
                {
                    app_pick_light.timer = 0;
                    app_pick_light.output = 1;
                    app_pick_light.state = pick_light_state_process();
                }          
            }
  
        break;
        default:
        while(1);
    }
    #endif
}

void background_light_task(void)
{
    uint8_t enter_ota_mode_req;

    uint8_t power_gear;
    uint8_t background_light_level;
    uint8_t pick_light_state;

    Nm_StateType can_nm_state;
    Nm_ModeType  can_nm_mode;

    can_app_receive_signal(COM_RXSIGMETER1_BACKGROUNDLIGHTLVLCMD, &background_light_level);
    can_app_receive_signal(COM_RXSIGBCM1_POWER_GEAR, &power_gear);
    can_app_receive_signal(COM_RXSIGMOD_4G_ENTER_OTA_MODE_REQ, &enter_ota_mode_req);
   
    CanNm_GetState(0 ,(Nm_StateType * )(&can_nm_state),(Nm_ModeType * )(&can_nm_mode));
    


    if(power_gear == POWER_GEAR_OFF)
    {
        if((COM_RXIPDUMETER_1_DIR_4BF_TIMEOUTFLAG == 1u) || (background_light_level == BACKGROUND_LIGHT_LEVEL_INVALID) \
        || (background_light_level >= BACKGROUND_LIGHT_LEVEL_RESERVED))
        {
            if(app_background_light.meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer < 0xffffu)
            {
                app_background_light.meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer ++;
            }
            if(app_background_light.meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer >= BACKGROUND_LIGHT_METER_1_DIR_4BF_LOST_COMMUNICATION_2S)
            {
                app_background_light.cur_level = 0u;
            }

        }
        else
        {
            if(background_light_level > BACKGROUND_LIGHT_LEVEL_11)
            {
                background_light_level = 0u;
            }
            app_background_light.cur_level = background_light_level;
            app_background_light.meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer = 0u;
        }
    }
    else
    {
        if((background_light_level != BACKGROUND_LIGHT_LEVEL_INVALID) && (background_light_level < BACKGROUND_LIGHT_LEVEL_RESERVED))
        {
            if(background_light_level > BACKGROUND_LIGHT_LEVEL_11)
            {
                background_light_level = 0u;
            }
            app_background_light.cur_level = background_light_level;
        }
        app_background_light.meter_1_dir_4bf_lost_comm_or_lvl_sig_invalid_timer = 0u;
    }

    if(COM_RXIPDUMOD_4G_49A_TIMEOUTFLAG)
    {
        if(app_background_light.mod_4g_49a_lost_communication_timer < 0xffffffffu)
        {
            app_background_light.mod_4g_49a_lost_communication_timer ++;
        }
    }
    else
    {
        app_background_light.mod_4g_49a_lost_communication_timer = 0u;
    }

    if(app_background_light.ota_mod)
    {
        app_background_light.cur_level = 0u;

        if(app_background_light.mod_4g_49a_lost_communication_timer >= BACKGROUND_LIGHT_MOD_4G_49A_LOST_COMMUNICATION_3MIN)
        {
            app_background_light.mod_4g_49a_lost_communication_timer = 0u;
            app_background_light.ota_mod = 0u;
        }
        if(COM_RXIPDUMOD_4G_49A_TIMEOUTFLAG == 0u)
        {
            if(enter_ota_mode_req == 0u)
            {
                app_background_light.ota_exit_delay ++;
                if(app_background_light.ota_exit_delay >= OTA_EXIT_DELAY_3S)
                {
                    app_background_light.ota_exit_delay = 0u;
                    app_background_light.ota_mod = 0u;
                }
            }
            else
            {
                app_background_light.ota_exit_delay = 0u;
                app_background_light.ota_mod = 1u;
            }
        }

    }
    else
    {
        if(COM_RXIPDUMOD_4G_49A_TIMEOUTFLAG == 0u)
        {
            if(enter_ota_mode_req == 1u)
            {
                app_background_light.ota_mod = 1u;
            }
        }
    }
    if((can_nm_state == NM_STATE_BUS_SLEEP))
    {
        app_background_light.cur_level = 0;
    }
    app_background_light.step_timer ++;
    if(app_background_light.step_timer >= BACKGROUND_LIGHT_STEP_TIME_35MS)
    {
        app_background_light.step_timer = 0u;
        if(app_background_light.duty > background_light_level_tab[app_background_light.cur_level])
        {
            app_background_light.duty --;
        }
        else if(app_background_light.duty < background_light_level_tab[app_background_light.cur_level])
        {
            app_background_light.duty ++;
        }
        else
        {

        }
    
        pwm_set_duty(BACKGROUND_LIGHT_PWM_ID, BACKGROUND_LIGHT_PWM_CH, (uint16_t)(app_background_light.duty * 10u));
       
            pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, L_PICK_BACKGROUND_LIGHT_PWM_CH, (uint16_t)(app_background_light.duty * 10u));
            pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, R_PICK_BACKGROUND_LIGHT_PWM_CH, (uint16_t)(app_background_light.duty * 10u));
       

    }
}


void Led_EnterSleepMode(void)
{
    pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, L_PICK_BACKGROUND_LIGHT_PWM_CH, 0);
    pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, R_PICK_BACKGROUND_LIGHT_PWM_CH, 0);    
    pwm_set_duty(BACKGROUND_LIGHT_PWM_ID, BACKGROUND_LIGHT_PWM_CH, 0);
    pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
    pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);
    pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);
    pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);

    app_background_light.cur_level = 0;
    app_background_light.duty = 0;
    app_pick_light.state = APP_PICK_LIGHT_STATE_IDLE;
}

void led_app_task(void)
{
    uint8_t system_voltage_mode;

    system_voltage_mode = system_voltage_manage_mode_get(FUNC_SYSTEM_VOLTAGE_MANAGE_ID);

    if(system_voltage_mode == SYSTEM_VOLTAGE_MODE_NORMAL)
    {
        background_light_task();
        //pick_light_task();
    }
    else
    {
        pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, L_PICK_BACKGROUND_LIGHT_PWM_CH, 0);
        pwm_set_duty(PICK_BACKGROUND_LIGHT_PWM_ID, R_PICK_BACKGROUND_LIGHT_PWM_CH, 0);    
        pwm_set_duty(BACKGROUND_LIGHT_PWM_ID, BACKGROUND_LIGHT_PWM_CH, 0);
        pwm_set_duty(L_PICK_HIGH_LIGHT_PWM_ID, L_PICK_HIGH_LIGHT_PWM_CH, 0);
        pwm_set_duty(L_PICK_LOW_LIGHT_PWM_ID, L_PICK_LOW_LIGHT_PWM_CH, 0);
        pwm_set_duty(R_PICK_HIGH_LIGHT_PWM_ID, R_PICK_HIGH_LIGHT_PWM_CH, 0);
        pwm_set_duty(R_PICK_LOW_LIGHT_PWM_ID, R_PICK_LOW_LIGHT_PWM_CH, 0);

        app_background_light.cur_level = 0;
        app_background_light.duty = 0;
        app_pick_light.state = APP_PICK_LIGHT_STATE_IDLE;        
    }

}