-
-
Save dooglewoogle/5f06422829b528a699c16766a70b0065 to your computer and use it in GitHub Desktop.
Idea for how to interact with the python_simconnect api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PythonSimConnect import * | |
from time import time | |
# library code, | |
class DataTypes(): | |
Altitude = ('altitude', (b'Plane Altitude', b'feet')) | |
Latitude = ('Latitude', (b'Plane Latitude', b'degrees')) | |
Longitude = ('Longitude', (b'Plane Longitude', b'degrees')) | |
Kohlsman = ('Kohlsman', (b'Kohlsman setting hg', b'inHg')) | |
class SimEvents(): | |
GearDown = b'GEAR_DOWN' | |
GearUp = b'GEAR_UP' | |
GearToggle = b'GEAR_TOGGLE' | |
class Wrapper_Request(): | |
_request = None | |
def add(self, datatype): | |
self._request.append(datatype[0], datatype[1]) | |
class Wrapper_SimConnect(): | |
class GROUP_ID(SIMCONNECT_NOTIFICATION_GROUP_ID): # client-defined notification group ID | |
GROUP_A = auto() | |
_SimConnect = PythonSimConnect(_NOTIFICATION_GROUP_ID=GROUP_ID) | |
def addRequest(self, timeout=2000): | |
name = "Request" + len(self._SimConnect.Requests) | |
r = Wrapper_Request() | |
r._request = self._SimConnect.newRequest(name, timeout) | |
return r | |
##################################### | |
#user code | |
# default initialsing has no arguments | |
connection = Wrapper_SimConnect() | |
connection.setup() | |
myRequest = connection.addRequest() | |
# simpler and enumerated variables | |
myRequest.add(DataTypes.Altitude) | |
myRequest.add(DataTypes.Latitude) | |
myRequest.add(DataTypes.Longitude) | |
myRequest.add(DataTypes.Kohlsman) | |
gear_toggle = connection.MapToSimEvent(SimEvents.GearDown) | |
while not connection.quit: | |
if int(time()) % 10 == 0: | |
connection.RequestData(myRequest) | |
if int(time()) % 15 == 0: | |
connection.SendData(gear_toggle) | |
connection.Run() | |
data = connection.GetData(myRequest) | |
if data is not None: | |
print("Lat=%f Lon=%f Alt=%f Kohlsman=%.2f" % ( | |
data.Latitude, | |
data.Longitude, | |
data.altitude, | |
data.Kohlsman | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment