Sign in to follow this  
taguilo

Case statement in XML gauge

Recommended Posts

Hello XML Gods of AVSIM.This is my first post here but I have been using this forum as a reference for some time.I am in the process of building a quite complex MFD system for a Raytheon T-6B prototype. The MFD works on a basic logic to allow easy modification, with each page of the MFD being allocated an enumerated value using (L:page_select, enum).Now, the problem I am having with so many pages, is with my Case statements and logical OR mathematics.Problem 1:Why doesn't the set of elements below this line display when the values of 91 and 92 are in the variable. I know the variable has the correct number in it at the time b/c I have set up a debug gauge as well.((L:page_select, enum) 91 == ) ((L:page_select, enum) 92 == ) ||Am I doing the OR statement wrong?Problem 2:I have never tried before, but can I use a Case statement in a Click tag? Like this:(L:page_select, enum) 93 (>L:page_select, enum) 93 (>L:page_select, enum)I look forward to any help you might be able to give me!Thanks guys.daz

Share this post


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

no post should go unanswered! bla bla bla bla (L:page_select, enum) 91 == if{ 93 (>L:page_select, enum) } els{ (L:page_select,emum) 92 == if{ 93 (>L:page_select, enum) } els{ (L:page_select,emum) xx == if{ ?? (>L:page_select, enum) } } }it can go on as long as you need.i am the worst of programers, but you look like your after my title!i am no god of xml.( what a mean fellow he must be) i instantly saw a easier way up your hill.in all my prowling through gauges i have never seen a case in a mouse statement used like that.... there are some really neat things you can do with 'case' but brother... i think you brought a duck to a cockfight.

Share this post


Link to post
Share on other sites

Hahahaha. That isn't "exactly" what I expected to get back as a reply, but it made me laugh anyway.Works a treat though - except for the minor spelling mistake of enum. *said with tic*It's a bummer that I am going to have to go this way - some of my line select keys are going to have about 30 possible uses.... dread.Any ideas on the first problem?Cheers,Daz.

Share this post


Link to post
Share on other sites

Never mind - I worked it out myself.This works:(L:page_select, enum) 91 == (L:page_select, enum) 92 == ||I've worked out the logic in my head finally I think! I used to use RPN at university all the time, but it's been 6 years since I last used it!

Share this post


Link to post
Share on other sites

For problem 1 quite possibly it is syntax. You have it somewhat correct for a string. Whilst for a tag not quite sure. Maybe try...(L:page_select, enum) 91 == (L:page_select, enum) 92 == ||(L:page_select, enum) s1 91 == l1 92 == ||the above are both the same except in the 2nd example when L:page... is called it is loaded into a temporary store for use immediately. s0 - s49 = Store in registers 0-49sp0 - sp 49 Store in registers 0-49 but remove value from stackl0 - l49 is to load the register #When the gauge is reread by the panel system per frequency, at the start of the gauge read, all registers become zero ( 0 ). You can reuse a single register over and over throughout a gauge as long as the "s=STORE" of the register happens before the next "l=LOAD". Problem #2 -While you have the right idea, the Select>Case tags work mainly for bitmaps. There is a workaround but if you have 92 + pages this could become very complicated.EX. 1 2 3 4 5 5 (L:select_my_page, enum) case (>L:make_my_page_work, enum) 1 2 3 4 5 are the the pages to be loaded to (>L:make_my_page_work, enum) based on the number/expression prior to "case". The second "5" is the number of options available to see where in the stack to look.For the example you have given above, below is an example of how it can work inside a tag set. 93 93 2 (L:page_select, enum) 90 - case (>L:page_select, enum) Works like this -- gauge system reads a "case" before the load into the next page select, it sees there are 2 options, from your previous page selected it subtracts 90 to give a ( 91 = select #1 , 92 = select #2 ) and at the very end a 93 gets loaded into (>L:page_select, enum).Another EX6 9 7 3 4 2 9 2 8 ( X ) case ( >Y)8 possibilitiesX Y------1 = 22 = 93 = 24 = 45 = 36 = 77 = 98 = 6It's very powerfull, but a pain in the neck to debug if necessary :-(I hope I got this right :-) and hope it helpsRegards,RomanKGRB!!!!EDIT!!!! it may be slightly wrong, giver a test... The first value selected by the "case" may need a zero to call it... Sorry donot remember at this time so if this is the case the above table would look like.... 6 9 7 3 4 2 9 2 8 ( X ) case ( >Y)8 possibilitiesX Y------0 = 21 = 92 = 23 = 44 = 35 = 76 = 97 = 6!!!!! END EDIT SORRY !!!!!!!!

Share this post


Link to post
Share on other sites

well there coutless ways to skin a cat, if you want to go the case route, just use the to set a var, the put your case matrix in a code startmix a case with a string and you got a mack-daddy tool, dont get me wrong, but in side a click statement you asking a lot. try setting a var then get fancy under an Element.heres a lill ditty to set radios, mixing case and a string, saved me a bunch of typing! you could adapt it for any matrix. this one sorts out a channel then cooses between 5 options 100 * 10000 % int d 10 % r 10 / int d 10 % r 10 / int d 10 % r 10 / int 16 * + 16 * + 16 * + (>K:COM_RADIO_SET) (L:change,bool) if{ (L:cchannel,enum) 1 == if{ 124.67 129.10 119.05 123.30 119.05 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 2 == if{ 127.50 127.10 121.85 128.70 122.10 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 3 == if{ 123.30 123.30 127.30 128.50 122.10 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 4 == if{ 125.95 130.60 127.40 126.90 122.20 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 5 == if{ 130.20 130.90 135.65 130.90 119.50 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 6 == if{ 119.00 128.20 125.45 130.80 118.40 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 7 == if{ 126.20 126.20 125.80 122.15 128.40 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 8 == if{ 125.20 123.30 121.65 129.55 132.75 5 (L:ctype,enum) case @fixradio } (L:cchannel,enum) 9 == if{ 128.45 123.30 124.50 129.90 119.20 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 10 == if{ 123.30 123.30 124.50 123.30 124.05 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 11 == if{ 119.30 128.20 123.00 123.30 124.55 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 12 == if{ 125.20 121.05 132.95 135.85 132.60 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 13 == if{ 126.85 126.85 123.30 126.85 119.50 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 14 == if{ 123.30 123.30 124.20 130.10 121.60 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 15 == if{ 135.35 135.35 124.20 126.40 119.30 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 16 == if{ 123.35 123.35 123.35 120.10 129.60 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 17 == if{ 118.25 118.25 118.25 122.70 118.60 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 18 == if{ 119.45 119.45 119.45 119.45 129.20 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 19 == if{ 129.55 121.70 118.80 132.45 129.27 5 (L:ctype,enum) case @fixradio }(L:cchannel,enum) 20 == if{ 123.75 118.50 121.70 121.82 119.00 5 (L:ctype,enum) case @fixradio } 0 (>L:change,enum) } els {0} the thing reads better on notepad, its set up like a grid, its not only fairly compact, but i can go back and edit it for different channels in a snap.

Share this post


Link to post
Share on other sites

That looks REALLY GOOD :-)MEEEEEEEOWWWWWWW --- Just saw a skinless cat LOL !!!!! EDIT --- That's almost cheating LOL !!! Set up your flight, mod up the XML and go hit it. No turnin of the knobs!!Regards,Roman

Share this post


Link to post
Share on other sites

Hi,This use of "case" structure is very efficient when dealing with complex code.Now, just some hints that would help the compiler to optimize the resultant code, and is a hand-coding saver as well:Instead of repeating (L:cchannel,enum) you may save it to a register at the top of the snippet, "(L:cchannel,enum) s0" and the use "l0 1 == ; l0 2 ==" etc to make the comparison. In this case you'll save a lot of typing and make FS access the value a bit faster (registers are accesed faster than var memory areas). The same applies for (L:ctype,enum)Instead of placing @fixradio on each "case" line, you may save the "case" result to a register (ie "case s1 } and then at the end of the snippet call the macro like: ...0 (>L:change,enum) l1 @fixradio } Or use a goto operator, which will avoid to process each line of comparison until the end of the snippet.The point here is, each time the macro is called, the compiler will replace the @macro reference with the code included in the structure, then if you call it 20 times, at run time there will be a lot of code inserted which, in complex projects, may have incidence in the gauge's performance. Tom

Share this post


Link to post
Share on other sites

wow, i wrote the code as an example to help the poster, guess helping the helper is cool.....way cool thx!

Share this post


Link to post
Share on other sites

That post was not intended to be a "help to the helper" but instead an observation of the way the compiler treats the source code, and a simple example on how to make FS take benefit of it.:-)Tom

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