
#include "BackLight\BackLight.h"
#include "Components.h"
#include "Application.h"
#include "TrmerM\TrmerM.h"
#include "Line_In\Line_In_user.h"


#define BACK_LIGHT_DAY 600
#define BACK_LIGHT_NIGHT 420
//_Light g_Light;
uint8_t LED_Turnoff = 0;
uint8_t LED_Turnon  = 0;
void BackLight_Init(void)
{
    //g_Light.Light_Day    = 0XFFFF;
    //g_Light.Light_Night  = 0XFFFF;
    LED_Turnoff = 0;
    LED_Turnon  = 0;
}

void BackLight_Process(void)
{
    if (SYS_OPR_STAT_IGN_ON)
    {
        if (Line_In_Get_Status(LINE_IN_Little_Lamp))
        {
            if(LED_Turnon < 5)
            {
                LED_Turnon ++ ;
            }
            else
            {
                LED_Turnon  = 5;
                LED_Turnoff = 0;               
            }
        }
        else
        {
            if(LED_Turnoff < 5)
            {
                LED_Turnoff ++ ;
            }
            else
            {
                LED_Turnoff = 5;
                LED_Turnon  = 0;               
            }
        }
        if ( LED_Turnon == 5 )
        {
            TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_NIGHT);
        }
        else
        {
            TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_DAY);
        }
        
    }
    else
    {
        //g_Light.Light_Day = 0;
        //g_Light.Light_Night = 0;
        TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 0);
    }
}
