Board index FlightGear Support Interfacing

FGFS screenshot and the property tree?

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

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Tue Dec 05, 2017 2:11 pm

Had a stab at adding a bit (is this a class?) to controls.nas:

Code: Select all
var screenshot = func {
    if (getprop("/controls/switches/trigger") == 1) {
   fgcommand("screen-capture");
    }
}


Does this look like it should be working?

Is there anywhere else where my new var "screenshot" needs to be placed? (my first fgfs nasal experience)

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby AndersG » Tue Dec 05, 2017 2:50 pm

That defines the function screenshot() that is never called - so not much will happen.

On Linux you can put your Nasal code in a file in ~/.fgfs/Nasal/ to have it loaded automatically.
And the code would be something along these lines:
Code: Select all
setlistener("/controls/switches/trigger", func {
    if (getprop("/controls/switches/trigger") == 1) {  # We don't want a second screenshot when the trigger is reset to 0.
        fgcommand("screen-capture");
    }
}, 0, 0); # These last two 0s are important: the first says no trigger on init and the second that the listener only triggers on value change, not on every write.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: FGFS screenshot and the property tree?

Postby ScottBouch » Tue Dec 05, 2017 3:13 pm

BINGO!!! You've cracked it!!!! My trigger now saves screenshots!

Many thanks indeed, I'm really pleased to have learnt a bit about flightgear coding through this experience!!

I know on the surface this may seem trivial, but it's helped me gain some exposure to xml configuration files and also Nasal, so well worth it!

Thanks again for the help that everyone has given.

Cheers, Scott.
User avatar
ScottBouch
 
Posts: 183
Joined: Wed Jun 22, 2016 4:14 pm
Location: Midlands, UK
OS: Linux Mint

Re: FGFS screenshot and the property tree?

Postby wlbragg » Tue Dec 05, 2017 3:51 pm

Congratulations, I was getting ready to post a "setlistener" code block and I see AndersG beat me to it.

You most certainly do not want to use joysticks.xml - your button-element even if it were at the right level of the tree (which I think it is not) would not help since it tries to connect a button on a USB HID (or gameport) joystick device to the screen-capture command. If the property added into the binding is correct it'd be a property that is set by the aforementioned joystick button.

@AndersG, I am a bit confused as to why you don't think a joystick.xml config entry wouldn't work if the joystick is using it and the protocol file entries were in the correct order/position?

My written example was using "<property>/controls/screen-capture</property>" which is created by the protocol file, which was proven to capture the button click and work correctly. If a custom joystick file with all the buttons mapped correctly were employed I still don't see why that wouldn't work. Isn't that how this is typically done?
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: FGFS screenshot and the property tree?

Postby wlbragg » Tue Dec 05, 2017 3:54 pm

While I'm at it @AndersG,

}, 0, 0); # These last two 0s are important: the first says no trigger on init and the second that the listener only triggers on value change, not on every write.


If omitted, would these "default" to 0? I ask because I see it done all the time.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: FGFS screenshot and the property tree?

Postby AndersG » Tue Dec 05, 2017 3:58 pm

wlbragg wrote in Tue Dec 05, 2017 3:54 pm:While I'm at it @AndersG,
If omitted, would these "default" to 0? I ask because I see it done all the time.


Reading fgdata/Nasal/globals.nas they'd default to 0, 1 (No trigger on init and trigger on all writes).
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: FGFS screenshot and the property tree?

Postby AndersG » Tue Dec 05, 2017 4:05 pm

wlbragg wrote in Tue Dec 05, 2017 3:51 pm:@AndersG, I am a bit confused as to why you don't think a joystick.xml config entry wouldn't work if the joystick is using it and the protocol file entries were in the correct order/position?


Given that the joystick here is not recognized as such (being neither a USB HID nor a gameport device) I don't see what good any joystick binding file would do?

Isn't the joystick input in this case dumped straight into the property tree by the generic protocol?
How would that make FG trigger a <button n="x">-binding? (Which I must assume is normally triggered from C++-space when a particular joystick event is signalled (well, polled most likely) by the plib joystick library.)

The joystick-file tried on the previous page also seemed to define its <button>-element at the wrong level of the property tree.
Callsign: SE-AG
Aircraft (uhm...): Submarine Scout, Zeppelin NT, ZF Navy free balloon, Nordstern, Hindenburg, Short Empire flying-boat, ZNP-K, North Sea class, MTB T21 class, U.S.S. Monitor, MFI-9B, Type UB I submarine, Gokstad ship, Renault FT.
AndersG
 
Posts: 2524
Joined: Wed Nov 29, 2006 10:20 am
Location: Göteborg, Sweden
Callsign: SE-AG
OS: Debian GNU Linux

Re: FGFS screenshot and the property tree?

Postby wlbragg » Tue Dec 05, 2017 4:30 pm

Given that the joystick here is not recognized as such (being neither a USB HID nor a gameport device)

I missed this part, I wasn't sure if it "could" be recognized by a custom joystick config.

sn't the joystick input in this case dumped straight into the property tree by the generic protocol?
How would that make FG trigger a <button n="x">-binding?

Right, I assumed that is what the joystick config file is doing.

After looking closer at the generic joystick config I see it is mapping a "axis" or "button" event using a property to a control. I thought it was mapping only mapping a property to a control.

Thanks, my confusion.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Previous

Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests