Skip to content

Commit 1d7587a

Browse files
committed
update sample to support asyncio
1 parent c23084c commit 1d7587a

File tree

1 file changed

+58
-15
lines changed

1 file changed

+58
-15
lines changed

local_example.py

+58-15
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,77 @@
11
from SimConnect import *
22
import logging
3+
from SimConnect.Enum import *
34
from time import sleep
45
import asyncio
6+
57
logging.basicConfig(level=logging.DEBUG)
68
LOGGER = logging.getLogger(__name__)
79
LOGGER.info("START")
10+
11+
12+
# creat simconnection and pass used user classes
813
sm = SimConnect()
9-
aq = AircraftRequests(sm)
14+
aq = AircraftRequests(sm, _time=10, _attemps=10)
15+
ae = AircraftEvents(sm)
16+
17+
# PARKING_BRAKES = Event(b'PARKING_BRAKES', sm)
18+
# long path
19+
PARKING_BRAKES = ae.Miscellaneous_Systems.PARKING_BRAKES
20+
# using get
21+
GEAR_TOGGLE = ae.Miscellaneous_Systems.get("GEAR_TOGGLE")
22+
# Using find to lookup Event
23+
AP_MASTER = ae.find("AP_MASTER")
24+
25+
# THROTTLE1 Event
26+
THROTTLE1 = ae.Engine.THROTTLE1_SET
27+
1028

11-
Data = {}
29+
# THROTTLE1 Request
30+
Throttle = aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:1')
1231

32+
# If useing
33+
# Throttle = aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:index')
34+
# Need to set index befor read/write
35+
# Note to set index 2 vs 1 just re-run
36+
# Throttle.setIndex(1)
1337

14-
async def pintVal(name):
15-
global Data
16-
Data[name] = await aq.get(name)
38+
39+
# print the built in description
40+
# AP_MASTER Toggles AP on/off
41+
print("AP_MASTER", AP_MASTER.description)
42+
# Throttle Percent of max throttle position
43+
print("Throttle", Throttle.description)
44+
# THROTTLE1 Set throttle 1 exactly (0 to 16383)
45+
print("THROTTLE1", THROTTLE1.description)
1746

1847

1948
async def main():
49+
# time holder for inline commands
50+
ct_g = millis()
2051
while not sm.quit:
21-
temp = {}
22-
for ed in aq.PositionandSpeedData.list:
23-
temp[ed] = asyncio.create_task(pintVal(ed))
52+
print("Throttle:", await Throttle.value)
53+
print("Alt=%f Lat=%f Lon=%f Kohlsman=%.2f" % (
54+
await aq.PositionandSpeedData.get('PLANE_ALTITUDE'),
55+
await aq.PositionandSpeedData.get('PLANE_LATITUDE'),
56+
await aq.PositionandSpeedData.get('PLANE_LONGITUDE'),
57+
await aq.FlightInstrumentationData.get('KOHLSMAN_SETTING_HG')
58+
))
59+
sleep(2)
2460

25-
for ed in aq.PositionandSpeedData.list:
26-
await temp[ed]
61+
# Send Event with value
62+
# THROTTLE1(1500)
2763

28-
print(Data)
29-
sleep(2)
30-
sm.exit()
31-
quit()
64+
# Send Event toggle AP_MASTER
65+
# AP_MASTER()
66+
67+
# PARKING_BRAKES()
3268

69+
# send new data inine @ 5s
70+
if ct_g + 5000 < millis():
71+
if await Throttle.value < 100:
72+
Throttle.set(await Throttle.value + 5)
73+
print("THROTTLE SET")
74+
ct_g = millis()
75+
sm.exit()
3376

34-
asyncio.run(main())
77+
asyncio.run(main())

0 commit comments

Comments
 (0)