Board index FlightGear Support Interfacing

in-sim 'button press' using .xml protocol booleans -part2  Topic is solved

Connecting two computers, using generic protocol, connecting with Matlab?

in-sim 'button press' using .xml protocol booleans -part2

Postby Volador » Thu Apr 08, 2021 8:18 pm

Here it is at last... (arduino interface Win7 generic protocol over serial usb)

Image

*** EDIT: SOLUTION FOUND just skip to the post further down viewtopic.php?f=36&t=39021&p=384359#p384387 ***

Having written up the solution here https://forum.flightgear.org/viewtopic.php?f=36&t=38531&start=30#p379310 kindly guided by the community because I'm not great at programming, I've found myself at a stumbling block.

On my interface I have a four position switch for APR VOR MAP PLAN, and I was just changing the property instrumentation/efis/mfd/mode-num to 0,1,2 or 3 using xml protocol from the arduino for that property but as all I see is the switch moving but no update to the radar display so I suspect there's more to it so I dug into the code as previously advised by a very helpful member who wants to remain nameless, but this one is not so straight forward.

to increment or decrement the switch position there are two hotspots in the glareshield.xml that send either:
Boeing747.Efis.ctl_func("display",1); or
Boeing747.Efis.ctl_func("display",-1);

In my new arduino-747.nas file I've got things like the following so I'd like to use the same sort of format, please note that I'm not great with nasal so I'm really after a solid description of the code rather than a theoretical answer, thanks in advance :D

Code: Select all
setlistener("input/arduino/ap/ap-dis-but", func(state)
   {
   if(state.getBoolValue())
      {
      # AP disengage
      Boeing747.afds.input(2,0);Boeing747.afds.ap_update();
      }
   else {}
   },1,0); 



With this in mind (or if you know a clever way *and can describe it for a novice* ) how could you trigger either:
Boeing747.EfisR.ctl_func("display",1); or Boeing747.Efis.ctl_func("display",-1); by using an updated property (this bit is easy)
eg two new properties for the two hotspots:
arduino/efis/radar-mode-up
arduino/efis/radar-mode-down
*But the tricky bit* know where the switch position is i.e. APR, VOR, MAP, PLAN (not just that it's 1 or -1).
I suspect there'll be a clever nasal way just to maybe use one property - say an integer (I could create a new property like arduino/efis/radar-mode of value 1 or 2) while also sending the property instrumentation/efis/mfd/mode-num (which can be 0,1,2,3)


here's the section of the efis.nas that receives the 1 or -1
Code: Select all
 elsif(md=="display")
        {
            var num =me.mfd_mode_num.getValue();
            num+=val;
            if(num<0)num=0;
            if(num>3)num=3;
            me.mfd_mode_num.setValue(num);
            me.mfd_display_mode.setValue(me.mfd_mode_list[num]);

      # for all modes except plan, acft is up. For PLAN,
                  # north is up.
            var isPLAN = (num == 3);
            setprop("instrumentation/nd/aircraft-heading-up", !isPLAN);
            setprop("instrumentation/nd/user-position", isPLAN);
            me.nd_plan_wpt.setValue(getprop("autopilot/route-manager/current-wp"));

            me.update_nd_center();
            me.update_nd_plan_center();
        }


The solution seems tantalisingly close - I might even have stumbled on the solution while typing this up but I can't quite see it, can anyone shed some light?
Last edited by Volador on Wed Apr 21, 2021 10:27 am, edited 2 times in total.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' using .xml protocol booleans -part

Postby daweed » Fri Apr 09, 2021 3:02 pm

Hello,
Very nice hardware
Windows 10 / Linux Mint 20
AMD Ryzen 7 3700X |32 Go RAM GeForce RTX 3070 Ti 8 Go
FG Interface
Lyon Saint Exupery Scenery

ATC on LFLL on Friday 19:00 UTC => 22:00 UTC
daweed
 
Posts: 398
Joined: Thu Dec 11, 2014 11:45 am
Location: LFKP LFLL
Callsign: daweed
OS: Linux Mint 20

Re: in-sim 'button press' using .xml protocol booleans -part

Postby tom_nl » Fri Apr 09, 2021 3:09 pm

indeed, that is looking good!

Tom
tom_nl
 
Posts: 84
Joined: Tue Aug 04, 2020 11:41 am
Location: Netherlands
OS: OS X Big Sur

Re: in-sim 'button press' using .xml protocol booleans -part

Postby Volador » Fri Apr 09, 2021 3:19 pm

Thanks Daweed and Tom :) ...any clues on the property/nasal conundrum?

By the way, I must credit Tom with the button/ switch matrix code which was very very helpful! and I'll be sharing that solution on the forum in due course.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' using .xml protocol booleans -part

Postby Volador » Fri Apr 09, 2021 8:12 pm

I've been pondering the problem some more and think I can simplify the question.

How could you pass 0,1,2 or 3 from the arduino to the property instrumentation/efis/mfd/mode-num (which I'm already doing) but use that value to trigger the following piece of code in the efis.nas file, which is currently triggered by Boeing747.Efis.ctl_func("display",1); and Boeing747.Efis.ctl_func("display",-1);
Code: Select all
var num =me.mfd_mode_num.getValue();
            num+=val;
            if(num<0)num=0;
            if(num>3)num=3;
            me.mfd_mode_num.setValue(num);
            me.mfd_display_mode.setValue(me.mfd_mode_list[num]);

             # for all modes except plan, acft is up. For PLAN,
            # north is up.

            var isPLAN = (num == 3);
            setprop("instrumentation/nd/aircraft-heading-up", !isPLAN);
            setprop("instrumentation/nd/user-position", isPLAN);
            me.nd_plan_wpt.setValue(getprop("autopilot/route-manager/current-wp"));

            me.update_nd_center();
            me.update_nd_plan_center();


I've tried pasting the above code into my already working custom 747-adrduino.nas listener file as a new listener on a property that detects a boolean if the switch changes position (arbitrary) but it didn't work

Code: Select all
setlistener("input/arduino/radar-mode-change", func(state)
   {
   if(state.getBoolValue())
         {
         var num =me.mfd_mode_num.getValue();
         num+=val;
         if(num<0)num=0;
         if(num>3)num=3;
         me.mfd_mode_num.setValue(num);
         me.mfd_display_mode.setValue(me.mfd_mode_list[num]);

         # for all modes except plan, acft is up. For PLAN,
         # north is up.

         var isPLAN = (num == 3);
         setprop("instrumentation/nd/aircraft-heading-up", !isPLAN);
         setprop("instrumentation/nd/user-position", isPLAN);
         me.nd_plan_wpt.setValue(getprop("autopilot/route-manager/current-wp"));

         me.update_nd_center();
         me.update_nd_plan_center();
         }
   else {}
   },1,0);
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' .xml protocol bools Arduino - part  

Postby Volador » Fri Apr 09, 2021 9:49 pm

SOLVED:

I was just experimenting so I really don't know if this is the best solution. In my 747-arduino.nas listener file I put this:

Code: Select all
setlistener("input/arduino/radar-mode-change", func(state)
   {
   if(state.getBoolValue())
      {
      #
      Boeing747.Efis.ctl_func("display",0);
      }
   else {}
   },1,0);


It seems that by sending a 0 for the "display" value (rather than the 1 or -1 ) it causes the efis.nas to just look up the current mode in the property instrumentation/efis/mfd/mode-num (which is updated by the arduino at the same time as a property that just flags a switch position change event (boolean)) and then it kind of sorts itself out. I can't really explain it but sharing here for anyone facing the same problem with multiple position (rotary) switches that are usually triggered by +1 or -1 hot-spots in the cockpit. :D
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' using .xml protocol booleans -part

Postby Johan G » Mon Apr 12, 2021 2:35 pm

That panel looks very good. :)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' using .xml protocol booleans -part

Postby Volador » Fri Apr 16, 2021 3:09 pm

Thank you Johan,

I should have gone for the black rack in hindsight but all fitted quite nicely into a 2U rack -took a lot of design time as I went for a hybrid layout rather than a straight copy, all hand cut too as I don't have CNC, so don't look too closely :) - Here's the 2U rack, it may be available elsewhere. Pro-power 2U rack grey or black
[url]https://cpc.farnell.com/pro-power/g17082ubk/case-19-abs-2u-black-anti-static/dp/EN85543?mckv=sgyRRFaRE_dc|pcrid|426684131183|kword||match||plid||slid||product|EN85543|pgrid|100371159558|ptaid|pla-333076567674|&CMP=KNC-GUK-CPC-SHOPPING&s_kwcid=AL!5616!3!426684131183!!!network}!333076567674!&gclid=EAIaIQobChMIo_LE5faC8AIVVeztCh1sGAKCEAQYASABEgLdKPD_BwE[/url]
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: in-sim 'button press' using .xml protocol booleans -part

Postby Johan G » Sun Apr 18, 2021 6:00 pm

Volador wrote in Fri Apr 16, 2021 3:09 pm:[...] all hand cut too as I don't have CNC, so don't look too closely :)

I could not tell. It looked CNC cut to me, in particular the display hole corners. :)
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests