/////////////////////////////////////////////////////////////////////////////
// Lights_down.c
//
/////////////////////////////////////////////////////////////////////////////
//	Set up gauge header
GAUGE_CALLBACK	Light_down_cb;
char Lights_down_gauge_name[]	= GAUGE_NAME;
extern PELEMENT_HEADER	Lights_down_list;
extern MOUSERECT      	Lights_down_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, Lights_down_gauge_name, &Lights_down_list, \
						Lights_down_mouse_rect, Light_down_cb, 0, 0, 0);


/*---------------------------------------------------------------------------
---- Functions that ilustrate status of Keys --------------------------------
---------------------------------------------------------------------------*/
FLOAT64 FSAPI	Lights_down_icon_cb( PELEMENT_ICON pelement )
{
	if ( power_good == FALSE){ // No power connected
		Lights_down = 0; 
		return Lights_down;
	}
	lookup_var (&AIRSPEEDvar);
	if ( AIRSPEEDvar.var_value.n > 230 ){  //Auto closing of lights on 415 km/h		
		Lights_down = 0;
		trigger_key_event( KEY_LANDING_LIGHT_DOWN, 0);
		trigger_key_event( KEY_LANDING_LIGHTS_OFF,0);
	}
	return Lights_down;
}

/*---------------------------------------------------------------------------
------------ Make ICONS macroses     ----------------------------------------
---------------------------------------------------------------------------*/

MAKE_ICON
(		
	Lights_down_icon,
	BMP_Lights_down_off,
	NULL,
	NULL,
	IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,
	0,
	0,0,

	MODULE_VAR_NONE, Lights_down_icon_cb,

	ICON_SWITCH_TYPE_SET_CUR_ICON,
	2,
	0,
	0
)

PELEMENT_HEADER		Lights_down_icon_list[] =
{
	&Lights_down_icon.header,
	NULL
};
/////////////////////////////////////////////////////////////////////////////
MAKE_STATIC
(
	Lights_down_background,
	BMP_Lights_down_off,
	&Lights_down_icon_list,
	NULL,
	IMAGE_USE_TRANSPARENCY,
	0,
	0,0
)

PELEMENT_HEADER		Lights_down_list= &Lights_down_background.header;

/*---------------------------------------------------------------------------
---------------- Call back mouse functions ----------------------------------
---------------------------------------------------------------------------*/

BOOL FSAPI Lights_down_mouse_cb( PPIXPOINT relative_point, FLAGS32 mouse_flags )
{	
	//lookup_var(&);
	if (Lights_down == 0) {
			Lights_down = 1;
			trigger_key_event( KEY_LANDING_LIGHT_UP,0);
	}
	else {
			Lights_down = 0;
			trigger_key_event( KEY_LANDING_LIGHT_DOWN, 0);
			trigger_key_event( KEY_LANDING_LIGHTS_OFF,0);	
	}
	return TRUE;
}
/////////////////////////////////////////////////////////////////////////////

MOUSE_BEGIN( Lights_down_mouse_rect, HELP_NONE, 0, 0 )
	MOUSE_CHILD_FUNCT( 0,0,50,50, CURSOR_HAND, MOUSE_LEFTSINGLE, Lights_down_mouse_cb )
MOUSE_END

/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
//-----------------------   Call back guage   -------------------------------
//---------------------------------------------------------------------------
void FSAPI	Light_down_cb (PGAUGEHDR pgauge, int service_id, UINT32 extra_data)
{
	PPOWER_SUPLY_STATUS_var = (PINT)POWER_SUPLY_STATUS_var.var_ptr;  // If power suply on?
	switch(service_id)
	{
		case    PANEL_SERVICE_PRE_INSTALL:			
		break;

		case    PANEL_SERVICE_PRE_INITIALIZE:
			initialize_var_by_name(&POWER_SUPLY_STATUS_var, "POWER_SUPLY_STATUS");	
		break;

		case    PANEL_SERVICE_PRE_UPDATE:
			// Check if power supported by power suply system
			if ( PPOWER_SUPLY_STATUS_var != NULL && (*PPOWER_SUPLY_STATUS_var == 2 ||
				*PPOWER_SUPLY_STATUS_var == 4 || *PPOWER_SUPLY_STATUS_var == 5 ||
				*PPOWER_SUPLY_STATUS_var == 6 || *PPOWER_SUPLY_STATUS_var == 7) )// defined in PS gauge
				power_good = TRUE;
			else power_good = FALSE;

			// POS updates
			lookup_var(&GENERAL_ENGINE1_ANTI_ICE_POS_var);
			lookup_var(&GENERAL_ENGINE2_ANTI_ICE_POS_var);
			if ( power_good == TRUE && (POS_1_switch == 0 || POS_1_switch == 2) ){ // man or auto
				POS_1_ind = 0;
				if (GENERAL_ENGINE1_ANTI_ICE_POS_var.var_value.n == 0) // if off
					trigger_key_event( KEY_ANTI_ICE_TOGGLE_ENG1, 0);
			}
			else {
				POS_1_ind = -1;
				if (GENERAL_ENGINE1_ANTI_ICE_POS_var.var_value.n == 1) // if on
					trigger_key_event( KEY_ANTI_ICE_TOGGLE_ENG1, 0);
			}

		break;

		case    PANEL_SERVICE_PRE_DRAW:
		break;

		case    PANEL_SERVICE_PRE_KILL:
		break;
	}
}

#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
