//----------------------------------------------------------------------------------------------------
// ID Code  	: Mode.c No.0002
// Update Note  :
//
//----------------------------------------------------------------------------------------------------

#define __MODE_CUSTOMER__

#include "Core\Header\Include.h"

/**
 * CModeHandler
 * main control flow
 * first system initial, then main loop
 * @param <none>
 * @return {none}
 *
*/
//--------------------------------------------------
// Description  : Mode handler, the main control flow
// Input Value  : None
// Output Value : None
//--------------------------------------------------
//--------------------------------------------------
// Description  : No signal event
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CModeNoSignalEvent(void)
{

	//    ucOsdEventMsg = _SHOW_NOSIGNAL_MSG;
	if(!bForcePanelOff)
		{
	CPowerPanelOn(); // avoid power on not active panel power
		}
	COsdMessagePush(_SHOW_NOSIGNAL_MESSAGE);
	SET_DONT_ENABLE_OSD_WHEN_CHANGE_SRC();

//741002***	
#if (_HDMI_SUPPORT == _ON)	
	CLR_HDMISHOWSEARCH();
#endif
//741002###

	SET_SHOW_IS_NOSIGNAL_STATE();
//20080823 ccy modify
	#if (_PCB_TYPE == _PCB_TEST)
	LED_Message(_LED_MSG_RED);
	#endif


}

//--------------------------------------------------
// Description  : No cable event
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CModeNoCableEvent(void)
{

	//    ucOsdEventMsg = _SHOW_NOCABLE_MSG;
	if(!bForcePanelOff)
	CPowerPanelOn(); // avoid power on not active panel power
	COsdMessagePush(_SHOW_NOCABLE_MESSAGE);
	SET_DONT_ENABLE_OSD_WHEN_CHANGE_SRC();

//741002***	
#if (_HDMI_SUPPORT == _ON)	
	CLR_HDMISHOWSEARCH();
#endif
//741002###
	
}

//--------------------------------------------------
// Description  : No support event
// Input Value  : None
// Output Value : None
//--------------------------------------------------
void CModeNoSupportEvent(void)
{
	if(!bForcePanelOff)
	CPowerPanelOn(); // avoid power on not active panel power
	COsdMessagePush(_SHOW_NOSUPPORT_MESSAGE);
	SET_DONT_ENABLE_OSD_WHEN_CHANGE_SRC();

	//    ucOsdEventMsg = _SHOW_NOSUPPORT_MSG;
//741002***	
#if (_HDMI_SUPPORT == _ON)	
	CLR_HDMISHOWSEARCH();
#endif
//741002###
	
}

void CModeResetCustomer(void)
{ 
	#if (_IR_HANDLER_MODE==_HW_MODE)
	 	CIrdaInitial();
	#endif
	
	COsdIconMoveDisableResetEnv();
}

//void CPowerSavingCustomer(void)
//{

//}

void CModeNoSignalIconMoveEvent(void)
{
	COsdMessagePush(_SHOW_ICONMOVE_MESSAGE);
}

void CTimerCancelNosignal_Icon_Powersaving(void)
{
	CTimerCancelTimerEvent(CModeNoSignalEvent);
	CTimerCancelTimerEvent(CModeNoSignalIconMoveEvent);
	CTimerCancelTimerEvent(CModePowerSavingEvent);
}

//type : 0=no icon, 1=icon
void CTimerReactiveNosignal_Icon_Powersaving(BYTE type)
{
	if (type==0)
	{
		CTimerReactiveTimerEvent(SEC(_TIMER_NOSIGNAL), CModeNoSignalEvent);
		CTimerReactiveTimerEvent(SEC(_TIMER_POWERSAVING_BURNIN), CModePowerSavingEvent);
	}
	else
	{
		CTimerReactiveTimerEvent(SEC(_TIMER_NOSIGNAL), CModeNoSignalEvent);
		CTimerReactiveTimerEvent(SEC(_TIMER_ICONMOVE), CModeNoSignalIconMoveEvent);
#if(_CUSTOMER_CGT)
		if (GET_INPUTPORT_TYPE(stSystemData.InputSource)==_DSUB_A0_PORT)
		{
			CTimerReactiveTimerEvent(SEC(10), CModePowerSavingEvent);
		}
		else
		{
			CTimerReactiveTimerEvent(SEC(_TIMER_POWERSAVING), CModePowerSavingEvent);
		}			
//20080912 ccy add
#elif( _PCB_TYPE == _PCB_TEST)
#else
		CTimerReactiveTimerEvent(SEC(_TIMER_POWERSAVING), CModePowerSavingEvent);

#endif
	}
}

// type: 0-source, 1-NoSignal
void COsdShowNoSignalOrSrc(UINT8 type)
{
	if (type==0)
	{
		//COsdMessagePush(_SHOW_SIGNALSOURCE_MESSAGE);
		;//COsdMessagePush(_SHOWINFO_MESSAGE);
	}
	if(GET_INPUTPORT_TYPE(stSystemData.InputSource)!=_YPBPR_A0_PORT)	//add 20091210
	if (GET_BURNSTATUS())
		CTimerReactiveNosignal_Icon_Powersaving(0);
	else
	{
			if(GET_INPUTPORT_TYPE(stSystemData.InputSource)==_VIDEO_TV_PORT)
			{
			//czl disable 080708 for close blue background
			
				if(GET_TV_BACKGROUND())
					CTimerReactiveNosignal_Icon_Powersaving(1);
			
			}
			else
				CTimerReactiveNosignal_Icon_Powersaving(1);
		}		

//20080829 ccy modify
		if ((GET_INPUTPORT_TYPE(stSystemData.InputSource) == _VIDEO_TV_PORT))
		{      //   CLR_DVD_POWERONOFF();
			if (GET_TV_BACKGROUND() ==0)//20081020 ccy modify
			{
				CScalerPageSelect(_PAGE8);
				CScalerSetBit(_P8_OUTPUT_CTRL_A7, 0x4f, 0xB0);		//Enable snow noise. zhang_dc 2008.01.28
				CVideoDisplaySet();
				CScalerSetBit(_VDISP_CTRL_28, ~(_BIT7 | _BIT5 | _BIT3 | _BIT1 | _BIT0), (_BIT7 | _BIT3 |_BIT1 | _BIT0));
			//if(Panel[0].PanelConfig&_BIT3 == 0)
			//	CScalerSetBit(_VDISP_CTRL_28, ~( _BIT3), (0));
			//else
			//	CScalerSetBit(_VDISP_CTRL_28, ~( _BIT3), (_BIT3));
				CAdjustBackgroundColor(0,0,0x00);
				}
			else
			{
				CScalerPageSelect(_PAGE8);
				CScalerSetBit(_P8_OUTPUT_CTRL_A7, 0x4f, 0x20);		//Disable snow noise. zhang_dc 2008.01.28
				CModeSetFreeRun();
				CScalerSetBit(_VDISP_CTRL_28, ~(_BIT7 | _BIT5 | _BIT3 | _BIT1 | _BIT0), (_BIT5 | _BIT1 | _BIT0));
				CAdjustBackgroundColor(0x00, 0x00, 0xff);	
			}
		}
		else 
		{
		//if(GET_INPUTPORT_TYPE(stSystemData.InputSource)!=_YPBPR_A0_PORT)
		//	 CLR_DVD_POWERONOFF();    //add by dengyi on  2010-01-11
			CModeSetFreeRun();
			if(GET_TV_BACKGROUND())
				{
				if(GET_INPUTPORT_TYPE(stSystemData.InputSource)==_YPBPR_A0_PORT)
					CAdjustBackgroundColor(0x00, 0x00, 0x00);	
				
					else
				CAdjustBackgroundColor(0x00, 0x00, 0xff);	
				}
			else
				CAdjustBackgroundColor(0x00, 0x00, 0x00);
			CScalerSetBit(_VDISP_CTRL_28, ~(_BIT7 | _BIT5 | _BIT3 | _BIT1 | _BIT0), (_BIT5 | _BIT1 | _BIT0));
		}

}


