Archived

This topic is now archived and is closed to further replies.

n4gix

Little Things Can Get You Down...

Recommended Posts

It's truly frustrating when the "little things get you down," but I've been beating my head against the wall for three days on this tiny thing... ;)I'm replicating an ST-360 controller in C code, and the Altitude Alerter is mostly complete and functional except for this last niggling detail.When approaching the pre-selected altitude, a soft chime will sound when 1000' from the target, again when 300' from the target, and a soft double-chime when pre-selected altitude is captured.Also, an excursion >200' above or below the captured altitude will sound a soft chime.All of this is working and complete. The niggling detail is that the "ALR" label must flash rapidly each time the chime plays...I set up a function like this:

void flashALR(){	altcaptimer = fmod(time_count,4);	if (altcaptimer < 2 && flashcount < 72 ) { st360_AltAlert = 1; flashcount++; }	else { st360_AltAlert = 0; }}

and call the function immediately after the sound is played:

// Altitude Captureif (		st360_alr == 1	&& current_altitude > st360_altsel - 20 	&& current_altitude < st360_altsel + 20 	&& acftongrnd == 0){ 	altcap = 1;	altwascap = 1;	if (altcap_oneshot == 0 && mute == 0)	{		(GaugePlaySound)("sound\\ESEP\\twotonechime.wav","",0);		altcap_oneshot = 1;	}	flashALR();}else { altcap_oneshot = 0; altcap = 0; flashcount = 0; }

There are two problems though.1. Only the above instance will cause the "ALR" label to blink.2. The function doesn't always end with st360_AltAlert = 0, which means the "ALR" label is not displayed, as the element's visibility is controlled thusly:

if (st360_alr && st360_AltAlert == 0) st360_showalr = true; else st360_showalr = false;

Where st360_alr is the button's position and st360_showalr controls the ALR image's visibility

Share this post


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

Well, you kinda went about that in what I would call the 'brute force' method.Here's a few ideas:1 - Set up a central flash variable... just a bool value.2 - Set up a central timer that is responsible for flipping the flash bool value between true and false.3 - In your logic simply trigger whether ALT needs to flash or not.

FLOAT64 flash_timer = 0;bool flash_on = false;FLOAT64 flash_alt_timer = 0;bool flash_alt = false;void update_flash(){  if (elapsedTime>=flash_timer)  {	flash_on = ~flash_on; // I think it's ~ and not ! but my mind's old and feeble.;)	flash_timer = elapsedTime + flash_cycle_duration; // flash_cycle_duration is the on/off cycle duration  }}void to_flash_or_not_to_flash(){  // decide if we need to flash or not... then  if (we_need_to_flash) // if we do...  {	flash_alt = true;	flash_alt_timer = flash_duration; // flash_duration is how long you want the flash to happen  }}void some_main_gauge_code_area(){  if (flash_alt)  {	if (flash_on)	{ // we need to flash, and it's the 'on' cycle... display!	}	if (elapsed_timer>=flash_alt_timer)	{ // shouldn't do any more flashing...	  flash_alt = false;	  flash_alt_timer = 0;	}  }  else  { // if we need to display it solid on... do it here.  }}

Share this post


Link to post
Share on other sites

Thanks, Ed. I've got that sorted out now. Onwards to code the DH alert sound(s) and flashing DH label......then add the bloody "keyboard support" for this package... <ugh!> :(

Share this post


Link to post
Share on other sites
flash_on = ~flash_on; // I think it's ~ and not ! but my mind's old and feeble.;)

Definately don't want to be picky here, but I'm pretty sure it is !, not ~. :( Just to clarify. ~ was the bitwise NOT thingy. Thanks to both for posting your ideas. :(

Share this post


Link to post
Share on other sites

I have always found it helpful in programing generally to have lots of "state" variables - boolean or integer as appropriate. Also, having to identify the possible states an object can be in helped my initia thinking about the logic. It makes it much easier to write code to set, reset, or read them wherever at the appropriate places in the aplication.

Share this post


Link to post
Share on other sites