Sign in to follow this  
Guest HC001ST - Stick

C Gauge Question

Recommended Posts

I'm making a simple Oil Pressure/Temp gauge. I have gotten the gauge to compile, but have several things to get right on my first gauge.First, while the PSI pressure can run from 0 - 150 PSI, dispite my non-linearity section (which works in XML) as follows:

#define	GAUGE_MIN_PSI	0#define	GAUGE_MAX_PSI	150NONLINEARITY  eng_oil_pressure_nonlinearity[] ={	{{84,	182},	 0, 0},	{{84,	 72},	150, 0}};FLOAT64 FSAPI eng_oil_psi_needle_cb( PELEMENT_NEEDLE pelement ){	FLOAT64	val = pelement->source_var.var_value.n;	if (val > GAUGE_MAX_PSI)		val = GAUGE_MAX_PSI;	else if (val < GAUGE_MIN_PSI)		val = GAUGE_MIN_PSI;	return val;}

My needle travels only a short portion of it's range. BTW, this is from my header file:

///////////////////////////////////////////////////////////////////////////////// Engine Oil Bitmaps//#define		BMP_ENG_OIL_BACKGROUND				0x1000#define		BMP_ENG_OIL_NEEDLE					0x1010#define		BMP_ENG_OIL_POST					0x1020#define		BMP_ENG_OIL_BEVEL					0x1030

and appears to work fine. Right now, I'm only using the BG and Needle.So, after examining the fs9gauge.h file, I found this:

typedef	enum	GAUGE_TOKEN{ // snip... ENGINE1_OIL_TEMPERATURE, // oil temperature (degC) (16k = 140 deg) ENGINE1_OIL_PRESSURE, 	 // oil pressure (PSI) (16k = 55 PSI) // snip...}

and suspect that this is my problem here. But, I'm not quite sure what the meaning of Arne's notes are here and how to use them.Also, I'm wondering if I really need a call back. Perhaps I do not really need a call back function.And finally, I'm attempting to have a TOOLTIP say, "Engine oil pressure (# PSI)" with the number dynamically added.I have been looking at trying something like this:

MOUSE_BEGIN( eng_oil_mouse_rect, HELP_NONE, 0, 0 )	MOUSE_PARENT_BEGIN( 0,0,120,256, HELPID_GAUGE_OIL_PRESSURE)		MOUSE_TOOLTIP_TEXT_STRING ("Engine Oil Pressure: %3!d! PSI", ENGINE1_OIL_PRESSURE)	MOUSE_PARENT_END	MOUSE_PARENT( 136,0,120,256, HELPID_GAUGE_OIL_TEMPERATURE)MOUSE_END

But, it doesn't work.Thanks for any help.

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Ok,I'm guessing after looking more at the SDK that the ENGINE1_OIL_PRESSURE variable runs from 0-32K (with Arne's note that 55 PSI = 16K).Thus, I've made some progress, and have updated my .zip file to reflect this. But, I'm still not sure what I'm doing. When I put a multiplier into the tooltip equation, I get values in the tooltip, but the needle still is stuck on max until those values are below zero.

Share this post


Link to post
Share on other sites

I think ENGINE1_OIL_PRESSURE will actually run as high as 64K. 55 psi will have a value of 16384. I downloaded your source code, and your needle function is still using the raw value.Try changing this:FLOAT64 val = pelement->source_var.var_value.n;to this:FLOAT64 val = pelement->source_var.var_value.n * 55 / 16384;This should have the effect of changing the scalar value to a psi value.Doug

Share this post


Link to post
Share on other sites

As you already noticed, the ENGINE1_OIL_PRESSURE needs a scaling factor, I don't know it exactly but 55.0/16284.0 looks good. On the other hand all ENGINE1_.... vars are outdated, some of them don't work any more. It is recommandable to switch to the RECIP_ENGINE1_... TURB_ENGINE1_... GENERAL_ENGINE1_... variables (in your case GENERAL_ENGINE1_OIL_PRES?). These are already scaled to a certain unit (PSF?), not some abstract powers of two. All C variables don't use a unit to scale to your needs, you have to do it by hand. In the gauges.h from the Dai's tutorials contain some handy rescaling macros.You used a callback for scaling and limiting? If you don't want to use it, make the NONLINEARITY do the job. E.g. the variable is in PSF and you want ticks in PSI. The scale the rescale the ticks value in PSF instead of PSI:... {{84, 182}, PSI_TO_PSF(0), 0}, {{84, 72}, PSI_TO_PSF(150), 0}...(BTW PSI_TO_PSF is just multiplying by 144.0 or 12.0x12.0)If you don't want to limit in the callback, limit with the NONLINEARITY, by adding two entries with different tick levels, but the same coordinates. FS will interpolate a movememt of 0

Share this post


Link to post
Share on other sites

Thanks alot guys. I think you put me back on track and gave me the info I needed to get to the next level with this.I sure didn't want to have to use cb functions or construct arrays with macros unless I have to, as it means I have to go try to decode MS's macros. C is bad enough without that further obfuscation! :DAnyway, thanks for the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this