Sign in to follow this  
N2056

How are macros used in xml?

Recommended Posts

In the post concerning modulus in this forum I found a perfect macro for the rolling numbers I want to have that will show elapsed run time on my Tachometer. Can someone explain how to use macros?Thanks!Robert

Share this post


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

Probably the best place to learn about macros is to tear appart the default GPS and look at the way it does things. I have pulled a variety of usefull functions from it.CheersShad

Share this post


Link to post
Share on other sites

>In the post concerning modulus in this forum I found a>perfect macro for the rolling numbers I want to have that will>show elapsed run time on my Tachometer. Can someone explain>how to use macros?There is a really neat function for the forums called "Search..." Use the "Advanced Search," type in a keyword or two, such as "Macro" (w/o the quotes), and you will find every message ever written in this forum on the subject... ;)Possibly the clearest example of XML Macro usage was posted several weeks ago by Tom (taquillo):(A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor(A:pLANE HEADING DEGREES TRUE, radians) s0(L:Cage switch,bool)if{ 0 }els{ @Macro1 l0 - abs 0.5 Wherever you see "@Macro1" used, simply substitute whatever is contained in the Macro1 code! ;)Now it truly makes NO sense to bother with creating a @Macro unless you are planning to use the same calculation more than once or twice in any given gauge project!Notice that in Tom's example he's used the @Macro1 five times!!! thus making the code much easier to write, read and understand... :-beerchug Now, parsing the code above, the first thing Tom's done is store the value of (A:pLANE HEADING DEGREES TRUE, radians) in register s0 (s0 is a temporary memory location used only during this calculation.This allows Tom to further simplify the if/else code because anytime he needs the value of (A:pLANE HEADING DEGREES TRUE, radians), all he needs to do is write l0 (lowercase L for "load" register 0). Note that Tom's used the l0 register five times in the if/else clause as well.Had all of this been written out without the use of the register and the @Macro, the result would have been a very long and messy bit of code!!!!!(L:Cage switch,bool)if{ 0 }els{ (A:VELOCITY WORLD X, m/s) (A:VELOCITY WORLD Z, m/s) atg2 rnor (A:pLANE HEADING DEGREES TRUE, radians) - abs 0.5 Which do you suppose is the easier to write/read/understand and most importantly, maintain? *:-*

Share this post


Link to post
Share on other sites

I'm actually a big fan of the search feature, somehow I missed this in all the searches I've done over the last couple of days in various forums. I'm still working at putting rolling numbers in my RPM gauge to show elapsed time using the (A:General eng elapsed time:1,seconds) variable, and this macro would be great for all the different digits I need to shift...I understand that the part is at the top of the code, but how to call it is still unclear. Here's the macro...@1 sp0@3 0 > if{ l0 10 @3 pow * sp0 }l0 int 10 @2 pow % 10 @2 1 - 0 max pow / int And the calling:@ExtDigit((ALGVar),nDigit,nDecimals)Where:(ALGVar) is the A,L or G var from where to extract the digitnDigit is the position of the digit to extract, starting from the right (honor to RPN! )nDecimals is the number of decimals to be included in the calcs.Here's my gauge...right now I can see a number in the window when I look at the gauge in FSPS, but I don't in the sim. @1 sp0 @3 0 > if{ l0 10 @3 pow * sp0 } l0 int 10 @2 pow % 10 @2 1 - 0 max pow / int @ExtDigit((A:GENERAL ENG ELAPSED TIME:1,seconds),1,0) %((A:GENERAL ENG ELAPSED TIME:1,seconds) 3600 / d 1% 60 * r flr )%!04.0f!:%!02.0f!(A:General eng1 rpm,RPM)Sorry the indents don't show...Robert

Share this post


Link to post
Share on other sites

Try this in the statement (remove the other one after the tag: %((@ExtDigit((A:GENERAL ENG ELAPSED TIME:1,seconds),1,0)) 3600 / d 1% 60 * r flr )%!04.0f!:%!02.0f!

Share this post


Link to post
Share on other sites

Hi Robert,Some hints:> @ExtDigit((A:GENERAL>ENG ELAPSED TIME:1,seconds),1,0)/Value>Make it Maximum="9", as you're actually extracting one digit :-)And check this against the bmp layout you're using, related to the tag, with between 0 and 9.> %((A:GENERAL ENG ELAPSED TIME:1,seconds) 3600>/ d 1% 60 * r flr )%!04.0f!:%!02.0f!Replace this with %((A:GENERAL ENG ELAPSED TIME:1,hours))%!04d!:%((A:GENERAL ENG ELAPSED TIME:1,hours) 60 %)%!02d!%if you want the result in hhhh:mm format.Regards,Tom

Share this post


Link to post
Share on other sites

Thanks guys! After lots of trial & error last night I have an elapsed time indication using rolling digits. Well, digit at least. The original macro returned an integer value-no scrolling effect. I removed the 'int' entries that were in the bottom line of code, and that got the 100ths position to 'roll'(getting it to roll accurately was a battle).Right now I'm using the original macro for all the other values. When the hundredths get to 0 the tenths position increments without scrolling. Otherwise it slowly 'rolls' all the time. I don't know how to make it wait and scroll only when the value changes.Anyway, it looks good, and even though only the 100ths digit rolls the effect is good.Note: The string was a temporary display to compare the rolling digits to (accuracy check and alignment). It's not used in the final version.Robert

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