//
// VSU_RPM.c
//
char	 VSU_RPM_gauge_name[]		= GAUGE_NAME;
extern	 PELEMENT_HEADER			VSU_RPM_list;
extern	 MOUSERECT					VSU_RPM_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, VSU_RPM_gauge_name, &VSU_RPM_list, \
						VSU_RPM_mouse_rect, 0, 0, 0, 0);

int fueltankchange[5]={0,100,100,100,100}, fueltankcounter = 0, currenttank = 0;

/////////////////////////////////////////////////////////////////////////////
FAILURE_RECORD	VSU_RPM_fail[] =
{
	{FAIL_SYSTEM_ELECTRICAL_PANELS, FAIL_ACTION_NO_DRAW},
	{FAIL_NONE, FAIL_ACTION_NONE}
};

/////////////////////////////////////////////////////////////////////////////
FLOAT64 FSAPI	VSU_RPM_string_cb( PELEMENT_STRING pelement )
{
	lookup_var(&TICK18_var);
	if (rmp_time == -1) rmp_time = TICK18_var.var_value.n;

	if (start_vsu == 1 ){
		if ( rmp_time + 2 < TICK18_var.var_value.n ) { // 15 secs for full stop/start
			RPM += 0.9 ;
			if (RPM > 97 ) {
					RPM = 97.1;
			}
			rmp_time = TICK18_var.var_value.n;
		}
	}
	else if (start_vsu == 0 ) {
		if ( rmp_time + 2 < TICK18_var.var_value.n ) {  // 15 secs for full stop/start
			RPM -= 0.9 ;
			rmp_time = TICK18_var.var_value.n;
			if (RPM < 0) {
				RPM = 0;
			}
		}
	}
	sprintf(pelement->string ,"%05.1f",RPM);

	return RPM;
}

MAKE_STRING
(
	VSU_RPM_string,
	NULL,
	VSU_RPM_fail,
	IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,
	0,
	6, 1,
	88, 55,
	5,

	MODULE_VAR_NONE,
	MODULE_VAR_NONE,
	MODULE_VAR_NONE,
	RGB(139,149,90),
	RGB(0,0,0),
	RGB(92,92,92),
	GAUGE_FONT_DEFAULT,
	GAUGE_WEIGHT_DEFAULT,
	GAUGE_CHARSET,
	0,
	DT_CENTER | DT_VCENTER | DT_SINGLELINE,
	NULL,
	VSU_RPM_string_cb
)

PELEMENT_HEADER		VSU_RPM_icon_list[] =
{
	&VSU_RPM_string.header,
	NULL
};


/////////////////////////////////////////////////////////////////////////////
MAKE_STATIC
(
	VSU_RPM_background,
	BMP_STRING_BG,
	&VSU_RPM_icon_list,
	NULL,
	IMAGE_USE_TRANSPARENCY,
	0,
	0,0
)

PELEMENT_HEADER		VSU_RPM_list	= &VSU_RPM_background.header;


MOUSE_BEGIN( VSU_RPM_mouse_rect, HELP_NONE, 0, 0 )
MOUSE_END


/////////////////////////////////////////////////////////////////////////////
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
#undef GAUGE_CHARSET
#undef GAUGE_FONT_DEFAULT
#undef GAUGE_WEIGHT_DEFAULT


