Jump to content

Sign in to follow this  
n4gix

Selected Vertical Speed change in a C gauge...

Recommended Posts

Here's one way to get "Vertical Speed Change" working in a C autopilot. VS is selected via the "knob" to descend or ascend. Clicking on the knob's center will "cancel" SVS (Selected Vertical Speed) and return the AP HOLD (current altitude.For brevity, I've only included the relevant parts of the C source code:/* The two FLOAT64 values may be simple "float" if you wish. I have to use FLOAT64 because of the need to convert to WCHAR for a GDI+ string */FLOAT64 vspeed = 0 ; // This variable is used for display of the AUTOPILOT_VERTICAL_HOLD_VARFLOAT64 dvspeed = 0 ; // This variable is needed because the AUTOPILOT_VERTICAL_HOLD_VAR cannot be "changed" when in ALT HOLD modeMODULE_VAR AUTOPILOT_ALTITUDE_LOCKvar = {AUTOPILOT_ALTITUDE_LOCK};MODULE_VAR AUTOPILOT_ACTIVEvar = {AUTOPILOT_ACTIVE};MODULE_VAR AUTOPILOT_HEADING_LOCKvar = {AUTOPILOT_HEADING_LOCK};MODULE_VAR AUTOPILOT_NAV1_LOCKvar = {AUTOPILOT_NAV1_LOCK};MODULE_VAR GPS_GROUND_TRACKvar = {GPS_GROUND_TRACK};MODULE_VAR AUTOPILOT_VERTICAL_HOLD_VARvar = {AUTOPILOT_VERTICAL_HOLD_VAR};MODULE_VAR AUTOPILOT_VERTICAL_HOLDvar = {AUTOPILOT_VERTICAL_HOLD};MODULE_VAR AUTOPILOT_ATTITUDE_HOLDvar = { AUTOPILOT_ATTITUDE_HOLD };case PANEL_SERVICE_PRE_UPDATE: lookup_var(&AUTOPILOT_ALTITUDE_LOCKvar); lookup_var(&AUTOPILOT_ACTIVEvar); lookup_var(&AUTOPILOT_NAV1_LOCKvar); lookup_var(&AUTOPILOT_VERTICAL_HOLD_VARvar); lookup_var(&AUTOPILOT_ATTITUDE_HOLDvar); vspeed = (AUTOPILOT_VERTICAL_HOLD_VARvar.var_value.n); lookup_var(&AUTOPILOT_HEADING_LOCKvar); lookup_var(&AUTOPILOT_HEADING_LOCK_DIRvar); hdg = (AUTOPILOT_HEADING_LOCK_DIRvar.var_value.n); lookup_var(&HSI_OBI_NEEDLEvar); crs = (HSI_OBI_NEEDLEvar.var_value.n); lookup_var(&GPS_GROUND_TRACKvar); dtk = RAD_TO_DEG(GPS_GROUND_TRACKvar.var_value.n);break;case PANEL_SERVICE_PRE_DRAW: { /* Update Routines */ /* The dvspeed variable is set via the "knob turn" in the mouse callback. This line ensures that the "selected altitude" is always different (plus or minus) than current altitude! */ trigger_key_event(KEY_AP_ALT_VAR_SET_ENGLISH, (ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n + dvspeed) ); }break;/* This is the DECREASE mousepoint */BOOL FSAPI DF_mouse_cb2( PPIXPOINT relative_point, FLAGS32 mouse_flags){ if (mode == 3 || mode == 5) { dvspeed = dvspeed - 100 ; trigger_key_event(KEY_AP_VS_VAR_SET_ENGLISH, dvspeed); trigger_key_event(KEY_AP_WING_LEVELER_OFF,0); } return FALSE;}/* This is the INCREASE mousepoint */BOOL FSAPI DF_mouse_cb3( PPIXPOINT relative_point, FLAGS32 mouse_flags){ if (mode == 3 || mode == 5) { dvspeed = dvspeed + 100 ; trigger_key_event(KEY_AP_VS_VAR_SET_ENGLISH, dvspeed); trigger_key_event(KEY_AP_WING_LEVELER_OFF,0); } return FALSE;}/* This is the CANCEL mousepoint */BOOL FSAPI DF_mouse_cb4( PPIXPOINT relative_point, FLAGS32 mouse_flags){ if (mode == 3 || mode == 5 ) { dvspeed = 0 ; trigger_key_event(KEY_AP_VS_VAR_SET_ENGLISH, dvspeed); trigger_key_event(KEY_AP_ALT_VAR_SET_ENGLISH, (ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n) ); trigger_key_event(KEY_AP_WING_LEVELER_OFF,0); trigger_key_event(KEY_AP_PANEL_VS_OFF, 0); }

Share this post


Link to post
Share on other sites
Guest HartmannH

Hi Bill, there's a major problem with this code. First, please use send_key_event instead of trigger_key_event. send_key_event doesn't flood FS with key presses. And second, avoid unconditional calls to send/trigger_key_event in element or gauge callbacks - they kill the frame rate and stop shortcuts like Shift+E+2 from working.Do it like this:case PANEL_SERVICE_PRE_DRAW: if ((ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n != oldAlt) || (dvspeed != olddvspeed)){ send_key_event(KEY_AP_ALT_VAR_SET_ENGLISH, ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n + dvspeed) ); oldAlt = ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n; olddvspeed = dvspeed;}break;BTW: there's no need for brackets {} in a case branch.

Share this post


Link to post
Share on other sites

>BTW: there's no need for brackets {} in a case branch.Thank you. I am aware of that. I omitted all the rest of the code that is contained within those {} braces though for the sake of clarity... :)Thanks for the suggestion to use send_key_event, as well as the reality check in the PRE_DRAW update routine.

Share this post


Link to post
Share on other sites

After removing the extraneous ), the code is perfect. Thanks again!ALT_FROM_BAROMETRIC_PRESSUREvar.var_value.n + dvspeed) );

Share this post


Link to post
Share on other sites
Guest HartmannH

Oops. I didn't see that when I typed the message. Nobody's perfect ;-)

Share this post


Link to post
Share on other sites

>Oops. I didn't see that when I typed the message. Nobody's>perfect ;-)Too true! Pobody's nerfect, that for sure! Thanks again...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...