From bcafb487e63973aca37276cc1acb16ce21bf9257 Mon Sep 17 00:00:00 2001 From: Julianne Swinoga Date: Sun, 4 Jun 2023 11:35:14 -0400 Subject: [PATCH] Clean up simple_gui.py --- examples/simple_gui.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/simple_gui.py b/examples/simple_gui.py index bbead50..3b440a0 100755 --- a/examples/simple_gui.py +++ b/examples/simple_gui.py @@ -1,26 +1,31 @@ #!/usr/bin/python3 """ -Simple GUI example TODO: Docs +Simple GUI example that prints the latitude and longitude of the aircraft """ import time +import math from flightgear_python.fg_if import GuiConnection def gui_callback(gui_data, event_pipe): - print(gui_data) - return gui_data + lat_deg = math.degrees(gui_data['lat_rad']) + lon_deg = math.degrees(gui_data['lon_rad']) + child_data = (lat_deg, lon_deg) + event_pipe.child_send(child_data) """ Start FlightGear with `--native-gui=socket,out,30,localhost,5504,udp --native-gui=socket,in,30,localhost,5505,udp` """ if __name__ == '__main__': # NOTE: This is REQUIRED on Windows! gui_conn = GuiConnection(gui_version=8) - ctrls_event_pipe = gui_conn.connect_rx('localhost', 5504, gui_callback) - gui_conn.connect_tx('localhost', 5505) - gui_conn.start() # Start the GUI RX/TX loop + gui_event_pipe = gui_conn.connect_rx('localhost', 5504, gui_callback) + # Note: I couldn't get FlightGear to do anything with the returned data on this interface + # I think it's just ignoring everything. Technically you can send data back though. + # gui_conn.connect_tx('localhost', 5505) + gui_conn.start() # Start the GUI RX loop - time.sleep(2) while True: - # could also do `gui_conn.event_pipe.parent_send` so you just need to pass around `gui_conn` - # ctrls_event_pipe.parent_send((gear_down_parent,)) # send tuple - # gear_down_parent = not gear_down_parent # Flip gear state - time.sleep(10) + # could also do `gui_conn.event_pipe.parent_recv` so you just need to pass around `gui_conn` + pipe_data = gui_event_pipe.parent_recv() # receive tuple + lat_deg, lon_deg = pipe_data + print(f'Lat: {lat_deg:.6f} Lon: {lon_deg:.6f}') + time.sleep(0.01)