-
Notifications
You must be signed in to change notification settings - Fork 0
/
simconnect_mobiflight.py
39 lines (30 loc) · 1.47 KB
/
simconnect_mobiflight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging, logging.handlers
import ctypes
from ctypes import wintypes
from SimConnect import SimConnect
from SimConnect.Enum import SIMCONNECT_CLIENT_DATA_ID, SIMCONNECT_RECV_ID, SIMCONNECT_RECV_CLIENT_DATA
class SimConnectMobiFlight(SimConnect):
def __init__(self, auto_connect=True, library_path=None):
self.client_data_handlers = []
if library_path:
super().__init__(auto_connect, library_path)
else:
super().__init__(auto_connect)
# Fix missing types
self.dll.MapClientDataNameToID.argtypes = [wintypes.HANDLE, ctypes.c_char_p, SIMCONNECT_CLIENT_DATA_ID]
def register_client_data_handler(self, handler):
if not handler in self.client_data_handlers:
logging.info("Register new client data handler")
self.client_data_handlers.append(handler)
def unregister_client_data_handler(self, handler):
if handler in self.client_data_handlers:
logging.info("Unregister client data handler")
self.client_data_handlers.remove(handler)
def my_dispatch_proc(self, pData, cbData, pContext):
dwID = pData.contents.dwID
if dwID == SIMCONNECT_RECV_ID.SIMCONNECT_RECV_ID_CLIENT_DATA:
client_data = ctypes.cast(pData, ctypes.POINTER(SIMCONNECT_RECV_CLIENT_DATA)).contents
for handler in self.client_data_handlers:
handler(client_data)
else:
super().my_dispatch_proc(pData, cbData, pContext)