11from SimConnect import *
22import logging
3- from SimConnect .Enum import *
43from time import sleep
5-
6-
4+ import asyncio
75logging .basicConfig (level = logging .DEBUG )
86LOGGER = logging .getLogger (__name__ )
97LOGGER .info ("START" )
10- # time holder for inline commands
11- ct_g = millis ()
12-
13- # creat simconnection and pass used user classes
148sm = SimConnect ()
159aq = AircraftRequests (sm )
16- ae = AircraftEvents (sm )
17-
18-
19- mc = aq .find ("MAGNETIC_COMPASS" )
20- mv = aq .find ("MAGVAR" )
21- print (mc .get () + mv .get ())
22-
23- sm .exit ()
24- quit ()
25-
26- # Set pos arund space nedle in WA.
27- sm .set_pos (
28- _Altitude = 1000.0 ,
29- _Latitude = 47.614699 ,
30- _Longitude = - 122.358473 ,
31- _Airspeed = 130 ,
32- _Heading = 70.0 ,
33- # _Pitch=0.0,
34- # _Bank=0.0,
35- # _OnGround=0
36- )
37-
38- # PARKING_BRAKES = Event(b'PARKING_BRAKES', sm)
39- # long path
40- PARKING_BRAKES = ae .Miscellaneous_Systems .PARKING_BRAKES
41- # using get
42- GEAR_TOGGLE = ae .Miscellaneous_Systems .get ("GEAR_TOGGLE" )
43- # Using find to lookup Event
44- AP_MASTER = ae .find ("AP_MASTER" )
45-
46- # THROTTLE1 Event
47- THROTTLE1 = ae .Engine .THROTTLE1_SET
48-
49-
50- # THROTTLE1 Request
51- Throttle = aq .find ('GENERAL_ENG_THROTTLE_LEVER_POSITION:1' )
52-
53- # If useing
54- # Throttle = aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:index')
55- # Need to set index befor read/write
56- # Note to set index 2 vs 1 just re-run
57- # Throttle.setIndex(1)
5810
11+ Data = {}
5912
60- # print the built in description
61- # AP_MASTER Toggles AP on/off
62- print ("AP_MASTER" , AP_MASTER .description )
63- # Throttle Percent of max throttle position
64- print ("Throttle" , Throttle .description )
65- # THROTTLE1 Set throttle 1 exactly (0 to 16383)
66- print ("THROTTLE1" , THROTTLE1 .description )
6713
14+ async def pintVal (name ):
15+ global Data
16+ Data [name ] = await aq .get (name )
6817
69- while not sm .quit :
70- print ("Throttle:" , Throttle .value )
71- print ("Alt=%f Lat=%f Lon=%f Kohlsman=%.2f" % (
72- aq .PositionandSpeedData .get ('PLANE_ALTITUDE' ),
73- aq .PositionandSpeedData .get ('PLANE_LATITUDE' ),
74- aq .PositionandSpeedData .get ('PLANE_LONGITUDE' ),
75- aq .FlightInstrumentationData .get ('KOHLSMAN_SETTING_HG' )
76- ))
77- sleep (2 )
7818
79- # Send Event with value
80- # THROTTLE1(1500)
19+ async def main ():
20+ while not sm .quit :
21+ temp = {}
22+ for ed in aq .PositionandSpeedData .list :
23+ temp [ed ] = asyncio .create_task (pintVal (ed ))
8124
82- # Send Event toggle AP_MASTER
83- # AP_MASTER()
25+ for ed in aq . PositionandSpeedData . list :
26+ await temp [ ed ]
8427
85- # PARKING_BRAKES()
28+ print (Data )
29+ sleep (2 )
30+ sm .exit ()
31+ quit ()
8632
87- # send new data inine @ 5s
88- if ct_g + 5000 < millis ():
89- if Throttle .value < 100 :
90- Throttle .value += 5
91- print ("THROTTLE SET" )
92- ct_g = millis ()
9333
94- sm . exit ( )
34+ asyncio . run ( main () )
0 commit comments