Sign in to follow this  
badderjet

Arne, this one's for you

Recommended Posts

No, it is not a Bud, sorry ;-).Anyone else that might now, I'd be happy to read your thoughts.Trying to display the tansponder code in a string. Here is the make string code:

MAKE_STRING(	xpdr_code,	NULL,	xpdr_fail,	IMAGE_USE_ERASE | IMAGE_USE_BRIGHT,	0,	68, 25,	90, 18,	4,	MODULE_VAR_NONE,	MODULE_VAR_NONE,	MODULE_VAR_NONE,	RGB (245,255,77),	RGB (0,0,0),	RGB (245,255,77),	GAUGE_FONT_ARIAL,	GAUGE_WEIGHT_DEFAULT,	GAUGE_CHARSET,	0,	DT_CENTER | DT_VCENTER | DT_SINGLELINE,	NULL,	xpdr_code_cb)

And here is the xpdr_code_cb

FLOAT64 FSAPI	xpdr_code_cb (PELEMENT_STRING pelement){	FLOAT64 val=pelement->source_var[0].var_value.n;	val = !val;		wsprintf(pelement->string, "%4d", xpdr_value_var);		return val;}

Finally the gauge update

void FSAPI	xpdr_update (PGAUGEHDR pgauge, int service_id, UINT32 extra_data){	switch(service_id)	{/* "update_routine()" */		case	PANEL_SERVICE_PRE_UPDATE:						lookup_var(&alt_value);			alt_value_var = alt_value.var_value.n;			lookup_var(&xpdr_value);			xpdr_value_var = xpdr_value.var_value.n;		break;	}}

Where xpdr_value is defined in the main (master) .c file as

MODULE_VAR xpdr_value = {TRANSPONDER_CODE};UINT32 xpdr_value_var = 0;

As you can see from the gauge update routine I am also displaying the altitude in this gauge, in a string setup just like the one above, but with a callback that prints the altitude from ALT_FROM_BAROMETRIC_PRESSURE. Everything is setup exactly the same as this one, and that altitude works. But the XPDR code only shows a static 0. If I am not mistaken, FS starts with the xpdr code set to 1200, right?Am I missing a variable type declaration before xpdr_value_var in the macro callback? I've tried INT to no avail.On a related topic, according to sd2gau131 it is possible to make the black squares that surround string fields transparent, but I haven't succeeded to do so. I want only the numbers to shw up, and Dai's documentation states BIT15 should take care of this. Well, BIT15 is defined as IMAGE_USE_LUMINOUS_PARTIAL in gauges.h, so I tried that, but nothing, still have black squares covering the defined string field.Thanks for the help.

Share this post


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

That won't work so easy.The transponder is no decimal. It's Binary Coded Decimal BCD. You gotta shift some bits. Arne will certainly know the correct syntax. He told me once some working routines but I don't recall from memory.Something like the following, but it's for a NAV, but should be similar to the XPNDR code:

wsprintf(xpdr.string, "%d%d%d%d", (x >> 12) & 0x000f, (x >> 8) & 0x000f, (x >> 4) & 0x000f, x & 0x000f);

Try it and let us know if or how it works. :-)Etienne :-wave

Share this post


Link to post
Share on other sites

There are very few variables where you shouldn't use ...var_value.n but e.g. ...var_value.d. This generally the case for all ..._FREQUENCY and ..._CODE variables.So xpdr_value_var = xpdr_value.var_value.d; in the gauge callback is sufficient. For an easy BCD -> decimal conversion use "%04x" as format string. You should also "return xpdr_value_var;" in the string callback. A seperate gauge callback isn't necessary, if you use this:FLOAT64 FSAPI xpdr_code_cb (PELEMENT_STRING pelement){ wsprintf(pelement->string, "%04x", pelement->source_var&l;0&r;.var_value.d); return pelement->source_var&l;0&r;.var_value.d;}MAKE_STRING( xpdr_code, NULL, xpdr_fail, IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY, 0, 68, 25, 90, 18, 4, TRANSPONDER_CODE, MODULE_VAR_NONE, MODULE_VAR_NONE, RGB (245,255,77), RGB (0,0,0), RGB (245,255,77), GAUGE_FONT_ARIAL, GAUGE_WEIGHT_DEFAULT, GAUGE_CHARSET, 0, DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL, xpdr_code_cb)There were some tricks with BIT15 aka IMAGE_USE_LUMINOUS... for FS98 style string gauges in FS200x. For "true" FS2000 style gauges (multigauge structure) you can use the "normal" transparency bit (IMAGE_USE_TRANSPARENCY) for that purpose.Arne Bartels

Share this post


Link to post
Share on other sites

Oops yes it seems it's even easier than with bit shifing. I think that was just 'cause of the format 1xx.xx for the NAV radio while the transponder actually shows the whole number directly like xxxx. ;-)Etienne :-wave

Share this post


Link to post
Share on other sites

If you "only" want to display a BCD number the most simple way is to use a formatting to hexadecimal numbers:e.g. TRANSPONDER:sprintf(..."%04x",..var_value.d);COM/NAVsprintf(..."1%02x.%02x",..var_value.d/0x100,..var_value.d%0x100);No bitshift, no conversion needed.Arne Bartels

Share this post


Link to post
Share on other sites

Ahem, I don't use them at all, mainly because (until very recently) I wasn't able to figure out how they work. You need them or another decimal -> bcd conversion, if you wan't to convert a decimal frequency e.g. 123.45 MHz to BCD frequency for using in a ...FREQUENCY_SET key event. The trick with the hexadecimal formatting doesn't work this way round, you can only transfer from BCD to decimal. For an alternative BCD to decimal or decimal to dec have a look in Dais tutorial page 98:#include #define Bcd2Dec(BcdNum) HornerScheme(BcdNum,0x10,10)#define Dec2Bcd(DecNum) HornerScheme(DecNum,10,0x10)UINT32 HornerScheme(UINT32 Num,UINT32 Divider,UINT32 Factor){ UINT32 Remainder=0,Quotient=0,Result=0; Remainder=Num%Divider; Quotient=Num/Divider; if(!(Quotient==0&&Remainder==0)) Result+=HornerScheme(Quotient,Divider,Factor)*Factor+Remainder; return Result;}Arne Bartels

Share this post


Link to post
Share on other sites

Thanks a lot Arne.Works perfect now. I am adding now the sequential info to be able to tune the xpdr to a different frequency.I am also going to MSDN now to figure out how to display the numbers closer to each other, maybe changing the font settings.Oh, and by the way, for fans out there, don't forget, Brasil's Formula 1 qualifying starts at 1700 UTC today. Should be an awesome show.

Share this post


Link to post
Share on other sites

Sometimes I think it's a bad idea that I don't have a TV. Anyway, all my hopes to Mc Laren.Arne Bartels

Share this post


Link to post
Share on other sites

Hey Arne.Oh yeah, all my cheers go for Kimi. The boy, although being called Iceman (he's even got that on his helmet now :-)), is on fire, and I am pretty sure he will be one of the top runners this weekend. I actually like the new qualifying rules. Sucks that they are not as light as possible on fuel, so they don't go as fast, but it definitely increases the emotion for the viewers.

Share this post


Link to post
Share on other sites

>Ahem, I don't use them at all, mainly because (until very >recently) I wasn't able to figure out how they work. LOL :-lolAnyway, thanks for the info. Should be useful to me soon.Etienne :-wave

Share this post


Link to post
Share on other sites

>I am also going to MSDN now to figure out how to display the >numbers closer to each other, maybe changing the font >settings. If you have any success, lemme know, I also need this at the moment. The font size seems somehow dependent on the NUM_CHARS in the MAKE_STRING macro.Etienne :-wave

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