Sign in to follow this  
Guest bartels

Alright, now on to make a string blink

Recommended Posts

Hey all.Arne helped me earlier with getting the xpdr code to show. That works fine, and I even defined some MOUSE_CHILD rectangles for me to test and see if I could increase the numbers by clicking on them. Works fine.Now to replicate the operations of this xpdr, I will need to do the following: Right click the mouse in a defined rectangle. That should make only the first number blink. Then with left clicks on the same rectangle that started the blinking, this number should increase.After the number is what you want, right click again, and the second number will now blink, with left clicks increasing it. Another right click and now the third number blinks, you adjust it the same way.Right click, the fourth and last number blinks, you adjust, and finally you right click again, and they all stop blinking.I understand, as said above, how to increase them. What I don't know is:1 - How to make a string blink (although I have an idea: define, say, a=0, make a loop that will serve as timer (by using TIK18) and will display nothing, or "" as the last thing in the wsprintf. When the time runs out, set a=1. Following is a loop that only starts if a=1, has the same timer, and will set wsprintf to the actual value. When the loop ends, it sets a=0 again, to start all over)2 - Following the idea above, how can I erase only one number from the xpdr code BCD? As of now, I read them as %04x, so I have no idea here.3 - The general arrangement of this entire issue. Where time loops would go, who would change what variables to what and where.I know I am asking for a lot, but I've got nowhere else to run :-). And the panel will be freeware :7

Share this post


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

>1 - How to make a string blink (although I have an idea: >define, say, a=0, make a loop that will serve as timer (by >using TIK18) and will display nothing, or "" as the last >thing in the wsprintf. When the time runs out, set a=1. >Following is a loop that only starts if a=1, has the same >timer, and will set wsprintf to the actual value. When the >loop ends, it sets a=0 again, to start all over) >>2 - Following the idea above, how can I erase only one >number from the xpdr code BCD? As of now, I read them as >%04x, so I have no idea here. The simplest way would be to "mask" one digit with a ' '. E.g. the callback runs like:{...//preset with the "real" xpndr codewsprintf(pelement->string,"%04x",xpndrcode);...//cover first digit:pelement->string&l;0&r;=' ';...//cover second digit:pelement->string&l;1&r;=' ';...//cover third digit:pelement->string&l;2&r;=' ';...//cover last digit:pelement->string&l;3&r;=' ';return xpndrcode;}The Concorde XPNDR does something similar with '_' instead of ' '.>>3 - The general arrangement of this entire issue. Where >time loops would go, who would change what variables to what >and where. I'm not sure if I understood the logic behind it yet, additionaly I have my doubts with right clicks.Arne Bartels

Share this post


Link to post
Share on other sites

Huh? You can access the single chars that easy?? Wow. Gotta remember that, heheh...The rightclick cannot be done as easily as desribed in the SDK I think cause of the popup menu. Recently I saw a post on FlightSim.Com about something working... Here's some quote:Hi Bill,The answer is very simple, see this sample mouse CB function:BOOL FSAPI YourMouseCb ( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if ( mouse_flags & MOUSE_LEFTSINGLE ) { // // Left Mouse Button Functionality here // } else if ( mouse_flags & MOUSE_RIGHTSINGLE ) { // // Right Mouse Button Functionality here // } return ( TRUE );}Obviously with the same method you can be sensible to other MOUSE_BLABLA flags.When checking for many of them, also, I'd use a switch() statements rather thana neverending list of if(){}else if(){}else if(){} etc.Hope this helps,CiaoMarco>I'm getting requests that I institute a system that allows a right mouse button>press to increase autopilot heading in increments of ten instead of one, like>PSS uses. I know I can program a mouse function to use the right mouse along>with the left by using this....>>MOUSE_CHILD_FUNCT(820,58,6,17, CURSOR_DOWNARROW, MOUSE_LEFTSINGLE |>MOUSE_RIGHTSINGLE | MOUSE_DOWN_REPEAT, ias_mach_dec10_mf)>>... but this does either left of right mouse, and I can't figure out a way to>tell which one is pressed so I can either increment by ones or tens. Putting>two mouse click zones overlying each other won't work either.>>Bill Grabowski>wsgrabowski@attbi.com>Etienne :-wave

Share this post


Link to post
Share on other sites

I've just found another thing which might be of some use, especially for setting a new code:Hi,you need to set only the last four numbers, e.g. 0845 for 108.45. You also haveto use bcd numbers (binary coded decimals) where every group of 4 bits (= onehex digit) represents one decimal digit.If you want to set 113.45, do this:int n1, n2, n3, n4, bcd;n1 = 1; // first digitn2 = 3; // second digitn3 = 4; // third digitn4 = 5; // fourth digit//calculate bcd numberbcd = (n1 8) + (n3 << 4) + n4;trigger_key_event(KEY_VOR1_SET, bcd);That's all.For more detailed information about how to handle bcd numbers, have a look at Dai's sd2gau08.zip.HansEtienne :-wave

Share this post


Link to post
Share on other sites

Hey guys.I will give it a try with the information you provided me.Regarding right mouse clicks, I have them working fine, using, for example,

MOUSE_CHILD_FUNCT( 90, 25, 22, 18, CURSOR_UPARROW, MOUSE_RIGHTSINGLE, xpdr_0100_select)

xpdr_0100_select then increases the second xpdr code using

BOOL FSAPI xpdr_0100_select( PPIXPOINT relative_point, FLAGS32 mouse_flags ){			trigger_key_event(KEY_XPNDR_100_INC, 0);	return FALSE;}

Alright, back to work.

Share this post


Link to post
Share on other sites

Something like this?

#define   BLINK_FREQUENCY	0.5int	   selected_digit=-1;FLOAT64 FSAPI xpdr_code_cb (PELEMENT_STRING pelement){   FLOAT64 time=0;   BOOL is_masked=FALSE;   wsprintf(pelement->string,"%04x",pelement->source_var&l;0&r;.var_value.d);   if(selected_digit>=0)   {	  time=fmod(pelement->source_var&l;1&r;.var_value.n,BLINK_FREQUENCY);	  //recalc to something between 0...1	  time/=BLINK_FREQUENCY;	  	  if(time>0.5)		 is_masked=TRUE;	  if(is_masked)		 pelement->string&l;selected_digit&r;=' ';	}		return pelement->source_var&l;0&r;.var_value.d+is_masked;}MAKE_STRING(   xpdr_code,   NULL,   xpdr_fail,   IMAGE_USE_ERASE | IMAGE_USE_BRIGHT | IMAGE_USE_TRANSPARENCY,   0,   68, 25,   90, 18,   4,   TRANSPONDER_CODE,   ELAPSED_SECONDS,   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)...BOOL	FSAPI	SetXpndr( PPIXPOINT relative_point, FLAGS32 mouse_flags){   if(mouse_flags&MOUSE_RIGHTSINGLE)   {	  selected_digit++;	  if(selected_digit==4)		 selected_digit=-1;   }	   if(mouse_flags&MOUSE_LEFTSINGLE)   {	  switch(selected_digit)	  {		 case   0:			trigger_key_event(KEY_XPNDR_1000_INC,0);			break;		 case   1:			trigger_key_event(KEY_XPNDR_100_INC,0);			break;		 case   2:			trigger_key_event(KEY_XPNDR_10_INC,0);			break;		 case   3:			trigger_key_event(KEY_XPNDR_1_INC,0);			break;	   }   } 	   return   FALSE;}....  MOUSE_CHILD_FUNCT( 90, 25, 22, 18, CURSOR_UPARROW,		MOUSE_LEFTSINGLE|MOUSE_RIGHTSINGLE, SetXpndr)

For blinking speed adjust BLINK_FREQUENCY. Arne Bartels

Share this post


Link to post
Share on other sites

>#define BLINK_FREQUENCY 0.5 What actually makes the difference declaring a var with #define or with e. g. UINT8?

Share this post


Link to post
Share on other sites

Wow, Arne! Thanks a lot!Couple things I don't understand a couple of things:1 - In the following loop

if(selected_digit>=0){	  time=fmod(pelement->source_var[1].var_value.n,BLINK_FREQUENCY);	  //recalc to something between 0...1	  time/=BLINK_FREQUENCY;	  if(time>0.5)		 is_masked=TRUE;	  if(is_masked)		 pelement->string[selected_digit]=' ';	}

I don't get the logic. Is fmod a function defined by windows.h, gauges.h or math.h? And what is it doing? I understand it is reading ELAPSED_SECONDS, but I am not sure what it does with that and BLINK_FREQUENCY at the same time.What do you mean by recalculate to something between 0...1? Who do I have to recalculate?And finally , I don't know what time/=BLINK_FREQUENCY; means.Oh, one more thing. Why are you returning return pelement->source_var[0].var_value.d+is_masked; instead of return pelement->source_var[0].var_value.d;?Thanks a lot forthe help Arne.

Share this post


Link to post
Share on other sites

>Couple things I don't understand a couple of things: >>1 - In the following loop >>if(selected_digit>=0) >{ > >time=fmod(pelement->source_var[1].var_value.n,BLINK_FREQUENCY); > //recalc to something between 0...1 > time/=BLINK_FREQUENCY; >> if(time>0.5) > is_masked=TRUE; > if(is_masked) > pelement->string[selected_digit]=' '; >} >>I don't get the logic. Is fmod a function defined by >windows.h, gauges.h or math.h?The function fmod is defined in math.h and it's just x modulo y, he rest of the division.>And finally , I don't know what>time/=BLINK_FREQUENCY; means. It's a short form for:time = time / BLINK_FREQUENCY;It's like this: You can also do that with +, -, *, %, ^, <<, >>... etcIf you have this:A = A + B;you can shorten it to:A += B;Another example:X = X * Y;can be:X *= Y;Shweet C.Etienne :-wave

Share this post


Link to post
Share on other sites

The difference is that a "#define something else" is just that every string "something" is replaced with "else". A variable declarations like UINT8 is a complete variable, for a purpose of a constant value. A #define doesn't need any memory, whereas any variable does. For our purposes, the difference is more or less meaningless. Ir's just "my way" to use #defines for constants.Arne Bartels

Share this post


Link to post
Share on other sites

Oops, fmod is in math.h, I forgot to include that one I think (I include math.h always so I forgot to mention it).I wanted to achieve that you can make the blink frequency simply by changing one parameter BLINK_FREQUENCY. #define BLINK_FREQUENCY 0.5 means 0.25 sec off, 0.25 sec. on, so the whole repeating time is 0.5s or 2Hz (I know, it is blink time constant not frequency, sorry, got that wrong).In a first step with fmod, I make sure the value time goes from 0 to 0.5, to 0 to 0.5 etc. Then divide it by 0.5 to get in a range from 0 to 1. To allow a simple if(time<0.5) instead of anything more complicated, where I need to modulo divide by one parameter and then decide if it is on or off on another parameter. With variations of time<0.5 you can get different on and off times. if(time < 0.6) gives e.g. 0.3 secs off and 0.2 secs on. The time base isn't changed but the relation between on and off.> pelement->string=' ';This is really dangerous. I don't know if it is the old forum problem, but ist has to bepelement->string&l;selected_digit&r;=' '; pelement->string=' '; sets the pointer to the string element somewhere in the nirvana of your system memory (to the address 0x20 precisely). This is presumably somewhere in the vitals, so some changes in the display are relatively harmless, a full crash can also happen!With you change one of the elements of the string element directly, this is something completely different then "bending the pointer around". pelement->string=' '; does look very similar to pelement->string&l;selected_digit&r;=' '; but it is something very different! Ans C is a language with "all safety catches off".Last the reason for returning return pelement->source_var&l;0&r;.var_value.d+is_masked;is that strings (all drawing elements) are redrawn if the return value of the callback changes. Returning the sum of both values means, redraw every time the transponder code changes, or the blink state changes.Arne Bartels

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