Sign in to follow this  
mgh

MAKE_NEEDLE: Extremely baffled!

Recommended Posts

Okay, I can't figure this one out at all. Anyone willing to put forth some assistance, I would be grateful. I'll try to make the question clear, since the issue isn't.I'm working on an EICAS gauge. I have the N1 needles working properly. Also displayed is the EGT readings. However, even though the EGT MAKE_NEEDLE functions are basically the same as the N1 setup, the EGT needles don't display properly.Here's an example of my code://-------------------------------------------------------------------#define GAUGE_MIN_EGTL 0#define GAUGE_MAX_EGTL 760NONLINEARITY egtl_nlt[]={ {{135,209},0,0}, {{132,226},421,0}, {{32,239},666,0}, {{35,175},730,0}, {{39,171},760,0}};FLOAT64 FSAPI egtl_ndl_cb(PELEMENT_NEEDLE pelement){ FLOAT64 val_egtl_ndl = pelement->source_var.var_value.n; if(val_egtl_ndl > GAUGE_MAX_EGTL) val_egtl_ndl = GAUGE_MAX_EGTL; if(val_egtl_ndl < GAUGE_MIN_EGTL) val_egtl_ndl = GAUGE_MIN_EGTL; return val_egtl_ndl;}MAKE_NEEDLE( ndl_egtl, BMP_NEEDLE_EGT, NULL, NULL, IMAGE_USE_ERASE, 0, 79,209, 1,56, GENERAL_ENGINE1_EGT, egtl_ndl_cb, egtl_nlt, 3)//-------------------------------------------------------------------If there are any glaring errors in here, please point me in the right direction for a fix. The needles show up on the gauge, but don't move, even though the digital readout (MAKE_STRING) works fine.Thanks,Matt

Share this post


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

Okay, I'm an idiot... The problem lay not in the code or the nonlinearity table, but in the Token Variable. I forgot to convert it from Deg Ra to Deg C.

Share this post


Link to post
Share on other sites

Just out of curiosity, why do you bother with "named constants?"if(val_egtl_ndl > GAUGE_MAX_EGTL)val_egtl_ndl = GAUGE_MAX_EGTL;if(val_egtl_ndl < GAUGE_MIN_EGTL)val_egtl_ndl = GAUGE_MIN_EGTL;Why not simply:if(val_egtl_ndl > 760)val_egtl_ndl = 760;if(val_egtl_ndl ;)

Share this post


Link to post
Share on other sites

Hey, Bill.A couple of reasons, actually:1. Most of my programming experience came from VB, and it's habit. I had a #### of a time getting the OOP dynamic out of my head when I started this project.2. I'm still really new to C programming and it helps keep me clear on what's what!I don't mind the typing, really; I write, so typing isn't a difficulty.

Share this post


Link to post
Share on other sites

Using #defines for numbers is a good idea as soon as they're used in more than one place. I know a lot of people who always use #defines for any kind of constant.

Share this post


Link to post
Share on other sites

And why not even simpler ?val_egtl_ndl=max(GAUGE_MIN_EGTL,min(GAUGE_MAX_EGTL,val_egtl_ndl));;-)

Share this post


Link to post
Share on other sites

A quote from Kernighan and Ritchies's classic - The C Progamming Language:'It's bad practice to bury "magic numbers" like 300 or 20 in a program; they convey little information to someone who might have to read the program, and they are hard to change in a systematic way.'

Share this post


Link to post
Share on other sites

>And why not even simpler ?>>val_egtl_ndl=max(GAUGE_MIN_EGTL,min(GAUGE_MAX_EGTL,val_egtl_ndl));>>;-)Because simpler code isn't necessarily the faster in execution.The functions max and min will still have to make the comparisions in the original code and will have the additional overhead of 2 function calls.

Share this post


Link to post
Share on other sites

>Using #defines for numbers is a good idea as soon as they're>used in more than one place. I know a lot of people who always>use #defines for any kind of constant.Fair enough. I do in fact use "named constants" myself whenever the occasion demands... ;)Is there any inherent advantage to using #define rather than a variable declaration, aside from the visual clue that it IS a "constant?"#define myconstant 100vs.int myconstant = 100;

Share this post


Link to post
Share on other sites

In theory there is an advantage to using #define. Where ever you use myconstant in code the pre-processor will substitute it before compling the code. Thus if you code:#define myconstant 100x = a * myconstant;what will be complied is:x = a * 100;This will generally be faster than the original statement, although in most situations you'd be hard pressed to notice it.One common convention is to use capitals for defined constants to make them even more obvious.#define MYCONSTANT 100x = a * MYCONSTANT;

Share this post


Link to post
Share on other sites

"The functions max and min will still have to make the comparisions in the original code and will have the additional overhead of 2 function calls."Wrong. At least for the Microsoft C/C++ compilator, min & max are not real functions but macros ;-)

Share this post


Link to post
Share on other sites

But it's not true for all compiliers.Also macros can introduce problems with side effects. A max macro is typically defined as:#define max(A, :( ((A) > (:() ? (A) : (:()which evaluates both arguments twice.

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