Sign in to follow this  
taguilo

Elaspsed timer reset

Recommended Posts

Hi all Stuck with how to get a single push button to cycle my timer On, Off, Reset to zero. Here's what I got so far. %ET %((P:ABSOLUTE TIME, seconds) d (G:Var1) - r (>G:Var1) (L:OffOn,bool) if{ (G:Var2) + (>G:Var2) } (G:Var2) 3600 / 24 % 1 (G:Var3) case d flr )%!02d!:%( 1 % 60 * d flr )%!02d!(L:OffOn,bool) ! (>L:OffOn,bool) can anyone help

Share this post


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

Hi, Not exactly your code, but this should work (or almost :-))%ET %((L:MyVar, seconds) (G:Var1) (P:ABSOLUTE TIME, seconds) - abs 0 3 (L:OnOffReset,enum) case (>L:MyVar, seconds) (L:MyVar,hours) int)%!02d!%:%((L:MyVar,minutes) 60 % int)%!02d! (L:OnOffReset,enum) ++ d 3 != * d (>L:OnOffReset,enum) 1 == if{ (P:ABSOLUTE TIME, seconds) (>G:Var1) } Starts in reset mode (L:OnOffReset,enum) = 0Then to On mode, begin to sumThen to Off mode, freezes valueThen to reset, back to 00:00TomNote: Beware GVars reset to 0 whenever ALT_ENTER or Panel ReloadsI'd recommend to use a LVar instead

Share this post


Link to post
Share on other sites

Tom Tried that but don't have the first two zeros showing (Hours) ET :00 and no counting. Cycle button changes OK but button is in another gauge so no sure the G:vars link. Paul

Share this post


Link to post
Share on other sites

Hi Tom Worked it out, one typo and changed the G:vars to L:'s works good. Thanks Paul

Share this post


Link to post
Share on other sites

Hi,Can you give the code?Interested too.Cannot get it to work.Jan"Beatus ille qui procul negotiis..."

Share this post


Link to post
Share on other sites

Hi Jan This works OK, The click is in a seperate gauge. %ET %((L:ETVar, Seconds) (L:Off1, enum) (P:Absolute time, seconds) - abs 0 3 (L:OffOnReset,enum) case (>L:ETVar, seconds) (L:ETVar, hours) int)%!02d!%:%((L:ETVar,minutes) 60 % int)%!02d!(L:OffOnReset,enum) ++ d 3 != * d (>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds) (>L:Off1, enum) } Paul

Share this post


Link to post
Share on other sites

>>>Hi Jan> This works OK, The click is in a seperate gauge. >> %ET %((L:ETVar, Seconds) (L:Off1, enum) (P:Absolute>time, seconds) - abs 0 3 (L:OffOnReset,enum) case (>L:ETVar,>seconds) (L:ETVar, hours) int)%!02d!%:%((L:ETVar,minutes) 60 %>int)%!02d!>> (L:OffOnReset,enum) ++ d 3 != * d>(>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds)>(>L:Off1, enum) }>> PaulPaul/Tom,Since I am still getting used to RPN (I've always used in-fix based languages to program), could you please perhaps walk through this and explain why/how it is working? Better yet, if you'd be willing to translate to infix I'd be very grateful.Thanks,J-

Share this post


Link to post
Share on other sites

J-,Pseudo code would be like> (L:OffOnReset,enum) ++ d 3 != * d> (>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds)> (>L:Off1, enum) }"If (L:OffOnReset,enum) is lower than 3, add one to (L:OffOnReset,enum) else assing 0 to (L:OffOnReset,enum)""If (L:OffOnReset,enum) is 1, save (P:Absolute time, seconds) value to (L:Off1, enum)" %ET %((L:ETVar, Seconds) (L:Off1, enum) (P:Absolute>time, seconds) - abs 0 3 (L:OffOnReset,enum) case (>L:ETVar,>seconds) (L:ETVar, hours) int)%!02d!%:%((L:ETVar,minutes) 60 %>int)%!02d!"If (L:OffOnReset,enum) is 0, assign 0 to (L:ETVar, Seconds)""Elseif (L:OffOnReset,enum) is 1, assign the difference between (L:Off1, enum) and (P:Absolute time, seconds) in absolute value (to get rid of minus sign) to (L:ETVar,seconds)""Elseif (L:OffOnReset,enum) is 2, assign (L:ETVar, Seconds) the same value it had on the previous cycle""Make FS automatically convert (L:ETVar, Seconds) to (L:ETVar, Hours) and remove the decimals to prevent roundings." "Make FS automatically convert (L:ETVar, Seconds) to (L:ETVar, minutes) ;obtain the remainder of hours' multiplo and remove the decimals to prevent roundings". "Express all this stuff as ET HH:MM, with leading zeros"This was the best I could do :-)Tom

Share this post


Link to post
Share on other sites

>J-,>>Pseudo code would be like>>> (L:OffOnReset,enum) ++ d 3 != * d>> (>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds)>> (>L:Off1, enum) }>>>"If (L:OffOnReset,enum) is lower than 3, add one to>(L:OffOnReset,enum) else assing 0 to (L:OffOnReset,enum)">"If (L:OffOnReset,enum) is 1, save (P:Absolute time, seconds)>value to (L:Off1, enum)" >> %ET %((L:ETVar, Seconds) (L:Off1, enum) (P:Absolute>>time, seconds) - abs 0 3 (L:OffOnReset,enum) case (>L:ETVar,>>seconds) (L:ETVar, hours) int)%!02d!%:%((L:ETVar,minutes) 60>%>>int)%!02d!>>>"If (L:OffOnReset,enum) is 0, assign 0 to (L:ETVar, Seconds)">"Elseif (L:OffOnReset,enum) is 1, assign the difference>between (L:Off1, enum) and (P:Absolute time, seconds) in>absolute value (to get rid of minus sign) to>(L:ETVar,seconds)">"Elseif (L:OffOnReset,enum) is 2, assign (L:ETVar, Seconds)>the same value it had on the previous cycle">>"Make FS automatically convert (L:ETVar, Seconds) to (L:ETVar,>Hours) and remove the decimals to prevent roundings." >>"Make FS automatically convert (L:ETVar, Seconds) to (L:ETVar,>minutes) ;obtain the remainder of hours' multiplo and remove>the decimals to prevent roundings". >>"Express all this stuff as ET HH:MM, with leading zeros">>This was the best I could do :-)>>Tom>>> >>Tom,Thanks. Maybe I'm stupid, but I don't see any if else structure in that code - neither do I see the ? operator (L:OffOnReset,enum) ++ d 3 != * d(>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds)(>L:Off1, enum) }

Share this post


Link to post
Share on other sites

>Tom,>>Thanks. Maybe I'm stupid, but I don't see any if else structure in >that code - neither do I see the ? operator>>>Click> (L:OffOnReset,enum) ++ d 3 != * d> (>L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds)> (>L:Off1, enum) }I used "if/elseif" as pseudo code to make things more understandable. Here bool maths ("3 != *") are replacing "if{" structures.A more "standard" XML phrase would be: (L:OffOnReset,enum) 1 + s0 3 < if{ l0 } els{ 0 } (>L:OffOnReset,enum) (L:OffOnReset,enum) 1 == if{ (P:Absolute time, seconds) (>L:Off1, enum) }TomEdit: In the section I used "case" operator, that searchs for a "passed" value among three stack values. Something likeSelect case a case a = 0 case a = 1 case a = 2End selectAgain, the "if/elseif" was mere pseudo code

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