Jump to content
Sign in to follow this  
n4gix

Bi-Directional C to MDL-XML Code

Recommended Posts

Establishing communications from a C gauge to the .mdl files' XML animation code is relatively simple.However, how to establish a "bi-directional control" is eluding me...Here's the situation:I have two rocker switches in the VC for "Battery 1" and "Battery2" and both are XML coded to animate either via a mouse click in the VC, or according to the condition set by the C gauge on the 2d panel.Clicking on the 2d switches toggles the VC rocker properly, but clicking on the VC rocker is "prohibited" because as soon as you do, the 2d switch value will instantly update the VC rocker's L:var...How can I use the mouseclick from the VC to control the C gauge variable and make this "bi-directional?"// C Gauge Code Sectionint sw_bat1 = 0;int sw_bat2 = 0;ID sw_bat1_id;ID sw_bat2_id;case PANEL_SERVICE_PRE_INITIALIZE: register_named_variable ( "BatteryOne" ); register_named_variable ( "BatteryTwo" );case PANEL_SERVICE_PRE_UPDATE: sw_bat1_id = check_named_variable ( "BatteryOne" ) ; set_named_variable_value ( sw_bat1_id, (FLOAT64)bat1on ) ; sw_bat2_id = check_named_variable ( "BatteryTwo" ) ; set_named_variable_value ( sw_bat2_id, (FLOAT64)bat2on ) ;BOOL FSAPI bat1_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if (bat1on==1) bat1on = 0; else bat1on = 1; if (((bat1on==1)&&(mbat_on==0))||((mbat_on==1)&&(bat2on==0)&&(bat1on==0))) send_key_event(KEY_TOGGLE_MASTER_BATTERY,0); (GaugePlaySound)("soundESDGpush.wav","",0) ; return FALSE;}//---------------------------------------------------------------------------BOOL FSAPI bat2_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if (bat2on==1) bat2on = 0; else bat2on = 1; if (((bat2on==1)&&(mbat_on==0))||((mbat_on==1)&&(bat2on==0)&&(bat1on==0))) send_key_event(KEY_TOGGLE_MASTER_BATTERY,0); (GaugePlaySound)("soundESDGpush.wav","",0) ; return FALSE;}// MakeMDL.parts.xml Section switch_battery_one (L:BatteryOne,bool) 100 * HandBattery 1 (L:BatteryOne,bool) ! (>L:BatteryOne,bool) switch_battery_two (L:BatteryTwo,bool) 100 * HandBattery 2 (L:BatteryTwo,bool) ! (>L:BatteryTwo,bool)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Would I be correct in thinking that if I add a second L:var to the MakeMDL.parts.xml file's control code that I could use that as a check in the C gauge file?


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Bill,Your PANEL_SERVICE_PRE_UPDATE section is continually updating the two L:Vars. Try moving this code into the mouse functions so that it only gets executed when the value is changed by the C gauge.Doug

Share this post


Link to post
Share on other sites

Ah, that might be the ticket!I suspect though that I'll have to put a check in the PANEL_SERVICE_PRE_INITIALIZE section to "synchronize" the a/c load switch positions...


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

>Bill,>>Your PANEL_SERVICE_PRE_UPDATE section is continually updating>the two L:Vars. Try moving this code into the mouse functions>so that it only gets executed when the value is changed by the>C gauge.>>DougHow then would the C gauge be changed by the VC switch positions? We've come full circle then... ???


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

You can use the same L:Vars that drive the display of the VC gauge to drive the MAKE_ICON funtion in the C gauge. Remember that C treats the L:Vars as FLOAT64, so you will need to cast them to integers, but it should work.Doug

Share this post


Link to post
Share on other sites

As a followup to my own question, I feel compelled to share the solution with anyone who's interested... ;)There are two tasks that must be accomplished in order to achive our goal of bi-directional control:1) have the 3d VC switches and knobs animated in-synch with the 2d gauge logic.2) have the 2d gauge logic remain in synch with and respond to any input from the 3d VC switches and knobs.That is the precise reason for the extra variables that are added to the 2d gauge logic. Let us examine just one switch and it's associated variables for the moment, since they all work the same way.First, the needed variable declarations:ID sw_bat1_id; <= This is needed to "fetch" the memory address of the L:variable from the sim. It is a "memory pointer" only!int xml_bat1 = 0; <= This is used to hold the contents of the memory address pointed to by sw_bat1_idIn case PANEL_SERVICE_PRE_INITIALIZE, we need to "register" the names of the L: variables we are going to access:register_named_variable ( "BatteryOne" );The variable name is the XML variable L:BatteryOne that is used in the model file's embedded code. Once "registered," we can locate the memory address via the sw_bat1_id pointer.In case PANEL_SERVICE_CONNECT_TO_ WINDOW, we need to read the ascertain the current state of the sim and set the 3d switch accordingly: if (mbat_on==1) { bat1on = 1; xml_bat1 = 1; set_named_variable_value ( sw_bat1_id, (FLOAT64)xml_bat1 ) ; bat2on = 1; xml_bat2 = 2; set_named_variable_value ( sw_bat2_id, (FLOAT64)xml_bat2 ) ; }The "set_named_variable_value (sw_bat1_id, (FLOAT64)xml_bat1)" command assigns the value of xml_bat1 to the memory location pointed to by sw_bat1_id, which is of course the L:BatteryOne variable.In case PANEL_SERVICE_PRE_UPDATE , we need to keep checking the status of the 3d switch position and update it as needed, based on the 2d gauge logic: sw_bat1_id = check_named_variable("BatteryOne"); xml_bat1 = get_named_variable_value (sw_bat1_id);This "fetches" the contents of the L:BatteryOne variable and assigns it to our local variable xml_bat1 if (xml_bat1 != bat1on) { if (((xml_bat1==1)&&(mbat_on==0))||((mbat_on==1)&&(bat2on==0)&&(xml_bat1==0))) send_key_event(KEY_TOGGLE_MASTER_BATTERY,0); } if(xml_bat1 != bat1on) { bat1on = xml_bat1 ; (GaugePlaySound)("soundESDGpush.wav","",0) ; }The above code checks the status of the 3d switch position, and if changed by the pilot, will update the 2d gauge logic and switch it on/off as needed Notice that this ONLY is called IF the status of the 3d switch is changed, otherwise it is ignored. The basic code from the 2d gauge's mouse callback is repeated here simply because there's no way to "trigger" a mouse callback from an external input!In the mouse callback, bat1_mcb, a similar check is made against the 2d switch position, and if needed, the status of the 3d switch is updated:BOOL FSAPI bat1_mcb( PPIXPOINT relative_point, FLAGS32 mouse_flags ){ if (bat1on==1) {bat1on = 0;} else {bat1on = 1;} if (bat1on != xml_bat1) {set_named_variable_value(sw_bat1_id, bat1on) ; } // <= this updates the 3d switch positionto keep it in synch! if (((bat1on==1)&&(mbat_on==0))||((mbat_on==1)&&(bat2on==0)&&(bat1on==0))) send_key_event(KEY_TOGGLE_MASTER_BATTERY,0); (GaugePlaySound)("soundESDGpush.wav","",0) ;


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

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  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...