#include "GUI_Display\GUI_Display.h"
#include "SEG_DISPLAY\SEG_DISPLAY.h" 
#include "Application.h"
void Gauge_VSpeed_Display(void)
{
    uint16_t VSpeedDisplayValue = 0;
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {
        if ( Get_VechileSpeedValid( ) == 1u )
        {
            VSpeedDisplayValue = Get_DispVechileSpeed( ) / 10u;
            SEG_SET_VSpeed_NUM(1u, VSpeedDisplayValue);
        }
        else
        {
            VSpeedDisplayValue = 0u;
            SEG_SET_VSpeed_NUM(1u, VSpeedDisplayValue);
        }
    }
    else
    {
        VSpeedDisplayValue = 0u;
        SEG_SET_VSpeed_NUM(0u, 0u);
    }
    
}
void Gauge_Clock_Display(void)
{
    uint8_t PageType_DIS = 0;
    if (Common_Get_IG_Sts( ) == COMMON_POWER_ON)
    {
        PageType_DIS = Get_Current_PageType();

       // LED_Driver_Channel_Set(LampChannel_0, LampCh0_06_Screen_Time, 100);
        
        if ( PageType_DIS == 1 )
        {
            if(FLASH_SYNC_1Hz)
            {
                SEG_SET_Clock(Get_Dis_Hour_Time(), Get_Dis_Minute_Time(), 1, 1, 1);
            }
            else
            {
                SEG_SET_Clock(Get_Dis_Hour_Time(), Get_Dis_Minute_Time(), 1, 0, 1);
            }
            
        }
        else if ( PageType_DIS == 2 )
        {
            if(FLASH_SYNC_1Hz)
            {
                SEG_SET_Clock(Get_Dis_Hour_Time(), Get_Dis_Minute_Time(), 1, 1, 1);
            }
            else
            {
                SEG_SET_Clock(Get_Dis_Hour_Time(), Get_Dis_Minute_Time(), 1, 1, 0);
            }
        }
        else 
        {
            SEG_SET_Clock(Get_Dis_Hour_Time(), Get_Dis_Minute_Time(), FLASH_SYNC_1Hz, 1, 1);
        }
    }
    else
    {
        SEG_SET_Clock(0, 0, 0, 0, 0);
        //LED_Driver_Channel_Set(LampChannel_0, LampCh0_06_Screen_Time, 0);
    }
}

void Gauge_Trip_Display(void)
{
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {   
        SEG_SET_TRIP_NUM(1u, Get_Trip_Value());    
    }
    else
    {
        SEG_SET_TRIP_NUM(0u, 0u);
    }
}

void Gauge_ODO_Display(void)
{
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {
        SEG_SET_ODO_NUM(1u, Get_ODO_Value() / 10u);
    }
    else
    {
        SEG_SET_ODO_NUM(0u, 0u);
    }
}
void Gauge_FuelDial_Display(void)
{
    
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {
        SEG_SET_FuelDial(1, Get_CurFuelSetp());
    }
    else
    {
        SEG_SET_FuelDial(0, 0);
    }
}
void Gauge_EspeedDial_Display(void)
{
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {
        SEG_SET_EspeedDial(1,  Get_DispEngineSpeed()/1000, Get_DispEngineSpeed());
    }
    else
    {
        SEG_SET_EspeedDial(0,  0,  0);
    }
}
void Gauge_Frame_Display(void)
{    
    if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
    {
        SEG_SET_Frame(1);
    }
    else
    {
        SEG_SET_Frame(0);
    }
}


void Clear_Bu98(void)
{
    uint8_t i = 0;
    for(i = 0; i < BU98R10_DDRAM_SIZE; i ++)
    {
        BU98R10Chip0DDRAM.Byte[i] = 0;
        BU98R10Chip1DDRAM.Byte[i] = 0;
    }
}


void Gauge_Service(void)
{
    static uint16_t VSpeed_Count = 0u;
    Gauge_Frame_Display(); 
    if (ClearODO_Flag == 1)
    {
        if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
        {
            Check_SEG_Display();         
        }
        else
        {
            Clear_Bu98();
           //RTE_GPIO_Set_Level(VSPEED_TEN_OUT, 0);
           //RTE_GPIO_Set_Level(VSPEED_HUNDREDS_OUT, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_29_MPH, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_30_KM_H, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_07_Key_ISTOP, 0); 
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_02_Normal_Voltage, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_03_High_Low_Voltage, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_04_Fuel_W, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_05_Fuel_Y, 0);
           //LED_Driver_Channel_Set(LampChannel_0, LampCh0_06_Screen_Time, 0);
        }
    }
    else
    {
        if ( Common_Get_IG_Sts( ) == COMMON_POWER_ON )
        {
            if (Common_GetIgnOnTime() >= 3000)
            {
                if (VSpeed_Count < 3)
                {
                    VSpeed_Count++;
                }
                else 
                {
                    VSpeed_Count = 0;
                    Gauge_VSpeed_Display();
                }

                Gauge_ODO_Display();
                Gauge_Clock_Display();
                Gauge_Trip_Display();
                Gauge_FuelDial_Display();
                Gauge_EspeedDial_Display();
            }
            else
            {            
                Checkself_SEG_Display();                
            }
        }
        else
        {
            Clear_Bu98();
            //RTE_GPIO_Set_Level(VSPEED_TEN_OUT, 0);
            //RTE_GPIO_Set_Level(VSPEED_HUNDREDS_OUT, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_29_MPH, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_30_KM_H, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_07_Key_ISTOP, 0); 
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_02_Normal_Voltage, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_03_High_Low_Voltage, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_04_Fuel_W, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_05_Fuel_Y, 0);
            //LED_Driver_Channel_Set(LampChannel_0, LampCh0_06_Screen_Time, 0);
        }
    }    
        
}

